-
Notifications
You must be signed in to change notification settings - Fork 1
93 lines (76 loc) · 2.43 KB
/
Copy pathrelease-on-merge.yml
File metadata and controls
93 lines (76 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
name: Create Release Tag and publish new version
on:
pull_request:
branches:
- main
types:
- closed
paths:
- "src/**"
- "pyproject.toml"
- "uv.lock"
- "README.md"
permissions:
contents: write
id-token: write # This is required for requesting the JWT for the OIDC provider
jobs:
# TODO: Re-enable tests when pushed
# test-core:
# if: github.event.pull_request.merged == true
# uses: ./.github/workflows/test.yml
# secrets: inherit
tag-release:
# needs: test-core
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Fetch tags
run: git fetch --tags
- name: Determine next version
id: versioning
run: |
# Get latest tag or fallback
LATEST_TAG=$(git tag --sort=-v:refname | head -n 1)
if [ -z "$LATEST_TAG" ]; then
LATEST_TAG="v0.0.0"
fi
echo "Latest tag: $LATEST_TAG"
VERSION=${LATEST_TAG#v}
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
BRANCH_NAME="${{ github.event.pull_request.head.ref }}"
echo "Merged branch: $BRANCH_NAME"
if [[ "$BRANCH_NAME" == fix/* || "$BRANCH_NAME" == patch/* || "$BRANCH_NAME" == chore/* ]]; then
PATCH=$((PATCH + 1))
elif [[ "$BRANCH_NAME" == feature/* || "$BRANCH_NAME" == minor/* ]]; then
MINOR=$((MINOR + 1))
PATCH=0
elif [[ "$BRANCH_NAME" == major/* ]]; then
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
else
echo "Branch does not trigger release."
exit 0
fi
NEW_VERSION="v$MAJOR.$MINOR.$PATCH"
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "Next version: $NEW_VERSION"
- name: Create and push tag
if: env.NEW_VERSION != ''
run: |
git config user.name "github-actions"
git config user.email "github-actions@github.com"
git tag $NEW_VERSION
git push origin $NEW_VERSION
publish:
needs: tag-release
if: github.event.pull_request.merged == true
uses: ./.github/workflows/publish.yml
with:
tag: ${{ needs.tag-release.outputs.new_version }}
secrets: inherit