Skip to content

Commit 3082667

Browse files
committed
chore: add RC releases
1 parent 37dc96f commit 3082667

File tree

1 file changed

+92
-2
lines changed

1 file changed

+92
-2
lines changed

.github/workflows/release.yml

Lines changed: 92 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
name: Release
2+
13
on:
24
push:
35
branches:
@@ -8,12 +10,100 @@ permissions:
810
contents: write
911
pull-requests: write
1012

11-
name: release-please
12-
1313
jobs:
1414
release-please:
1515
runs-on: ubuntu-latest
1616
steps:
1717
- uses: googleapis/release-please-action@v4
18+
id: release
1819
with:
1920
target-branch: ${{ github.ref_name }}
21+
22+
- uses: actions/checkout@v4
23+
if: ${{ steps.release.outputs.release_created == 'true' || steps.release.outputs.prs_created == 'true' }}
24+
with:
25+
fetch-depth: 0
26+
27+
- if: ${{ steps.release.outputs }}
28+
id: versions
29+
run: |
30+
set -ex
31+
32+
RELEASE_CANDIDATE=true
33+
NOT_RELEASE_CANDIDATE='${{ steps.release.outputs.release_created }}'
34+
if [ "$NOT_RELEASE_CANDIDATE" = "true" ]; then
35+
RELEASE_CANDIDATE=false
36+
fi
37+
38+
MAIN_RELEASE_VERSION=x
39+
RELEASE_VERSION=y
40+
41+
if [ "$RELEASE_CANDIDATE" = "true" ]; then
42+
# Release please doesn't tell you the candidate version when it
43+
# creates the PR, so we have to take it from the title.
44+
MAIN_RELEASE_VERSION=$(node -e "console.log('${{ steps.release.outputs.pr && fromJSON(steps.release.outputs.pr).title }}'.split(' ').reverse().find(x => x.match(/[0-9]+[.][0-9]+[.][0-9]+/)))")
45+
46+
# Use git describe tags to identify the number of commits the branch
47+
# is ahead of the most recent non-release-candidate tag, which is
48+
# part of the rc.<commit> value.
49+
RELEASE_VERSION=$MAIN_RELEASE_VERSION-rc.$(node -e "console.log('$(git describe --tags --exclude rc*)'.split('-')[1])")
50+
51+
# release-please only ignores releases that have a form like [A-Z0-9]<version>, so prefixing with rc<version>
52+
RELEASE_NAME="rc$RELEASE_VERSION"
53+
else
54+
MAIN_RELEASE_VERSION=${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }}.${{ steps.release.outputs.patch }}
55+
RELEASE_VERSION="$MAIN_RELEASE_VERSION"
56+
RELEASE_NAME="v$RELEASE_VERSION"
57+
fi
58+
59+
# Set environment variables
60+
{
61+
echo "MAIN_RELEASE_VERSION=${MAIN_RELEASE_VERSION}"
62+
echo "RELEASE_VERSION=${RELEASE_VERSION}"
63+
echo "RELEASE_CANDIDATE=${RELEASE_CANDIDATE}"
64+
echo "RELEASE_NAME=${RELEASE_NAME}"
65+
} >> "${GITHUB_ENV}"
66+
67+
# Set step outputs
68+
{
69+
echo "MAIN_RELEASE_VERSION=${MAIN_RELEASE_VERSION}"
70+
echo "RELEASE_VERSION=${RELEASE_VERSION}"
71+
echo "RELEASE_CANDIDATE=${RELEASE_CANDIDATE}"
72+
echo "RELEASE_NAME=${RELEASE_NAME}"
73+
} >> "${GITHUB_OUTPUT}"
74+
75+
- name: Create GitHub release and branches
76+
if: ${{ steps.release.outputs.release_created == 'true' || steps.release.outputs.prs_created == 'true' }}
77+
run: |
78+
set -ex
79+
80+
if [ "$RELEASE_CANDIDATE" = "true" ]; then
81+
PR_NUMBER='${{ steps.release.outputs.pr && fromJSON(steps.release.outputs.pr).number }}'
82+
83+
# Create release candidate
84+
GH_TOKEN='${{ secrets.GITHUB_TOKEN }}' gh release \
85+
create "$RELEASE_NAME" \
86+
--title "v$RELEASE_VERSION" \
87+
--prerelease \
88+
-n "This is a release candidate. See release-please PR #$PR_NUMBER for context."
89+
90+
# Comment on PR
91+
GH_TOKEN='${{ secrets.GITHUB_TOKEN }}' gh pr comment "$PR_NUMBER" \
92+
-b "Release candidate [v$RELEASE_VERSION](https://github.com/supabase/supabase-swift/releases/tag/$RELEASE_NAME) published."
93+
else
94+
if [ "$GITHUB_REF" == "refs/heads/main" ] || [ "$GITHUB_REF" == "refs/heads/master" ]; then
95+
IS_PATCH_ZERO=$(node -e "console.log('$RELEASE_VERSION'.endsWith('.0'))")
96+
97+
if [ "$IS_PATCH_ZERO" == "true" ]; then
98+
# Only create release branch if patch version is 0, as this
99+
# means that the release can be patched in the future.
100+
GH_TOKEN='${{ secrets.GITHUB_TOKEN }}' gh api \
101+
--method POST \
102+
-H "Accept: application/vnd.github+json" \
103+
-H "X-GitHub-Api-Version: 2022-11-28" \
104+
/repos/supabase/supabase-swift/git/refs \
105+
-f "ref=refs/heads/release/${RELEASE_VERSION}" \
106+
-f "sha=$GITHUB_SHA"
107+
fi
108+
fi
109+
fi

0 commit comments

Comments
 (0)