-
Notifications
You must be signed in to change notification settings - Fork 0
108 lines (97 loc) · 3.8 KB
/
create-release.yml
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
name: Release and Versioning
on:
push:
branches:
- main
pull_request_review:
types: [submitted]
jobs:
create-release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref || github.ref_name }}
- name: Check if version was already bumped
id: version_check
if: github.event.review.state == 'approved'
run: |
# Find the commit where the branch diverged from main
git fetch origin main
MERGE_BASE=$(git merge-base origin/main HEAD)
# Check commits between merge-base and current HEAD
COMMITS=$(git log $MERGE_BASE..HEAD --format=%B)
if echo "$COMMITS" | grep -q "\[bot\] New pkg version:"; then
VERSION_COMMIT=$(echo "$COMMITS" | grep "\[bot\] New pkg version:" | head -n 1)
echo "::warning::Version was already bumped in this branch with commit message: $VERSION_COMMIT"
echo "skip_bump=true" >> $GITHUB_OUTPUT
else
echo "No version bump found in branch commits"
echo "skip_bump=false" >> $GITHUB_OUTPUT
fi
- name: Check PR labels
id: check_labels
if: |
steps.version_check.outputs.skip_bump != 'true' &&
github.event.review.state == 'approved'
env:
GH_TOKEN: ${{ github.token }}
run: |
if [ "${{ github.event_name }}" == "pull_request_review" ]; then
PR_NUMBER=${{ github.event.pull_request.number }}
else
PR_NUMBER=$(gh pr list --state merged --json number --jq '.[0].number')
fi
LABELS=$(gh pr view "$PR_NUMBER" --json labels --jq '.labels[].name')
echo "::notice::PR used to check version bump: #$PR_NUMBER"
echo "::notice::PR labels: "[${LABELS//$'\n'/,}]""
# Make script executable
chmod +x ./.github/ci-scripts/pr-label-check.sh
# Run the script and capture both output and exit code
RELEASE_TYPE=$(./.github/ci-scripts/pr-label-check.sh $PR_NUMBER 2>&1) || {
# If script exits with non-zero, output the error and exit
echo "::error::Script failed with output: $RELEASE_TYPE"
exit 1
}
# Only proceed if we have a valid release type
if [ -z "$RELEASE_TYPE" ]; then
echo "::error::No valid release type determined"
exit 1
fi
echo "version=$RELEASE_TYPE" >> $GITHUB_OUTPUT
echo "::notice::Release type: $RELEASE_TYPE"
if [ "$RELEASE_TYPE" == "no-release" ]; then
echo "::notice::PR is not flagged for release, skipping other steps"
fi
- name: Bump version
id: bump
if: |
steps.version_check.outputs.skip_bump != 'true' &&
steps.check_labels.outputs.version != 'no-release' &&
github.event.review.state == 'approved'
run: |
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
if [ "${{ steps.check_labels.outputs.version }}" == "alpha" ]; then
npm version -m "[bot] New pkg version: %s" --preid=alpha prerelease
else
npm version -m "[bot] New pkg version: %s" ${{ steps.check_labels.outputs.version }}
fi
git push
- name: Create GitHub Release
if: |
github.event_name == 'push' &&
github.ref == 'refs/heads/main' &&
steps.check_labels.outputs.version != 'no-release'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION=$(node -p "require('./package.json').version")
gh release create "v${VERSION}" \
--title "Release v${VERSION}" \
--generate-notes \
--prerelease \
--target "${GITHUB_SHA}"