winbuild #447
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Nightly Windows builds | |
name: winbuild | |
on: | |
schedule: | |
- cron: "15 0 * * *" | |
permissions: | |
contents: write | |
packages: read | |
concurrency: winbuild | |
env: | |
GIT_AUTHOR_NAME: OpenSlide Automation | |
GIT_AUTHOR_EMAIL: [email protected] | |
GIT_COMMITTER_NAME: OpenSlide Automation | |
GIT_COMMITTER_EMAIL: [email protected] | |
jobs: | |
setup: | |
name: Set up | |
runs-on: ubuntu-latest | |
outputs: | |
builder_repo_and_digest: ${{ steps.find.outputs.builder_repo_and_digest }} | |
pkgver: ${{ steps.params.outputs.pkgver }} | |
openslide_commit: ${{ steps.params.outputs.openslide_commit }} | |
java_commit: ${{ steps.params.outputs.java_commit }} | |
winbuild_commit: ${{ steps.params.outputs.winbuild_commit }} | |
changed: ${{ steps.params.outputs.changed }} | |
stale: ${{ steps.params.outputs.stale }} | |
steps: | |
- name: Check out repo | |
uses: actions/checkout@v3 | |
- name: Find builder container digest | |
id: find | |
uses: openslide/openslide-winbuild/.github/find-container-digest@main | |
- name: Calculate parameters | |
id: params | |
run: | | |
set -euo pipefail | |
pkgver="$(date +%Y%m%d)-nightly" | |
echo "pkgver=$pkgver" >> $GITHUB_OUTPUT | |
duplicate=$(jq ".builds[] | select(.pkgver == \"$pkgver\")" \ | |
docs/windows/index.json) | |
if [ -n "$duplicate" ]; then | |
echo "Found existing nightly build $pkgver" | |
exit 1 | |
fi | |
# Modify the repository at least every 30 days so GitHub doesn't | |
# disable the workflow | |
if [ $(( $(jq .last_update docs/windows/index.json) + 86400 * 30 )) -lt $(date +%s) ]; then | |
echo "Repository is stale" | |
echo "stale=true" >> $GITHUB_OUTPUT | |
fi | |
for repo in openslide openslide-java openslide-winbuild; do | |
old=$(jq -r ".builds[-1][\"${repo}\"]" docs/windows/index.json) | |
new=$(curl --no-progress-meter \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
"https://api.github.com/repos/openslide/${repo}/commits/main" | | |
jq -r .sha) | |
echo "$repo commit: https://github.com/openslide/${repo}/commit/${new:0:10}" | |
echo "${repo##*-}_commit=$new" >> $GITHUB_OUTPUT | |
if [ "$old" != "$new" ]; then | |
echo " -> changed from https://github.com/openslide/${repo}/commit/${old:0:10}" | |
echo "changed=true" >> $GITHUB_OUTPUT | |
else | |
echo " -> unchanged" | |
fi | |
done | |
old=$(jq -r '.builds[-1]["builder"]' docs/windows/index.json) | |
new="${{ steps.find.outputs.builder_repo_and_digest }}" | |
echo "Builder container: $new" | |
if [ "$old" != "$new" ]; then | |
echo " -> changed from $old" | |
echo "changed=true" >> $GITHUB_OUTPUT | |
else | |
echo " -> unchanged" | |
fi | |
build: | |
name: Build | |
needs: setup | |
if: needs.setup.outputs.changed | |
uses: openslide/openslide-winbuild/.github/workflows/windows.yml@main | |
with: | |
builder_repo_and_digest: ${{ needs.setup.outputs.builder_repo_and_digest }} | |
openslide_repo: openslide/openslide | |
openslide_ref: ${{ needs.setup.outputs.openslide_commit }} | |
openslide_java_repo: openslide/openslide-java | |
openslide_java_ref: ${{ needs.setup.outputs.java_commit }} | |
openslide_winbuild_repo: openslide/openslide-winbuild | |
openslide_winbuild_ref: ${{ needs.setup.outputs.winbuild_commit }} | |
pkgver: ${{ needs.setup.outputs.pkgver }} | |
upload: | |
name: Upload | |
needs: [setup, build] | |
if: needs.setup.outputs.changed | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out repo | |
uses: actions/checkout@v3 | |
- name: Install dependencies | |
run: sudo apt-get install python3-dateutil python3-jinja2 | |
- name: Download artifacts | |
uses: actions/download-artifact@v3 | |
with: | |
name: ${{ needs.build.outputs.artifact }} | |
- name: Update index | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
scripts/winbuild-index.py \ | |
--pkgver "${{ needs.setup.outputs.pkgver }}" \ | |
--builder "${{ needs.setup.outputs.builder_repo_and_digest }}" \ | |
--openslide "${{ needs.setup.outputs.openslide_commit }}" \ | |
--java "${{ needs.setup.outputs.java_commit }}" \ | |
--winbuild "${{ needs.setup.outputs.winbuild_commit }}" | |
- name: Commit, tag, push, create release | |
env: | |
GITHUB_TOKEN: ${{ github.token }} | |
run: | | |
artifact="${{ needs.build.outputs.artifact }}" | |
pkgver="${{ needs.setup.outputs.pkgver }}" | |
unzip -j "${artifact}/openslide-win32-${pkgver}.zip" \ | |
"openslide-win32-${pkgver}/VERSIONS.md" | |
# trim width for commit message limit | |
sed -i -e 's/ |$/|/' VERSIONS.md | |
pkglen=$(awk -F'|' '{print length($2) - 2; exit}' VERSIONS.md) | |
verlen=$(awk -F'|' '{print length($3) - 2; exit}' VERSIONS.md) | |
line() { | |
# args: friendly-name repo-name commit-hash emphasis | |
printf "| %-${pkglen}s | %-${verlen}s |" \ | |
"$4$1$4" "${4}openslide/${2}@${3:0:8}${4}" | |
} | |
update_line() { | |
# args: friendly-name repo-name commit-hash emphasis | |
local new="$(line "$@")" | |
local escaped="$(sed 's/*/\\*/g' <<<"$4$1$4")" | |
sed -i -e "/$escaped/ s^.*^$new^" VERSIONS.md | |
} | |
update_line OpenSlide openslide \ | |
"${{ needs.setup.outputs.openslide_commit }}" "**" | |
update_line "OpenSlide Java" openslide-java \ | |
"${{ needs.setup.outputs.java_commit }}" "**" | |
line openslide-winbuild openslide-winbuild \ | |
"${{ needs.setup.outputs.winbuild_commit }}" _ >> VERSIONS.md | |
title="Windows build $pkgver" | |
body="$(cat VERSIONS.md)" | |
git add docs | |
git commit -m "$title" -m "$body" | |
git tag -a "windows-$pkgver" -m "$title" -m "$body" | |
git push origin HEAD "windows-$pkgver" | |
gh release create --notes-file - --prerelease --verify-tag \ | |
--title "Windows build $pkgver" "windows-$pkgver" \ | |
"${artifact}/"* <<EOF | |
See the [build index](https://openslide.org/builds/windows/) for more info. | |
$body | |
EOF | |
keepalive: | |
name: Keepalive | |
needs: setup | |
if: needs.setup.outputs.stale && ! needs.setup.outputs.changed | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out repo | |
uses: actions/checkout@v3 | |
- name: Install dependencies | |
run: sudo apt-get install python3-dateutil python3-jinja2 | |
- name: Commit and push | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
scripts/winbuild-index.py | |
git add docs | |
git commit -m "Update timestamp" | |
git push |