Skip to content

v1.15

v1.15 #14

Workflow file for this run

name: Sync App Version
on:
release:
types: [published]
permissions:
contents: write
jobs:
update-version:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.repository.default_branch }}
fetch-depth: 0
- name: Ensure latest default branch
run: |
set -euo pipefail
BRANCH='${{ github.event.repository.default_branch }}'
git fetch origin "$BRANCH"
git checkout "$BRANCH"
git pull --ff-only origin "$BRANCH"
- name: Capture release version
id: prep
run: |
VERSION="${{ github.event.release.tag_name }}"
if [ -z "$VERSION" ]; then
echo "Release tag name is required to update the version." >&2
exit 1
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Update version.txt
run: |
set -euo pipefail
VERSION='${{ steps.prep.outputs.version }}'
echo "$VERSION" > version.txt
- name: Commit changes
id: commit
run: |
set -euo pipefail
git status --short
if git diff --quiet; then
echo "No version update required."
echo "committed=false" >> "$GITHUB_OUTPUT"
exit 0
fi
VERSION='${{ steps.prep.outputs.version }}'
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git commit -am "chore: sync app version to $VERSION"
echo "committed=true" >> "$GITHUB_OUTPUT"
- name: Push commit
run: |
set -euo pipefail
if [ "${{ steps.commit.outputs.committed }}" != "true" ]; then
echo "No updates to push."
exit 0
fi
BRANCH='${{ github.event.repository.default_branch }}'
git push origin "HEAD:$BRANCH"
- name: Move release tag to synced commit
if: steps.commit.outputs.committed == 'true'
env:
TAG_NAME: ${{ steps.prep.outputs.version }}
run: |
set -euo pipefail
git fetch --tags origin
if git rev-parse "refs/tags/$TAG_NAME" >/dev/null 2>&1; then
TAG_TYPE=$(git for-each-ref --format="%(objecttype)" "refs/tags/$TAG_NAME")
if [ "$TAG_TYPE" = "tag" ]; then
# Preserve annotated-tag message if present
git for-each-ref --format="%(contents)" "refs/tags/$TAG_NAME" > tag_message.txt
git tag -fa "$TAG_NAME" -F tag_message.txt
rm -f tag_message.txt
else
git tag -f "$TAG_NAME"
fi
else
git tag "$TAG_NAME"
fi
git push --force origin "$TAG_NAME"
- name: Refresh release metadata
if: steps.commit.outputs.committed == 'true'
env:
GH_TOKEN: ${{ github.token }}
TAG_NAME: ${{ steps.prep.outputs.version }}
run: |
set -euo pipefail
COMMIT_SHA=$(git rev-parse HEAD)
gh release edit "$TAG_NAME" --target "$COMMIT_SHA"