Skip to content

Commit a3efcfe

Browse files
committed
1 parent 3cc1e4d commit a3efcfe

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# ❣❣❣ DO NOT EDIT ❣ THIS FILE IS AUTOMATICALLY SYNCED ❣ DO NOT EDIT ❣❣❣
2+
3+
name: semantic release
4+
5+
on:
6+
pull_request:
7+
types:
8+
- closed
9+
branches:
10+
- master
11+
12+
jobs:
13+
release:
14+
name: Release
15+
# ensures this only runs if the PR was actually merged, not just closed unmerged
16+
if: github.event.pull_request.merged == true
17+
runs-on: ubuntu-latest
18+
permissions:
19+
contents: write
20+
env:
21+
# toggle to 'false' to only push the tag and skip creating the GitHub Release
22+
CREATE_RELEASE: 'true'
23+
steps:
24+
- name: ⚡ Checkout repository ⚡
25+
uses: actions/checkout@v6
26+
with:
27+
# fetch all history so the workflow can find previous tags
28+
fetch-depth: 0
29+
30+
- name: ⚡ Parse bump type ⚡
31+
id: parse
32+
run: |
33+
TITLE="${{ github.event.pull_request.title }}"
34+
35+
if [[ "$TITLE" =~ ^\[major\] ]]; then
36+
echo "type=major" >> "$GITHUB_OUTPUT"
37+
elif [[ "$TITLE" =~ ^\[minor\] ]]; then
38+
echo "type=minor" >> "$GITHUB_OUTPUT"
39+
elif [[ "$TITLE" =~ ^\[patch\] ]]; then
40+
echo "type=patch" >> "$GITHUB_OUTPUT"
41+
else
42+
# Handles [none] or any PR title that lacks a recognized specifier
43+
echo "type=none" >> "$GITHUB_OUTPUT"
44+
fi
45+
46+
- name: ⚡ Increment version ⚡
47+
id: increment
48+
if: steps.parse.outputs.type != 'none'
49+
run: |
50+
# strip 'v' prefix if present, and sort them as versions
51+
LATEST_VERSION=$(git tag | sed 's/^v//' | sort -V | tail -n 1)
52+
53+
if [ -z "$LATEST_VERSION" ]; then
54+
LATEST_VERSION="0.0.0"
55+
fi
56+
57+
echo "Current highest version identified: $LATEST_VERSION"
58+
59+
IFS='.' read -r MAJOR MINOR PATCH <<< "$LATEST_VERSION"
60+
61+
if [ "${{ steps.parse.outputs.type }}" == "major" ]; then
62+
MAJOR=$((MAJOR + 1))
63+
MINOR=0
64+
PATCH=0
65+
elif [ "${{ steps.parse.outputs.type }}" == "minor" ]; then
66+
MINOR=$((MINOR + 1))
67+
PATCH=0
68+
elif [ "${{ steps.parse.outputs.type }}" == "patch" ]; then
69+
PATCH=$((PATCH + 1))
70+
fi
71+
72+
NEXT_VERSION="${MAJOR}.${MINOR}.${PATCH}"
73+
echo "version=$NEXT_VERSION" >> "$GITHUB_OUTPUT"
74+
75+
- name: ⚡ Create tag ⚡
76+
if: steps.parse.outputs.type != 'none'
77+
run: |
78+
git config user.name "rarest automation"
79+
git config user.email "automation@noreply.rarestype.com"
80+
81+
git tag "${{ steps.increment.outputs.version }}"
82+
git push origin "${{ steps.increment.outputs.version }}"
83+
84+
- name: ⚡ Create release ⚡
85+
if: steps.parse.outputs.type != 'none' && env.CREATE_RELEASE == 'true'
86+
run: |
87+
gh release create "${{ steps.increment.outputs.version }}" \
88+
--title "${{ steps.increment.outputs.version }}" \
89+
--generate-notes
90+
env:
91+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# ❣❣❣ DO NOT EDIT ❣ THIS FILE IS AUTOMATICALLY SYNCED ❣ DO NOT EDIT ❣❣❣
2+
3+
name: semantic pr title
4+
5+
on:
6+
pull_request:
7+
types: [opened, edited, synchronize, reopened]
8+
9+
jobs:
10+
validate:
11+
name: Validate PR title
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: 🌟 Check format 🌟
15+
env:
16+
TITLE: ${{ github.event.pull_request.title }}
17+
run: |
18+
if [[ ! "$TITLE" =~ ^\[(major|minor|patch|none)\]:\ .+ ]]; then
19+
echo "::error::Invalid PR title format!"
20+
echo "Expected format: '[type]: description'"
21+
echo "Valid types: major, minor, patch, none"
22+
echo "Example: '[patch]: blah blah blah'"
23+
exit 1
24+
fi
25+
echo "💘 PR title is valid!"

0 commit comments

Comments
 (0)