# Cut a GitHub Release whenever the shipped version changes. # # The dashboard links users to the releases page, and that page held a single # entry from five months earlier while the product shipped daily — which tells a # visitor the project is abandoned. Commit messages here already read as release # notes, so the note is the commit body rather than a generated list of subjects. name: Release on: push: branches: [main] paths: - 'frontend/package.json' permissions: contents: write jobs: release: runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 with: fetch-depth: 2 - name: Read version, and stop if it did not change id: v run: | VERSION=$(node -p "require('./frontend/package.json').version") PREV=$(git show HEAD~1:frontend/package.json 2>/dev/null | node -p "JSON.parse(require('fs').readFileSync(0,'utf8')).version" || echo "") echo "version=$VERSION" >> "$GITHUB_OUTPUT" if [ "$VERSION" = "$PREV" ]; then echo "unchanged=true" >> "$GITHUB_OUTPUT" echo "Version unchanged ($VERSION) — nothing to release." fi - name: Compose notes from the commit that shipped it if: steps.v.outputs.unchanged != 'true' env: VERSION: ${{ steps.v.outputs.version }} run: | # Written to a file rather than passed through a step output. Commit # messages here routinely contain backticks, and interpolating one into # a shell command lets the shell evaluate it — which is both why the # first attempt failed and a way to run arbitrary code in CI from a # commit message. { git log -1 --pretty=%B printf '\n---\n' printf 'Container image: `ghcr.io/2gt-media-group-llc/mikrotik-manager:%s`\n\n' "$VERSION" printf 'Documentation: https://2gt-media-group-llc.github.io/mikrotik-manager/\n' } > /tmp/release-notes.md - name: Publish if: steps.v.outputs.unchanged != 'true' env: GH_TOKEN: ${{ github.token }} VERSION: ${{ steps.v.outputs.version }} run: | TAG="v$VERSION" # Betas are marked pre-release so nobody is pointed at one by accident. PRERELEASE="" case "$TAG" in *beta*|*alpha*|*rc*) PRERELEASE="--prerelease" ;; esac gh release create "$TAG" \ --title "$TAG" \ --notes-file /tmp/release-notes.md \ $PRERELEASE