@@ -4,9 +4,11 @@ name: 'Terminal release'
44# attached to each release of the packages, whose version they carry, read from the release's
55# tag as Nuget.yml reads it. Run by hand, it builds and packs without attaching anything unless
66# asked to, and a pull request that touches the workflow or its scripts builds and packs the
7- # same way. Only the job that attaches the builds can write to the repository , and it runs no
8- # code from it .
7+ # same way. Only the jobs that attach the builds and publish the packages can write , and they run
8+ # no code from the repository .
99# https://github.com/asc-community/AngouriMath/issues/539
10+ # The AUR's amcli-bin and the Nix flake's release.json are rendered from the same archives, and
11+ # published with the release. https://github.com/asc-community/AngouriMath/issues/1660
1012on :
1113 release :
1214 types : [published]
1719 - ' Sources/Terminal/AngouriMath.Terminal/pack-deb-linux.sh'
1820 - ' Sources/Terminal/AngouriMath.Terminal/amcli.1'
1921 - ' Sources/Terminal/AngouriMath.Terminal/amcli.bash'
22+ - ' Sources/Terminal/AngouriMath.Terminal/packaging/**'
2023 workflow_dispatch :
2124 inputs :
2225 version :
3437 permissions :
3538 contents : read
3639 outputs :
40+ version : ${{ steps.version.outputs.version }}
3741 tag : ${{ steps.version.outputs.tag }}
3842
3943 steps :
@@ -129,3 +133,113 @@ jobs:
129133 'angourimath-terminal-arm64.deb' \
130134 -R "$GITHUB_REPOSITORY" \
131135 --clobber
136+
137+ # The PKGBUILD for the AUR's amcli-bin, its .SRCINFO, and the release.json the Nix flake reads,
138+ # from the archives the build made. Rendered on every run, so that a pull request that touches
139+ # them shows they still render, and published only with a release.
140+ TerminalPackagesRender :
141+ needs : TerminalBuild
142+ runs-on : ubuntu-latest
143+ permissions :
144+ contents : read
145+
146+ steps :
147+ - uses : actions/checkout@v6
148+ with :
149+ fetch-depth : 0
150+
151+ - uses : actions/download-artifact@v4
152+ with :
153+ name : angourimath-terminal
154+ path : archives
155+
156+ # The tag's own files where there is a tag; for a pull request or a run by hand, the commit
157+ # being built.
158+ - name : ' Render'
159+ env :
160+ VERSION : ${{ needs.TerminalBuild.outputs.version }}
161+ TAG : ${{ needs.TerminalBuild.outputs.tag }}
162+ run : |
163+ sum() { sha256sum "archives/angourimath-terminal-$1.zip" | cut -d' ' -f1; }
164+ if git rev-parse -q --verify "refs/tags/$TAG" > /dev/null; then ref="$TAG"; else ref=HEAD; fi
165+ mkdir -p packages
166+ PACKAGING_REF="$ref" Sources/Terminal/AngouriMath.Terminal/packaging/render-pkgbuild.sh \
167+ "$VERSION" "$(sum linux-x64)" "$(sum linux-arm64)" "$(sum linux-arm)" > packages/PKGBUILD
168+ printf '{\n "version": "%s",\n "sha256": {\n "linux-x64": "%s",\n "linux-arm64": "%s",\n "linux-arm": "%s"\n }\n}\n' \
169+ "$VERSION" "$(sum linux-x64)" "$(sum linux-arm64)" "$(sum linux-arm)" > packages/release.json
170+ cat packages/PKGBUILD packages/release.json
171+
172+ # makepkg will not run as root, and an Arch container is the only place it is.
173+ - name : ' .SRCINFO'
174+ run : |
175+ docker run --rm -v "$PWD/packages:/packages" archlinux:base-devel bash -c \
176+ 'useradd -m builder && cp /packages/PKGBUILD /home/builder/ && cd /home/builder && su builder -c "makepkg --printsrcinfo" > /packages/.SRCINFO'
177+ cat packages/.SRCINFO
178+
179+ - name : ' Keep the packages'
180+ uses : actions/upload-artifact@v4
181+ with :
182+ name : amcli-packages
183+ retention-days : 7
184+ include-hidden-files : true
185+ path : packages
186+
187+ # The PKGBUILD is pushed to the AUR where the repository has the AUR_SSH_KEY secret, the private
188+ # key of the AUR account that owns amcli-bin; without it nothing is pushed. release.json goes to
189+ # master by a pull request, which is what moves the flake to the release.
190+ TerminalPackagesPublish :
191+ needs : [TerminalBuild, TerminalRelease, TerminalPackagesRender]
192+ if : github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && inputs.release)
193+ runs-on : ubuntu-latest
194+ permissions :
195+ contents : write
196+ pull-requests : write
197+
198+ steps :
199+ - uses : actions/checkout@v6
200+ with :
201+ ref : ${{ github.event.repository.default_branch }}
202+
203+ - uses : actions/download-artifact@v4
204+ with :
205+ name : amcli-packages
206+ path : packages
207+
208+ - name : ' The flake follows the release'
209+ env :
210+ GH_TOKEN : ${{ github.token }}
211+ VERSION : ${{ needs.TerminalBuild.outputs.version }}
212+ run : |
213+ branch="amcli-release-$VERSION"
214+ cp packages/release.json Sources/Terminal/AngouriMath.Terminal/packaging/release.json
215+ if git diff --quiet; then echo "release.json already names $VERSION"; exit 0; fi
216+ git config user.name 'github-actions[bot]'
217+ git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
218+ git switch -c "$branch"
219+ git commit -am "The Nix flake installs amcli $VERSION"
220+ git push --force origin "$branch"
221+ gh pr create --base "${{ github.event.repository.default_branch }}" --head "$branch" \
222+ --title "The Nix flake installs amcli $VERSION" \
223+ --body "release.json for the $VERSION archives, rendered by the Terminal release workflow (#1660)."
224+
225+ - name : ' The AUR follows the release'
226+ env :
227+ AUR_SSH_KEY : ${{ secrets.AUR_SSH_KEY }}
228+ VERSION : ${{ needs.TerminalBuild.outputs.version }}
229+ run : |
230+ if [ -z "$AUR_SSH_KEY" ]; then echo 'No AUR_SSH_KEY secret: amcli-bin is not pushed.'; exit 0; fi
231+ install -d -m 700 ~/.ssh
232+ printf '%s\n' "$AUR_SSH_KEY" > ~/.ssh/aur && chmod 600 ~/.ssh/aur
233+ # The host key the AUR publishes on https://aur.archlinux.org, and no other.
234+ ssh-keyscan -t ed25519 aur.archlinux.org > aur.key 2> /dev/null
235+ [ "$(ssh-keygen -lf aur.key | cut -d' ' -f2)" = 'SHA256:RFzBCUItH9LZS0cKB5UE6ceAYhBD5C8GeOBip8Z11+4' ] \
236+ || { echo 'aur.archlinux.org did not present its published Ed25519 key'; exit 1; }
237+ cat aur.key >> ~/.ssh/known_hosts
238+ export GIT_SSH_COMMAND='ssh -i ~/.ssh/aur -o IdentitiesOnly=yes'
239+ git clone ssh://aur@aur.archlinux.org/amcli-bin.git aur
240+ cp packages/PKGBUILD packages/.SRCINFO aur/
241+ cd aur
242+ git config user.name 'github-actions[bot]'
243+ git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
244+ git add PKGBUILD .SRCINFO
245+ git diff --cached --quiet || { git commit -m "amcli $VERSION"; git push origin HEAD:master; }
0 commit comments