-
Notifications
You must be signed in to change notification settings - Fork 75
73 lines (62 loc) · 2.52 KB
/
Copy pathrelease-automation.yml
File metadata and controls
73 lines (62 loc) · 2.52 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
name: Release Automation
on:
push:
branches:
- main
- 'release-*'
paths:
- 'VERSION'
permissions: {}
jobs:
cut-release:
name: Cut Release
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
with:
fetch-depth: 0
persist-credentials: true
- name: Read Version
id: version
run: |
VERSION=$(cat VERSION | tr -d '[:space:]')
echo "version=${VERSION}" >> $GITHUB_OUTPUT
# Basic semver validation (e.g. v1.2.3)
if ! [[ "$VERSION" =~ ^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$ ]]; then
echo "Error: Invalid semver format in VERSION file: $VERSION"
exit 1
fi
# Extract patch number to determine if we need to cut a new release branch
PATCH_NUM=$(echo "$VERSION" | sed -n 's/^v[0-9]*\.[0-9]*\.\([0-9]*\).*/\1/p')
echo "patch_num=${PATCH_NUM}" >> $GITHUB_OUTPUT
echo "Cutting release for version: $VERSION (Patch: $PATCH_NUM)"
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Create and Push Tag
run: |
VERSION=${{ steps.version.outputs.version }}
if git ls-remote --tags origin refs/tags/${VERSION} | grep -q "refs/tags/${VERSION}$"; then
echo "Tag ${VERSION} already exists. Skipping tag creation."
else
git tag -a "${VERSION}" -m "Release ${VERSION}"
git push origin "${VERSION}"
echo "Successfully pushed tag ${VERSION}"
fi
- name: Create and Push Release Branch
if: steps.version.outputs.patch_num == '0'
run: |
VERSION=${{ steps.version.outputs.version }}
BRANCH_NAME="release-${VERSION}"
if git ls-remote --heads origin refs/heads/${BRANCH_NAME} | grep -q "refs/heads/${BRANCH_NAME}$"; then
echo "Branch ${BRANCH_NAME} already exists. Skipping branch creation."
else
# We are already on the commit that triggered the workflow (the merge commit).
git checkout -b "${BRANCH_NAME}"
git push origin "${BRANCH_NAME}"
echo "Successfully pushed branch ${BRANCH_NAME}"
fi