-
Notifications
You must be signed in to change notification settings - Fork 20
162 lines (150 loc) · 5.48 KB
/
update-index.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
name: Update index
on:
schedule:
- cron: "0 */2 * * *" # every second hour
push:
branches:
- main
paths:
- "registry/**"
- ".github/workflows/update-index.yml"
- ".github/scripts/**"
env:
GALLERY_JSON: bsdata.catpkg-gallery.json
RELEASE_TAG: index-v1
ENABLE_GHPAGES_UPDATE: false
jobs:
update-index:
runs-on: ubuntu-latest
steps:
- name: Checkout main
uses: actions/checkout@v4
with:
ref: main
path: master
- name: Checkout index
uses: actions/checkout@v4
with:
ref: index
path: index
- uses: ./master/.github/actions/install-yaml
- name: Compile index
uses: Amadevus/pwsh-script@v2
id: compile
with:
script: |
$ErrorActionPreference = 'Stop'
$args = @{
IndexPath = Resolve-Path ./index
RegistryPath = Resolve-Path ./master/registry
GalleryJsonPath = $env:GALLERY_JSON
Token = $github.token
}
./master/.github/scripts/Update-IndexCache.ps1 @args -Verbose
# save master's SHA to associate branches
"master-sha: $env:GITHUB_SHA" > index/master-sha.yml
- name: Upload gallery-json as workflow artifact
if: success() || failure()
uses: actions/upload-artifact@v4
with:
name: ${{ env.GALLERY_JSON }}
path: ${{ env.GALLERY_JSON }}
continue-on-error: true
- name: Format index commit message
uses: Amadevus/pwsh-script@v2
id: format_index_msg
with:
script: |
Set-Location ./index
# get list of changed files
$pkgids = @((git status --porcelain | % { $_.Substring(3) } | Split-Path -Leaf) -replace '\.catpkg\.yml$','')
if ($pkgids.Length -eq 0) {
Write-Host 'No changes in the index' -ForegroundColor Green
return
}
# create commit message
$summary = if ($pkgids.Length -eq 1) {
$pkgids
} else {
"{0} (+{1} more)" -f $pkgids[0],($pkgids.Length - 1)
}
$message = @"
Changed: $summary
$($pkgids -join "`n")
"@
return $message
- name: Push index changes
uses: stefanzweifel/git-auto-commit-action@v5
id: push-index
with:
commit_message: ":robot: ${{ steps.format_index_msg.outputs.result }}"
commit_author: ''
repository: index
- name: Replace ${{ env.GALLERY_JSON }} release asset
if: steps.push-index.outputs.changes_detected == 'true'
uses: actions/github-script@v7
with:
script: |
const { data: release } = await github.rest.repos.getReleaseByTag({
...context.repo,
tag: '${{ env.RELEASE_TAG }}'
});
console.log('Release retrieved');
const assetName = '${{ env.GALLERY_JSON }}';
const assets = await github
.paginate(github.rest.repos.listReleaseAssets, {
...context.repo,
release_id: release.id
});
const previousIndex = assets.find(x => x.name === assetName);
if (previousIndex) {
console.log('Deleting existing asset');
await github.rest.repos.deleteReleaseAsset({
...context.repo,
asset_id: previousIndex.id
});
}
// upload the file
const fs = require('fs');
const upload = await github.rest.repos.uploadReleaseAsset({
...context.repo,
release_id: release.id,
name: assetName,
data: fs.readFileSync(assetName),
headers: { 'content-type': 'application/json', 'content-length': fs.statSync(assetName).size }
})
console.log('Done');
return upload;
- name: Checkout gh-pages
if: steps.push-index.outputs.changes_detected == 'true' && env.ENABLE_GHPAGES_UPDATE == 'true'
uses: actions/checkout@v4
with:
ref: gh-pages
path: gh-pages
- name: Update dataindex
if: steps.push-index.outputs.changes_detected == 'true' && env.ENABLE_GHPAGES_UPDATE == 'true'
uses: Amadevus/pwsh-script@v2
id: update
env:
COMPILE_RESULT: ${{ needs.update-index.outputs.compile_result }}
with:
script: |
$ErrorActionPreference = 'Stop'
$compileResult = $env:COMPILE_RESULT | ConvertFrom-Json
$owner, $repo = $github.repository -split '/'
$subpath = "dataindex"
$args = @{
IndexPath = Resolve-Path ./index
DataPath = Resolve-Path (New-Item "./gh-pages/$subpath" -ItemType Directory -Force)
DataBaseUrl = "https://$owner.github.io/$repo/$subpath"
GalleryJsonPath = $env:GALLERY_JSON
ChangedIndexPath = $compileResult.changed_index_paths
Token = $github.token
}
./master/.github/scripts/Update-GhPagesData.ps1 @args -Verbose
- name: Push gh-pages changes
if: steps.push-index.outputs.changes_detected == 'true' && env.ENABLE_GHPAGES_UPDATE == 'true'
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: ":robot: update data index"
repository: gh-pages