-
-
Notifications
You must be signed in to change notification settings - Fork 103
189 lines (167 loc) · 6.64 KB
/
Copy pathpublish-scoop.yml
File metadata and controls
189 lines (167 loc) · 6.64 KB
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
name: Publish to Scoop
# Renders the Scoop manifest pointing at the official ZIP archives and
# commits it to the configured Scoop bucket repository whenever a non-draft,
# non-prerelease release is published.
permissions:
contents: read
on:
release:
types: [published]
workflow_dispatch:
inputs:
version:
description: 'Release version to publish (must already exist as a GitHub release).'
required: true
type: string
dry_run:
description: 'Render the manifest but do not commit to the bucket repo.'
required: false
type: boolean
default: true
workflow_call:
inputs:
version:
description: 'Release version to publish.'
required: true
type: string
dry_run:
description: 'Render the manifest but do not commit to the bucket repo.'
required: false
type: boolean
default: false
secrets:
SCOOP_BUCKET_PAT:
description: 'PAT (or deploy key token) with write access to the Scoop bucket repository.'
required: false
env:
# Override via the bucket repo's own clone URL when forking.
SCOOP_BUCKET_REPO: mickem/scoop-bucket
SCOOP_BUCKET_BRANCH: main
jobs:
publish:
if: ${{ github.event_name != 'release' || (github.event.release.draft == false && github.event.release.prerelease == false) }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Resolve release tag and version
id: ctx
run: |
if [ "${{ github.event_name }}" = 'release' ]; then
tag='${{ github.event.release.tag_name }}'
version="$tag"
dry_run='false'
# published_at is ISO-8601 like 2026-05-15T14:30:00Z; the
# manifest wants YYYY-MM-DD.
published_at='${{ github.event.release.published_at }}'
release_date="${published_at:0:10}"
else
tag='${{ inputs.version }}'
version='${{ inputs.version }}'
dry_run='${{ inputs.dry_run }}'
release_date=''
fi
if [ -z "$tag" ]; then
echo 'No release tag/version available.' >&2
exit 1
fi
{
echo "tag=$tag"
echo "version=$version"
echo "dry_run=$dry_run"
echo "release_date=$release_date"
} >> "$GITHUB_OUTPUT"
- uses: actions/setup-python@v6
with:
python-version: '3.11'
- name: Render Scoop manifest
run: |
render_args=(
--version "${{ steps.ctx.outputs.version }}"
--release-tag "${{ steps.ctx.outputs.tag }}"
--templates packaging/scoop
--output dist/scoop
--download-dir dist/_assets
--asset "ZIP_X64=NSCP-${{ steps.ctx.outputs.version }}-x64.zip"
--asset "ZIP_X86=NSCP-${{ steps.ctx.outputs.version }}-Win32.zip"
)
if [ -n "${{ steps.ctx.outputs.release_date }}" ]; then
render_args+=(--release-date "${{ steps.ctx.outputs.release_date }}")
fi
python packaging/scripts/render_templates.py "${render_args[@]}"
- name: Validate manifest is parseable JSON
run: python -m json.tool dist/scoop/nsclient.json > /dev/null
- name: Verify rendered hashes round-trip from URL
run: |
python packaging/scripts/verify_manifest_hashes.py scoop dist/scoop
- name: Verify Scoop bin paths exist in the ZIP
run: |
set -euo pipefail
python <<'PY'
import json, sys, zipfile
from pathlib import Path
manifest = json.loads(Path("dist/scoop/nsclient.json").read_text())
version = "${{ steps.ctx.outputs.version }}"
archives = {
"x64": Path(f"dist/_assets/NSCP-{version}-x64.zip"),
"Win32": Path(f"dist/_assets/NSCP-{version}-Win32.zip"),
}
# Normalise manifest bin entries to the path string scoop uses to
# locate the file inside the extracted archive.
bins = []
for entry in manifest.get("bin", []):
if isinstance(entry, str):
bins.append(entry)
elif isinstance(entry, list) and entry:
bins.append(entry[0])
missing = []
for arch, zpath in archives.items():
with zipfile.ZipFile(zpath) as zf:
names = {n.replace("\\", "/") for n in zf.namelist()}
for b in bins:
target = b.replace("\\", "/")
if target not in names:
missing.append(f"{zpath.name}: {b}")
if missing:
for m in missing:
print(f"::error::scoop bin entry not found — {m}")
sys.exit(1)
print("All scoop bin entries verified in both archives.")
PY
- name: Upload rendered manifest
uses: actions/upload-artifact@v6
with:
name: scoop-manifest-${{ steps.ctx.outputs.version }}
path: dist/scoop/nsclient.json
if-no-files-found: error
- name: Commit manifest to Scoop bucket repo
if: ${{ steps.ctx.outputs.dry_run != 'true' }}
env:
SCOOP_BUCKET_PAT: ${{ secrets.SCOOP_BUCKET_PAT }}
run: |
set -euo pipefail
if [ -z "${SCOOP_BUCKET_PAT:-}" ]; then
echo "::warning::SCOOP_BUCKET_PAT secret is not configured. Skipping commit."
exit 0
fi
# Pass the PAT via http.extraHeader so it never lands in argv or
# the cloned repo's .git/config. GitHub Actions masks the secret
# in logs but cannot mask process state on the runner.
auth_header="Authorization: Basic $(printf 'x-access-token:%s' "$SCOOP_BUCKET_PAT" | base64 -w0)"
bucket_dir="$(mktemp -d)"
git -c http.extraHeader="$auth_header" clone --depth=1 \
--branch "$SCOOP_BUCKET_BRANCH" \
"https://github.com/${SCOOP_BUCKET_REPO}.git" \
"$bucket_dir"
mkdir -p "$bucket_dir/bucket"
cp dist/scoop/nsclient.json "$bucket_dir/bucket/nsclient.json"
cd "$bucket_dir"
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
git add bucket/nsclient.json
if git diff --cached --quiet; then
echo 'No changes to nsclient.json; nothing to commit.'
exit 0
fi
git commit -m "nsclient: bump to ${{ steps.ctx.outputs.version }}"
git -c http.extraHeader="$auth_header" push \
origin "HEAD:${SCOOP_BUCKET_BRANCH}"