Skip to content

Commit aa47fbf

Browse files
Checkout code so package.json can be found
1 parent d87edb1 commit aa47fbf

File tree

1 file changed

+69
-69
lines changed

1 file changed

+69
-69
lines changed

.github/workflows/create-release.yml

Lines changed: 69 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -13,91 +13,91 @@ jobs:
1313
permissions:
1414
contents: write
1515
pull-requests: write
16-
steps:
17-
- uses: actions/checkout@v4
18-
with:
19-
fetch-depth: 0
20-
ref: ${{ github.event.pull_request.head.ref || github.ref_name }}
16+
steps:
17+
- uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
ref: ${{ github.event.pull_request.head.ref || github.ref_name }}
2121

22-
- name: Check PR labels
23-
id: check_labels
24-
env:
25-
GH_TOKEN: ${{ github.token }}
26-
run: |
27-
PR_NUMBER=${{ github.event.pull_request.number }}
28-
echo "::notice::PR used to check version bump: #$PR_NUMBER"
29-
LABELS=$(gh pr view "$PR_NUMBER" --json labels --jq '.labels[].name')
22+
- name: Check PR labels
23+
id: check_labels
24+
env:
25+
GH_TOKEN: ${{ github.token }}
26+
run: |
27+
PR_NUMBER=${{ github.event.pull_request.number }}
28+
echo "::notice::PR used to check version bump: #$PR_NUMBER"
29+
LABELS=$(gh pr view "$PR_NUMBER" --json labels --jq '.labels[].name')
3030
31-
# Make script executable
32-
chmod +x ./.github/ci-scripts/pr-label-check.sh
33-
34-
# Run the script and capture both output and exit code
35-
RELEASE_TYPE=$(./.github/ci-scripts/pr-label-check.sh $PR_NUMBER 2>&1) || {
36-
# If script exits with non-zero, output the error and exit
37-
echo "::error::Script failed with output: $RELEASE_TYPE"
38-
exit 1
39-
}
31+
# Make script executable
32+
chmod +x ./.github/ci-scripts/pr-label-check.sh
4033
41-
echo "version=$RELEASE_TYPE" >> $GITHUB_OUTPUT
42-
echo "::notice::Release label detected: $RELEASE_TYPE"
43-
if [ "$RELEASE_TYPE" == "no-release" ]; then
44-
echo "::notice::PR is not flagged for release, skipping bump"
45-
fi
34+
# Run the script and capture both output and exit code
35+
RELEASE_TYPE=$(./.github/ci-scripts/pr-label-check.sh $PR_NUMBER 2>&1) || {
36+
# If script exits with non-zero, output the error and exit
37+
echo "::error::Script failed with output: $RELEASE_TYPE"
38+
exit 1
39+
}
4640
47-
- name: Bump version
48-
if: steps.check_labels.outputs.version != 'no-release'
49-
env:
50-
GH_TOKEN: ${{ github.token }}
51-
run: |
52-
chmod +x ./.github/ci-scripts/bump-check.sh
53-
# Capture only the last line of output as BUMP_CHECK
54-
BUMP_CHECK=$(./.github/ci-scripts/bump-check.sh | tail -n 1)
55-
if [ "$BUMP_CHECK" == "true" ]; then
56-
git config user.name "GitHub Actions"
57-
git config user.email "actions@github.com"
58-
if [ "${{ steps.check_labels.outputs.version }}" == "alpha" ]; then
59-
npm version -m "[bot] New pkg version: %s" --preid=alpha prerelease
60-
else
61-
npm version -m "[bot] New pkg version: %s" ${{ steps.check_labels.outputs.version }}
41+
echo "version=$RELEASE_TYPE" >> $GITHUB_OUTPUT
42+
echo "::notice::Release label detected: $RELEASE_TYPE"
43+
if [ "$RELEASE_TYPE" == "no-release" ]; then
44+
echo "::notice::PR is not flagged for release, skipping bump"
6245
fi
63-
git push
64-
gh pr comment ${{ github.event.pull_request.number }} --body "Auto-bumped version for release, this cannot be the last commit as bots can't trigger the workflows to pass the PR checks"
65-
fi
6646
67-
- name: Revert version bump
68-
if: steps.check_labels.outputs.version == 'no-release'
69-
env:
70-
GH_TOKEN: ${{ github.token }}
71-
run: |
72-
MERGE_BASE=$(git merge-base origin/main HEAD)
73-
COMMITS=$(git log $MERGE_BASE..HEAD --format=%H:%B)
74-
# Find the latest version bump commit
75-
VERSION_COMMIT_SHA=$(echo "$COMMITS" | grep ":\[bot\] New pkg version:" | head -n 1 | cut -d':' -f1)
76-
77-
if [ -n "$VERSION_COMMIT_SHA" ]; then
78-
# Count version bumps and reverts
79-
BUMP_COUNT=$(echo "$COMMITS" | grep -c ":\[bot\] New pkg version:" || true)
80-
REVERT_COUNT=$(echo "$COMMITS" | grep -c ":Revert.*\[bot\] New pkg version:" || true)
81-
82-
if [ $REVERT_COUNT -lt $BUMP_COUNT ]; then
47+
- name: Bump version
48+
if: steps.check_labels.outputs.version != 'no-release'
49+
env:
50+
GH_TOKEN: ${{ github.token }}
51+
run: |
52+
chmod +x ./.github/ci-scripts/bump-check.sh
53+
# Capture only the last line of output as BUMP_CHECK
54+
BUMP_CHECK=$(./.github/ci-scripts/bump-check.sh | tail -n 1)
55+
if [ "$BUMP_CHECK" == "true" ]; then
8356
git config user.name "GitHub Actions"
8457
git config user.email "actions@github.com"
85-
git revert --no-edit $VERSION_COMMIT_SHA
58+
if [ "${{ steps.check_labels.outputs.version }}" == "alpha" ]; then
59+
npm version -m "[bot] New pkg version: %s" --preid=alpha prerelease
60+
else
61+
npm version -m "[bot] New pkg version: %s" ${{ steps.check_labels.outputs.version }}
62+
fi
8663
git push
87-
gh pr comment ${{ github.event.pull_request.number }} --body "Reverted version bump as no-release label was detected"
88-
else
89-
echo "::notice::Version bump has already been reverted, skipping"
64+
gh pr comment ${{ github.event.pull_request.number }} --body "Auto-bumped version for release, this cannot be the last commit as bots can't trigger the workflows to pass the PR checks"
65+
fi
66+
67+
- name: Revert version bump
68+
if: steps.check_labels.outputs.version == 'no-release'
69+
env:
70+
GH_TOKEN: ${{ github.token }}
71+
run: |
72+
MERGE_BASE=$(git merge-base origin/main HEAD)
73+
COMMITS=$(git log $MERGE_BASE..HEAD --format=%H:%B)
74+
# Find the latest version bump commit
75+
VERSION_COMMIT_SHA=$(echo "$COMMITS" | grep ":\[bot\] New pkg version:" | head -n 1 | cut -d':' -f1)
76+
77+
if [ -n "$VERSION_COMMIT_SHA" ]; then
78+
# Count version bumps and reverts
79+
BUMP_COUNT=$(echo "$COMMITS" | grep -c ":\[bot\] New pkg version:" || true)
80+
REVERT_COUNT=$(echo "$COMMITS" | grep -c ":Revert.*\[bot\] New pkg version:" || true)
81+
82+
if [ $REVERT_COUNT -lt $BUMP_COUNT ]; then
83+
git config user.name "GitHub Actions"
84+
git config user.email "actions@github.com"
85+
git revert --no-edit $VERSION_COMMIT_SHA
86+
git push
87+
gh pr comment ${{ github.event.pull_request.number }} --body "Reverted version bump as no-release label was detected"
88+
else
89+
echo "::notice::Version bump has already been reverted, skipping"
90+
fi
9091
fi
91-
fi
92-
9392
9493
create-release:
9594
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
9695
runs-on: ubuntu-latest
9796
permissions:
9897
contents: write
9998
steps:
100-
- name: Create GitHub Release
99+
- uses: actions/checkout@v4
100+
- name: Create GitHub Release
101101
# if: steps.check_labels.outputs.version != 'no-release'
102102
env:
103103
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -107,4 +107,4 @@ jobs:
107107
--title "Release v${VERSION}" \
108108
--generate-notes \
109109
--prerelease \
110-
--target "${GITHUB_SHA}"
110+
--target "${GITHUB_SHA}"

0 commit comments

Comments
 (0)