Skip to content

Commit 9d3904f

Browse files
committed
👷 Add GitHub Action for Release
1 parent 8a01abf commit 9d3904f

1 file changed

Lines changed: 80 additions & 0 deletions

File tree

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Tag Release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: write # Needed for tags & releases
11+
12+
concurrency:
13+
group: tag-release-${{ github.ref }}
14+
cancel-in-progress: false
15+
16+
jobs:
17+
tag-release:
18+
runs-on: brixion-runners
19+
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 0
25+
fetch-tags: true
26+
token: ${{ secrets.GITHUB_TOKEN }}
27+
28+
- name: Sync & prune tags
29+
run: |
30+
git fetch --tags --force --prune
31+
32+
- name: Determine version from composer.json
33+
id: version
34+
run: |
35+
VERSION=$(jq -r '.version // empty' composer.json)
36+
if [ -z "$VERSION" ]; then
37+
echo "composer.json does not have a 'version' field"; exit 1
38+
fi
39+
40+
# prefix with 'v' if it's not already
41+
if [[ "$VERSION" =~ ^v ]]; then
42+
TAG="$VERSION"
43+
else
44+
TAG="v$VERSION"
45+
fi
46+
47+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
48+
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
49+
echo "Resolved tag: $TAG"
50+
51+
- name: Check if tag exists on origin
52+
id: check_tag
53+
run: |
54+
TAG="${{ steps.version.outputs.tag }}"
55+
if git ls-remote --tags origin | grep -q "refs/tags/${TAG}$"; then
56+
echo "exists=true" >> "$GITHUB_OUTPUT"
57+
echo "Tag ${TAG} already exists on origin"
58+
else
59+
echo "exists=false" >> "$GITHUB_OUTPUT"
60+
echo "Tag ${TAG} does not exist on origin"
61+
fi
62+
63+
- name: Create and push tag
64+
if: steps.check_tag.outputs.exists == 'false'
65+
run: |
66+
TAG="${{ steps.version.outputs.tag }}"
67+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
68+
git config --global user.name "github-actions[bot]"
69+
git tag -a "${TAG}" -m "Version ${TAG}"
70+
git push origin "refs/tags/${TAG}"
71+
72+
- name: Create GitHub Release (autogenerated notes)
73+
if: steps.check_tag.outputs.exists == 'false'
74+
uses: softprops/action-gh-release@v2
75+
with:
76+
tag_name: ${{ steps.version.outputs.tag }}
77+
name: Version ${{ steps.version.outputs.tag }}
78+
generate_release_notes: true
79+
env:
80+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)