forked from Thilas/chocolatey-packages
138 lines (119 loc) · 4.71 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
name: Update
on:
push:
branches: [ master ] # Automatic update of all packages
schedule:
- cron: 5 */6 * * * # Scheduled update of all packages
workflow_dispatch: # Manual run
inputs:
packages:
description: Packages (optional, comma-separated values)
type: string
force:
description: Force update (requires packages)
type: boolean
jobs:
build:
name: Update packages
runs-on: windows-latest
timeout-minutes: 20
env:
# Set au version to use or omit to use the latest. Specify branch name to use development version from Github
au_version: master
# ID of the gist used to save run results - create a gist under the github_user (secret or not) and grab the id - https://gist.github.com/name/id
# Optional, leave empty to create anonymous gist
gist_id: c09573f2f23bc2aa904d90ff63de2cfe
# Force test: gist id for test results
gist_id_test: 83dd81cb41ebc10ef87ee50b168aca3f
steps:
- name: Set up git
run: |
git config --global user.name "GitHub Actions Bot"
git config --global user.email "<>"
git config --global core.safecrlf false
- name: Checkout
uses: actions/checkout@v3
- name: Determine manual scope
if: github.event_name == 'workflow_dispatch'
run: |
if ($Env:ManualScope) {
# Handle both comma and space-separated values
$scope = $Env:ManualScope -replace ',',' ' -replace '\s+',' '
$packages, $invalidPackages = ($scope -split ' ').Where({ Test-Path $_ }, 'Split')
"Scope:"
$packages | ForEach-Object { "- $_" }
"PackageScope=$packages" >> $Env:GITHUB_ENV
if ($invalidPackages) {
throw "Some packages do not exist or are invalid: `"$($invalidPackages -join '","')`""
}
} else {
"No specific scope, all packages will be processed"
}
env:
ManualScope: ${{ inputs.packages }}
- name: Install AU
run: |
git clone -q https://github.com/majkinetor/au.git $Env:TEMP/au
. "$Env:TEMP/au/scripts/Install-AU.ps1" $Env:au_version
- name: Install chocolatey-core.extension # required for several packages
run: choco install -y chocolatey-core.extension
- name: Update packages
id: updates
run: |
$arguments = @{ }
if ($Env:PackageScope) {
$arguments.Name = $Env:PackageScope -split ' '
}
if ($Env:force_update -eq 'true') {
if (!$Env:PackageScope) {
throw "Packages are required if you want to force an update."
}
$arguments.Force = $true
}
[array] $packages = ./update_all.ps1 @arguments -ThrowOnErrors -PassThru -UpdatesOnly | ForEach-Object {
$_ | ConvertTo-Json -Compress
}
$packages = ConvertTo-Json $packages -Compress
"Packages = $packages"
"packages=$packages" >> $Env:GITHUB_OUTPUT
env:
au_push: true
au_nogist: ${{ github.event_name != 'schedule' }}
force_update: ${{ inputs.force }}
github_user_repo: ${{ github.repository }}
github_api_key: ${{ secrets.GITHUB_TOKEN }}
gist_token: ${{ secrets.GIST_TOKEN }}
api_key: ${{ secrets.CHOCOLATEY_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Publish report
if: always() && hashFiles('Update-AUPackages.md', 'Update-Force-Test*.md')
run: Get-Content 'Update-AUPackages.md', 'Update-Force-Test*.md' -ErrorAction SilentlyContinue >> $Env:GITHUB_STEP_SUMMARY
- name: Publish history
if: always() && hashFiles('Update-History.md')
run: Get-Content 'Update-History.md' >> $Env:GITHUB_STEP_SUMMARY
- name: Upload Info artifact
if: always() && hashFiles('update_info.xml')
uses: actions/upload-artifact@v3.1.2
with:
name: Info
path: update_info.xml
- name: Prepare Packages artifact
if: always() && hashFiles('**/*.nupkg')
run: |
New-Item Packages -ItemType Directory
Get-ChildItem *.nupkg -Recurse | Move-Item -Destination Packages
- name: Upload Packages artifact
if: always() && hashFiles('Packages/*.nupkg')
uses: actions/upload-artifact@v3.1.2
with:
name: Packages
path: Packages/*.nupkg
outputs:
updates: ${{ steps.updates.outputs.packages }}
test:
name: Test
if: needs.build.outputs.updates != 'null'
needs: build
uses: ./.github/workflows/test_packages.yml
with:
updates: ${{ needs.build.outputs.updates }}