|
| 1 | +# |
| 2 | +# Copyright 2026 AtomVM Contributors |
| 3 | +# |
| 4 | +# SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later |
| 5 | +# |
| 6 | +# Maintainer notes: |
| 7 | +# - Requires RELEASE_TAG_PUSH_TOKEN (a fine-grained PAT). |
| 8 | +# - GitHub: Settings -> Developer settings -> Personal access tokens -> Fine-grained tokens. |
| 9 | +# - Grant it Contents: Read and write on atomvm/AtomVM. |
| 10 | +# - Add it with: gh secret set RELEASE_TAG_PUSH_TOKEN --repo atomvm/AtomVM |
| 11 | +# - Manual run: gh workflow run nightly-release-tags.yaml --repo atomvm/AtomVM --ref main |
| 12 | +# - Only if cleanup is needed, delete the stale release/tag and rerun: |
| 13 | +# gh release delete main-latest --repo atomvm/AtomVM --yes |
| 14 | +# Only for a complete cleanup, also delete the tag: |
| 15 | +# gh api -X DELETE repos/atomvm/AtomVM/git/refs/tags/main-latest |
| 16 | + |
| 17 | +name: Nightly Release Tags |
| 18 | + |
| 19 | +on: |
| 20 | + schedule: |
| 21 | + # Avoid the top of the hour when GitHub Actions is most congested. |
| 22 | + - cron: "17 2 * * *" |
| 23 | + workflow_dispatch: |
| 24 | + |
| 25 | +permissions: |
| 26 | + contents: read |
| 27 | + |
| 28 | +concurrency: |
| 29 | + group: ${{ github.workflow }} |
| 30 | + cancel-in-progress: false |
| 31 | + |
| 32 | +jobs: |
| 33 | + update-nightly-tags: |
| 34 | + runs-on: ubuntu-24.04 |
| 35 | + |
| 36 | + strategy: |
| 37 | + fail-fast: false |
| 38 | + matrix: |
| 39 | + include: |
| 40 | + # Add one entry per branch that should publish a moving nightly tag. |
| 41 | + - branch: main |
| 42 | + tag: main-latest |
| 43 | + - branch: release-0.7 |
| 44 | + tag: release-0.7-latest |
| 45 | + |
| 46 | + env: |
| 47 | + # Use a PAT or GitHub App token that can push tags. |
| 48 | + # We intentionally do not use GITHUB_TOKEN here because downstream |
| 49 | + # release workflows should run when the nightly tag moves. |
| 50 | + TAG_PUSH_TOKEN: ${{ secrets.RELEASE_TAG_PUSH_TOKEN }} |
| 51 | + |
| 52 | + steps: |
| 53 | + # In the official repository we fail fast if the secret is missing, so |
| 54 | + # nightly releases do not silently stop updating. |
| 55 | + - name: Require nightly tag token in official repository |
| 56 | + if: github.repository == 'atomvm/AtomVM' && env.TAG_PUSH_TOKEN == '' |
| 57 | + run: | |
| 58 | + echo "::error::Missing RELEASE_TAG_PUSH_TOKEN secret. Configure a token that can push tags and trigger downstream workflows." |
| 59 | + exit 1 |
| 60 | +
|
| 61 | + # Forks can run this workflow manually without configuring the secret. |
| 62 | + # That makes it easier to verify the workflow wiring before enabling |
| 63 | + # real nightly tag updates in a test repository. |
| 64 | + - name: Skip nightly tag updates without token in forks |
| 65 | + if: github.repository != 'atomvm/AtomVM' && env.TAG_PUSH_TOKEN == '' |
| 66 | + run: echo "::warning::Skipping nightly tag update because RELEASE_TAG_PUSH_TOKEN is not configured in this fork." |
| 67 | + |
| 68 | + - name: Checkout repository |
| 69 | + uses: actions/checkout@v4 |
| 70 | + with: |
| 71 | + fetch-depth: 0 |
| 72 | + persist-credentials: false |
| 73 | + |
| 74 | + - name: Check remote branch exists |
| 75 | + id: branch |
| 76 | + shell: bash |
| 77 | + run: | |
| 78 | + if git ls-remote --exit-code origin "refs/heads/${{ matrix.branch }}" > /dev/null 2>&1; then |
| 79 | + echo "exists=true" >> "$GITHUB_OUTPUT" |
| 80 | + else |
| 81 | + echo "exists=false" >> "$GITHUB_OUTPUT" |
| 82 | + echo "::warning::Skipping missing branch ${{ matrix.branch }}" |
| 83 | + fi |
| 84 | +
|
| 85 | + - name: Update nightly tag |
| 86 | + if: env.TAG_PUSH_TOKEN != '' && steps.branch.outputs.exists == 'true' |
| 87 | + shell: bash |
| 88 | + run: | |
| 89 | + set -euo pipefail |
| 90 | + git fetch origin "${{ matrix.branch }}" --force |
| 91 | + git checkout --detach FETCH_HEAD |
| 92 | + git config user.name "github-actions[bot]" |
| 93 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 94 | +
|
| 95 | + BRANCH_HEAD="$(git rev-parse HEAD)" |
| 96 | + EXISTING_TAG="$(git ls-remote --tags origin "refs/tags/${{ matrix.tag }}^{}" | awk '{print $1}')" |
| 97 | + # Fall back to lightweight tag if the dereferenced form is missing. |
| 98 | + if [ -z "$EXISTING_TAG" ]; then |
| 99 | + EXISTING_TAG="$(git ls-remote --tags origin "refs/tags/${{ matrix.tag }}" | awk '{print $1}')" |
| 100 | + fi |
| 101 | +
|
| 102 | + if [ "$BRANCH_HEAD" = "$EXISTING_TAG" ]; then |
| 103 | + echo "Tag ${{ matrix.tag }} already points at ${BRANCH_HEAD:0:12} – nothing to do." |
| 104 | + exit 0 |
| 105 | + fi |
| 106 | +
|
| 107 | + git tag -fa "${{ matrix.tag }}" -F - <<EOF |
| 108 | + Nightly build for ${{ matrix.branch }} |
| 109 | +
|
| 110 | + Commit: [${BRANCH_HEAD:0:12}](https://github.com/${{ github.repository }}/commit/${BRANCH_HEAD}) |
| 111 | + Change log: [CHANGELOG.md](https://github.com/${{ github.repository }}/blob/${BRANCH_HEAD}/CHANGELOG.md) |
| 112 | + Branch history: [${{ matrix.branch }}](https://github.com/${{ github.repository }}/commits/${{ matrix.branch }}) |
| 113 | + EOF |
| 114 | +
|
| 115 | + git remote set-url origin "https://x-access-token:${TAG_PUSH_TOKEN}@github.com/${{ github.repository }}.git" |
| 116 | + git push origin "refs/tags/${{ matrix.tag }}" --force |
0 commit comments