Skip to content

Commit 238c877

Browse files
Create tag-bump-commit.yml
1 parent d0174d5 commit 238c877

1 file changed

Lines changed: 93 additions & 0 deletions

File tree

.github/tag-bump-commit.yml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# ref from pxt-arcade/.github/tag-bump-commit.yml
2+
3+
name: Tag version on merged bump commit
4+
5+
on:
6+
workflow_call:
7+
outputs:
8+
did_tag:
9+
description: 'Whether a tag was created'
10+
value: ${{ jobs.return.outputs.did_tag }}
11+
12+
jobs:
13+
check-merge:
14+
uses: ./.github/workflows/check-if-merged-pr.yml
15+
16+
check-merge-outputs:
17+
needs: check-merge
18+
runs-on: ubuntu-latest
19+
if: always()
20+
steps:
21+
- name: check-merge outputs
22+
run: |
23+
echo "is_merged_pr = '${{ needs.check-merge.outputs.is_merged_pr }}'"
24+
echo "pr_head_sha = '${{ needs.check-merge.outputs.pr_head_sha }}'"
25+
26+
tag-version:
27+
needs: check-merge
28+
if: fromJSON(needs.check-merge.outputs.is_merged_pr || 'false') == true
29+
runs-on: ubuntu-latest
30+
outputs:
31+
did_tag: ${{ steps.tag-op.outputs.did_tag }}
32+
tag: ${{ steps.tag-op.outputs.tag }}
33+
steps:
34+
- uses: actions/checkout@v3
35+
with:
36+
fetch-depth: 0
37+
token: ${{ secrets.GITHUB_TOKEN }}
38+
39+
- name: Tag commit if it's a version bump
40+
id: tag-op
41+
shell: bash
42+
run: |
43+
set -euxo pipefail
44+
45+
COMMIT_SHA="${{ github.sha }}"
46+
echo "==> Current merge commit SHA: $COMMIT_SHA"
47+
48+
echo "==> Fetching commit message..."
49+
COMMIT_MSG=$(git log -1 --pretty=%s "$COMMIT_SHA")
50+
echo "==> Commit message: '$COMMIT_MSG'"
51+
52+
TAGGED=false
53+
54+
# Check if commit matches bump pattern and PR#
55+
if [[ "$COMMIT_MSG" =~ \[pxt-cli\]\ bump\ version\ to\ v([0-9]+\.[0-9]+\.[0-9]+)\ \(\#[0-9]+\) ]]; then
56+
VERSION="v${BASH_REMATCH[1]}"
57+
echo "==> Detected bump version: $VERSION"
58+
59+
# Check if tag already exists
60+
if git rev-parse "$VERSION" >/dev/null 2>&1; then
61+
echo "::warning::Tag $VERSION already exists — skipping tagging."
62+
else
63+
echo "==> Tagging $COMMIT_SHA with $VERSION"
64+
git tag "$VERSION" "$COMMIT_SHA"
65+
git push origin "$VERSION"
66+
echo "tag=$VERSION" >> "$GITHUB_OUTPUT"
67+
TAGGED=true
68+
fi
69+
else
70+
echo "==> No merged bump commit detected — skipping tag creation."
71+
fi
72+
73+
echo "==> did_tag=$TAGGED"
74+
echo "did_tag=$TAGGED" >> "$GITHUB_OUTPUT"
75+
76+
not-tag-version:
77+
needs: check-merge
78+
if: fromJSON(needs.check-merge.outputs.is_merged_pr || 'false') == false
79+
runs-on: ubuntu-latest
80+
outputs:
81+
did_tag: false
82+
steps:
83+
- run: echo "No tag because not a PR merge."
84+
85+
return:
86+
runs-on: ubuntu-latest
87+
needs: [tag-version, not-tag-version]
88+
if: always()
89+
outputs:
90+
did_tag: ${{ needs.tag-version.outputs.did_tag || false }}
91+
steps:
92+
- run: echo "Returning did_tag = ${{ needs.tag-version.outputs.did_tag || false }}"
93+
- run: echo "Returning tag = ${{ needs.tag-version.outputs.tag || '' }}"

0 commit comments

Comments
 (0)