Skip to content

Merge test changes to main (#21) #19

Merge test changes to main (#21)

Merge test changes to main (#21) #19

Workflow file for this run

name: "Add version tag on push to main or test"
on:
push:
branches:
- main
- test
jobs:
tag-on-push:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
statuses: read
# Additional permissions are a workaround for gh cli trying to read projects during edit
checks: read
repository-projects: read
issues: read
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # used by version (git) operations to find the most recent tag outside of this branch
- name: Check files changed
id: check-changes
run: |
# git diff --name-status ${{ github.event.before }}..${{ github.event.after }}
diffs=$(git diff --name-status ${{ github.event.before }}..${{ github.event.after }} | wc -l)
echo "diffs=$diffs"
if ((diffs > 0)); then
echo "setting has_diff true"
echo "has_diff=true" >> "$GITHUB_OUTPUT"
else
echo "setting has_diff false"
echo "has_diff=false" >> "$GITHUB_OUTPUT"
fi
- name: Get next version
uses: reecetech/[email protected]
id: version
if: ${{ steps.check-changes.outputs.has_diff == 'true' }}
with:
scheme: semver
increment: minor
# TODO: Could we use increment patch when bugfixes land on dev?
- name: Create tag
uses: actions/github-script@v7
if: ${{ steps.check-changes.outputs.has_diff == 'true' }}
with:
github-token: ${{ secrets.WORKFLOW_TOKEN }}
script: |
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/tags/v${{ steps.version.outputs.version }}',
sha: context.sha
})
- name: Update promotion PR (test)
id: update-pr-test
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: ${{ steps.check-changes.outputs.has_diff == 'true' && github.ref == 'refs/heads/test' }}
run: |
# Debug output:
gh pr list --json baseRefName,headRefName,number
pr_number=$(gh pr list --json baseRefName,headRefName,number --jq 'map(select(.baseRefName == "main" and .headRefName == "test")) | .[0].number')
echo "pr_number=$pr_number"
echo "pr_number=$pr_number" >> "$GITHUB_OUTPUT"
gh pr edit $pr_number --title "Merge test changes to main - ${{ steps.version.outputs.v-version }}"
- name: Create or update version tag comment in promotion PR (test)
uses: im-open/[email protected]
if: ${{ steps.check-changes.outputs.has_diff == 'true' && github.ref == 'refs/heads/test' }}
with:
pr-number: ${{ steps.update-pr-test.outputs.pr_number }}
github-token: ${{ secrets.GITHUB_TOKEN }}
comment-identifier: "current-tag"
comment-content: "🕔 This PR currently contains the tag: ${{ steps.version.outputs.v-version }} which supersedes ${{ steps.version.outputs.current-v-version }}"