|
| 1 | +name: Update version file |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + target-branch: |
| 7 | + description: Branch to check out before writing the version file |
| 8 | + required: false |
| 9 | + default: master |
| 10 | + type: string |
| 11 | + version-file: |
| 12 | + description: Path to the version file to overwrite |
| 13 | + required: false |
| 14 | + default: public/version.txt |
| 15 | + type: string |
| 16 | + next-tag: |
| 17 | + description: Tag value to write into the version file |
| 18 | + required: true |
| 19 | + type: string |
| 20 | + secrets: |
| 21 | + gh_token: |
| 22 | + required: true |
| 23 | + |
| 24 | + outputs: |
| 25 | + new-tag: |
| 26 | + description: Tag that was written into the version file |
| 27 | + value: ${{ jobs.update_version_file.outputs.new_tag }} |
| 28 | + |
| 29 | +jobs: |
| 30 | + update_version_file: |
| 31 | + name: Update version file |
| 32 | + runs-on: ubuntu-latest |
| 33 | + permissions: |
| 34 | + contents: write |
| 35 | + outputs: |
| 36 | + new_tag: ${{ steps.write_version.outputs.new_tag }} |
| 37 | + steps: |
| 38 | + - name: Check out branch with tags |
| 39 | + uses: actions/checkout@v4 |
| 40 | + with: |
| 41 | + ref: ${{ inputs['target-branch'] }} |
| 42 | + fetch-depth: 0 |
| 43 | + token: ${{ secrets.gh_token }} |
| 44 | + |
| 45 | + - name: Write version marker |
| 46 | + id: write_version |
| 47 | + env: |
| 48 | + NEXT_TAG: ${{ inputs['next-tag'] }} |
| 49 | + VERSION_FILE: ${{ inputs['version-file'] }} |
| 50 | + run: | |
| 51 | + set -euo pipefail |
| 52 | + if [ -z "${NEXT_TAG:-}" ]; then |
| 53 | + echo "next-tag input is required" >&2 |
| 54 | + exit 1 |
| 55 | + fi |
| 56 | + mkdir -p "$(dirname "$VERSION_FILE")" |
| 57 | + printf '%s\n' "$NEXT_TAG" > "$VERSION_FILE" |
| 58 | + echo "new_tag=${NEXT_TAG}" >> "$GITHUB_OUTPUT" |
| 59 | +
|
| 60 | + - name: Commit version marker |
| 61 | + env: |
| 62 | + VERSION_FILE: ${{ inputs['version-file'] }} |
| 63 | + NEW_TAG: ${{ steps.write_version.outputs.new_tag }} |
| 64 | + run: | |
| 65 | + set -euo pipefail |
| 66 | + git config --local user.name "github-actions[bot]" |
| 67 | + git config --local user.email "github-actions[bot]@users.noreply.github.com" |
| 68 | + git add "$VERSION_FILE" |
| 69 | + if git diff --cached --quiet; then |
| 70 | + echo "Version file already up to date." |
| 71 | + exit 0 |
| 72 | + fi |
| 73 | + git commit -m "Record version ${NEW_TAG}" |
| 74 | + git push origin HEAD:${{ inputs['target-branch'] }} |
0 commit comments