Skip to content

Build and Push all automatic packages #673

Build and Push all automatic packages

Build and Push all automatic packages #673

name: Build and Push all automatic packages
on:
push:
branches:
- 'main'
schedule:
# * is a special character in YAML so you have to quote this string
#- cron: '0 2 * * 1' # Every Monday at 2am UTC
- cron: '0 2 * * *' # Every day at 2am UTC
workflow_dispatch:
permissions:
contents: write
jobs:
build:
name: Build and Push
environment: production
runs-on: windows-latest
steps:
- name: Check out repo
uses: actions/checkout@v3
- name: "Initialise Git"
shell: pwsh
run: |
& git config --global user.email "glennsarti-bot@users.noreply.github.com"
& git config --global user.name "glennsarti-bot"
& git config --global core.safecrlf false
Write-Host "Git has been configured"
- name: "Build and Push"
shell: pwsh
env:
COMMIT_MSG: ${{ github.event.head_commit.message }}
gist_id: bd4f850684e8b9b26e9d64a87415d0ac # Belongs to glennsarti-bot
github_user_repo: glennsarti/ChocolateyPackages
au_push: true
github_api_key: ${{ secrets.BOT_GITHUB_API_KEY }}
api_key: ${{ secrets.BOT_CHOCOLATEY_API_KEY }}
run: |
$PSVersionTable | ft
./setup/au_setup.ps1
$ErrorActionPreference = 'Continue'
$ScheduledBuild = $ENV:GITHUB_EVENT_NAME -eq 'schedule'
$ManualBuild = $ENV:GITHUB_EVENT_NAME -eq 'workflow_dispatch'
$PushBuild = $ENV:GITHUB_EVENT_NAME -eq 'push'
Write-Host (' {0,-20} {1}' -f 'SCHEDULED BUILD:', $ScheduledBuild)
Write-Host (' {0,-20} {1}' -f 'MANUAL BUILD:', $ManualBuild)
Write-Host (' {0,-20} {1}' -f 'PER COMMIT BUILD:', $PushBuild)
if ($PushBuild) {
switch -regex ($Env:COMMIT_MSG)
{
'\[AU (.+?)\]' { $forced = $Matches[1] }
'\[PUSH (.+?)\]' {
$packages = $Matches[1] -split ' '
Write-Host "PUSHING PACKAGES: $packages"
foreach ($package in $packages) {
Write-Host ("{0}`n{1}`n" -f ('-'*60), "PACKAGE: $package")
$package_dir = ls -recurse | ? { $_.Name -eq "$package.nuspec"} | select -First 1 | % Directory
if (!$package_dir) { Write-Warning "Can't find package '$package'"; continue }
pushd $package_dir; choco pack; Push-Package; popd
}
return
}
default {
Write-Host "Commit message is not automated format. Disabling Pushing, Git and Gist"
$Env:au_push = 'false'
$Env:github_api_key = ''
$Env:gist_id = ''
}
}
}
./update_all.ps1 -ForcedPackages $forced
7z a au_temp.zip $Env:TEMP\chocolatey\au\*
- name: "Upload artifacts"
uses: actions/upload-artifact@v3
with:
name: AU-Build-Output
if-no-files-found: warn
path: |
update_info.xml
Update-AUPackages.md
au_temp.zip