From a59320b2e03ab8d76fe97bb12ea5e9659972f6cd Mon Sep 17 00:00:00 2001 From: Dan Rosser Date: Mon, 2 Nov 2026 06:59:30 +1100 Subject: [PATCH] CI: recreate the latest release in the build jobs, not a separate workflow that can run after uploads --- .github/workflows/build-linux.yml | 18 +++++++++++++++ .github/workflows/build-macos.yml | 6 +++++ .github/workflows/build-vs.yml | 6 +++++ .github/workflows/latest-release.yml | 33 ---------------------------- scripts/ci_latest_release.sh | 28 +++++++++++++++++++++++ 5 files changed, 58 insertions(+), 33 deletions(-) delete mode 100644 .github/workflows/latest-release.yml create mode 100755 scripts/ci_latest_release.sh diff --git a/.github/workflows/build-linux.yml b/.github/workflows/build-linux.yml index ff2a2975..da28655a 100644 --- a/.github/workflows/build-linux.yml +++ b/.github/workflows/build-linux.yml @@ -37,6 +37,12 @@ jobs: with: key: ${{ matrix.cfg.target }} + - name: Recreate the latest release for this commit + if: github.repository == 'openframeworks/projectGenerator' && github.event_name == 'push' && github.ref == 'refs/heads/master' + shell: bash + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: ./scripts/ci_latest_release.sh - name: Determine Release id: vars shell: bash @@ -141,6 +147,12 @@ jobs: with: key: ubuntu22-linux + - name: Recreate the latest release for this commit + if: github.repository == 'openframeworks/projectGenerator' && github.event_name == 'push' && github.ref == 'refs/heads/master' + shell: bash + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: ./scripts/ci_latest_release.sh - name: Determine Release shell: bash run: | @@ -219,6 +231,12 @@ jobs: with: key: arm64-linux + - name: Recreate the latest release for this commit + if: github.repository == 'openframeworks/projectGenerator' && github.event_name == 'push' && github.ref == 'refs/heads/master' + shell: bash + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: ./scripts/ci_latest_release.sh - name: Determine Release shell: bash run: | diff --git a/.github/workflows/build-macos.yml b/.github/workflows/build-macos.yml index 0b127d9e..d074f0f1 100644 --- a/.github/workflows/build-macos.yml +++ b/.github/workflows/build-macos.yml @@ -37,6 +37,12 @@ jobs: node-version: 26 - name: Setup run: ./scripts/osx/setup_environment.sh + - name: Recreate the latest release for this commit + if: github.repository == 'openframeworks/projectGenerator' && github.event_name == 'push' && github.ref == 'refs/heads/master' + shell: bash + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: ./scripts/ci_latest_release.sh - name: Determine Release id: vars shell: bash diff --git a/.github/workflows/build-vs.yml b/.github/workflows/build-vs.yml index 568e4df6..2fedd948 100644 --- a/.github/workflows/build-vs.yml +++ b/.github/workflows/build-vs.yml @@ -42,6 +42,12 @@ jobs: zip rsync wget + - name: Recreate the latest release for this commit + if: github.repository == 'openframeworks/projectGenerator' && github.event_name == 'push' && github.ref == 'refs/heads/master' + shell: bash + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: ./scripts/ci_latest_release.sh - name: Determine Release id: vars shell: bash diff --git a/.github/workflows/latest-release.yml b/.github/workflows/latest-release.yml deleted file mode 100644 index 1d5e036f..00000000 --- a/.github/workflows/latest-release.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: latest-release - -# a master push starts the builds, which upload to the "latest" release; recreate it first so -# its date and tag are this commit's (the builds take minutes before they upload) -on: - push: - branches: - - master - paths-ignore: - - '**/README.md' - -permissions: - contents: write - -concurrency: - group: latest-release - cancel-in-progress: false - -jobs: - latest-release: - if: github.repository == 'openframeworks/projectGenerator' - runs-on: ubuntu-latest - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - REPO: ${{ github.repository }} - steps: - - name: Recreate the latest release at this commit - shell: bash - run: | - set -euo pipefail - gh release delete latest --repo "$REPO" --cleanup-tag --yes || echo "no latest release yet" - gh release create latest --repo "$REPO" --target "$GITHUB_SHA" --title latest --latest=false \ - --notes "Latest master build from ${GITHUB_SHA:0:7} (copied to nightly every night). Files are added as each platform finishes building." diff --git a/scripts/ci_latest_release.sh b/scripts/ci_latest_release.sh new file mode 100755 index 00000000..1a78aad6 --- /dev/null +++ b/scripts/ci_latest_release.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +# master builds upload to the "latest" release. The first build job of a push recreates it at that +# commit, so its date and tag are this build's; jobs that start later (a runner can queue for half +# an hour) see the tag already there and leave it, so nothing already uploaded is deleted. +# Re-running an older master build doesn't touch a newer latest. + +REPO="${GITHUB_REPOSITORY:?}" +SHA="${GITHUB_SHA:?}" + +head=$(gh api "repos/$REPO/commits/master" --jq '.sha' 2>/dev/null || true) +if [ "$head" != "$SHA" ]; then + echo "${SHA:0:7} isn't the master head (${head:0:7}) - leaving latest" + exit 0 +fi + +current=$(gh api "repos/$REPO/git/ref/tags/latest" --jq '.object.sha' 2>/dev/null || true) +if [ "$current" = "$SHA" ]; then + echo "latest is already at ${SHA:0:7}" + exit 0 +fi + +echo "recreating latest at ${SHA:0:7} (was ${current:0:7})" +gh release delete latest --repo "$REPO" --cleanup-tag --yes || echo "no latest release yet" +# another build job may create it at the same moment +gh release create latest --repo "$REPO" --target "$SHA" --title latest --latest=false \ + --notes "Latest master build from ${SHA:0:7} (copied to nightly every night). Files are added as each platform finishes building." \ + || gh release view latest --repo "$REPO" > /dev/null