Skip to content

Commit d783bcd

Browse files
committed
ci: simplify release process
1 parent 982ef8c commit d783bcd

File tree

3 files changed

+43
-133
lines changed

3 files changed

+43
-133
lines changed

.github/workflows/release.yml

Lines changed: 31 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -4,158 +4,56 @@ on:
44
push:
55
branches:
66
- main
7-
- release/*
87

98
permissions:
10-
contents: read
9+
contents: write
10+
pull-requests: write
11+
id-token: write
1112

1213
jobs:
13-
release_please:
14+
release:
1415
runs-on: ubuntu-latest
15-
permissions:
16-
id-token: write
17-
contents: write
18-
pull-requests: write
1916
steps:
2017
- uses: googleapis/release-please-action@v4
2118
id: release
22-
with:
23-
release-type: go
24-
target-branch: ${{ github.ref_name }}
2519

2620
- uses: actions/checkout@v4
27-
if: ${{ steps.release.outputs.release_created == 'true' || steps.release.outputs.prs_created == 'true' }}
2821
with:
2922
fetch-depth: 0
3023

31-
- if: ${{ steps.release.outputs }}
32-
id: versions
33-
run: |
34-
set -ex
35-
36-
RELEASE_CANDIDATE=true
37-
NOT_RELEASE_CANDIDATE='${{ steps.release.outputs.release_created }}'
38-
if [ "$NOT_RELEASE_CANDIDATE" == "true" ]
39-
then
40-
RELEASE_CANDIDATE=false
41-
fi
42-
43-
MAIN_RELEASE_VERSION=x
44-
RELEASE_VERSION=y
45-
46-
if [ "$RELEASE_CANDIDATE" == "true" ]
47-
then
48-
# Release please doesn't tell you the candidate version when it
49-
# creates the PR, so we have to take it from the title.
50-
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]+/)))")
51-
52-
# Use git describe tags to identify the number of commits the branch
53-
# is ahead of the most recent non-release-candidate tag, which is
54-
# part of the rc.<commits> value.
55-
RELEASE_VERSION=$MAIN_RELEASE_VERSION-rc.$(node -e "console.log('$(git describe --tags --exclude rc*)'.split('-')[1])")
56-
57-
# release-please only ignores releases that have a form like [A-Z0-9]<version>, so prefixing with rc<version>
58-
RELEASE_NAME="rc$RELEASE_VERSION"
59-
else
60-
MAIN_RELEASE_VERSION=${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }}.${{ steps.release.outputs.patch }}
61-
RELEASE_VERSION="$MAIN_RELEASE_VERSION"
62-
RELEASE_NAME="v$RELEASE_VERSION"
63-
fi
64-
65-
echo "MAIN_RELEASE_VERSION=${MAIN_RELEASE_VERSION}" >> "${GITHUB_ENV}"
66-
echo "RELEASE_VERSION=${RELEASE_VERSION}" >> "${GITHUB_ENV}"
67-
echo "RELEASE_CANDIDATE=${RELEASE_CANDIDATE}" >> "${GITHUB_ENV}"
68-
echo "RELEASE_NAME=${RELEASE_NAME}" >> "${GITHUB_ENV}"
69-
70-
echo "MAIN_RELEASE_VERSION=${MAIN_RELEASE_VERSION}" >> "${GITHUB_OUTPUT}"
71-
echo "RELEASE_VERSION=${RELEASE_VERSION}" >> "${GITHUB_OUTPUT}"
72-
echo "RELEASE_CANDIDATE=${RELEASE_CANDIDATE}" >> "${GITHUB_OUTPUT}"
73-
echo "RELEASE_NAME=${RELEASE_NAME}" >> "${GITHUB_OUTPUT}"
74-
7524
- uses: actions/setup-node@v4
76-
if: ${{ steps.release.outputs.release_created == 'true' || steps.release.outputs.prs_created == 'true' }}
7725
with:
78-
node-version: 20
26+
node-version: 22
27+
registry-url: 'https://registry.npmjs.org'
7928

80-
# Ensure npm 11.5.1 or later is installed for trusted publishing support
81-
- name: Update npm
82-
run: npm install -g npm@latest
29+
- run: npm install -g npm@latest
8330

84-
- name: Build release artifacts
85-
if: ${{ steps.release.outputs.release_created == 'true' || steps.release.outputs.prs_created == 'true' }}
31+
- name: Determine version
32+
id: version
8633
run: |
87-
set -ex
88-
89-
echo "export const VERSION = '$RELEASE_VERSION';" > src/version.ts
90-
91-
npm ci
92-
npm run build
93-
94-
for f in package.json package-lock.json
95-
do
96-
sed -i 's|"version": "0.0.0",|"version": "'"$RELEASE_VERSION"'",|g' "$f"
97-
done
98-
99-
DIST_TAG=patched
100-
if [ "$RELEASE_CANDIDATE" == "true" ]
101-
then
102-
DIST_TAG=rc
103-
elif [ "$GITHUB_REF" == "refs/heads/main" ] || [ "$GITHUB_REF" == "refs/heads/master" ]
104-
then
105-
# This is the main branch and it's not a prerelease, so the dist-tag should be `latest`.
106-
DIST_TAG=latest
107-
elif [[ "$GITHUB_REF" == "refs/heads/release/"* ]]
108-
then
109-
# This is a release branch. We need to determine if this release
110-
# branch is the _latest_ release branch. If yes, use
111-
# DIST_TAG=latest. Make sure checkout action runs with
112-
# fetch-depth: 0!
113-
114-
LATEST_BRANCH=$(git branch -al origin/release/* --sort=-v:refname | head -n 1 | tr -d "* \t")
115-
REF_AS_REMOTE_BRANCH=$(echo "$GITHUB_REF" | sed "s|refs/heads/|remotes/origin/|g")
116-
117-
if [ "$LATEST_BRANCH" == "$REF_AS_REMOTE_BRANCH" ]
118-
then
119-
DIST_TAG=latest
120-
fi
34+
if [ "${{ steps.release.outputs.release_created }}" == "true" ]; then
35+
VERSION="${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }}.${{ steps.release.outputs.patch }}"
36+
TAG="latest"
37+
else
38+
# RC version from git describe, bump minor
39+
DESCRIBE=$(git describe --tags --always)
40+
BASE=$(echo "$DESCRIBE" | sed 's/^v//' | cut -d'-' -f1)
41+
MAJOR=$(echo "$BASE" | cut -d'.' -f1)
42+
MINOR=$(echo "$BASE" | cut -d'.' -f2)
43+
COMMITS=$(echo "$DESCRIBE" | cut -d'-' -f2)
44+
NEXT_MINOR=$((MINOR + 1))
45+
VERSION="${MAJOR}.${NEXT_MINOR}.0-rc.${COMMITS}"
46+
TAG="rc"
12147
fi
48+
echo "version=$VERSION" >> $GITHUB_OUTPUT
49+
echo "tag=$TAG" >> $GITHUB_OUTPUT
12250
123-
npm publish --provenance --tag "$DIST_TAG"
124-
125-
- name: Create GitHub release and branches
126-
if: ${{ steps.release.outputs.release_created == 'true' || steps.release.outputs.prs_created == 'true' }}
51+
- name: Build
12752
run: |
128-
set -ex
129-
130-
if [ "$RELEASE_CANDIDATE" == "true" ]
131-
then
132-
PR_NUMBER='${{ steps.release.outputs.pr && fromJSON(steps.release.outputs.pr).number }}'
133-
134-
GH_TOKEN='${{ github.token }}' gh release \
135-
create $RELEASE_NAME \
136-
--title "v$RELEASE_VERSION" \
137-
--prerelease \
138-
-n "This is a release candidate. See release-please PR #$PR_NUMBER for context."
139-
140-
GH_TOKEN='${{ github.token }}' gh pr comment "$PR_NUMBER" \
141-
-b "Release candidate [v$RELEASE_VERSION](https://github.com/supabase/ssr/releases/tag/$RELEASE_NAME) published."
142-
else
143-
if [ "$GITHUB_REF" == "refs/heads/main" ] || [ "$GITHUB_REF" == "refs/heads/master" ]
144-
then
145-
IS_PATCH_ZERO=$(node -e "console.log('$RELEASE_VERSION'.endsWith('.0'))")
146-
147-
if [ "$IS_PATCH_ZERO" == "true" ]
148-
then
149-
# Only create release branch if patch version is 0, as this
150-
# means that the release can be patched in the future.
53+
echo "export const VERSION = '${{ steps.version.outputs.version }}';" > src/version.ts
54+
npm ci
55+
npm run build
56+
npm version ${{ steps.version.outputs.version }} --no-git-tag-version
15157
152-
GH_TOKEN='${{ github.token }}' gh api \
153-
--method POST \
154-
-H "Accept: application/vnd.github+json" \
155-
-H "X-GitHub-Api-Version: 2022-11-28" \
156-
/repos/supabase/ssr/git/refs \
157-
-f "ref=refs/heads/release/${RELEASE_VERSION}" \
158-
-f "sha=$GITHUB_SHA"
159-
fi
160-
fi
161-
fi
58+
- name: Publish
59+
run: npm publish --provenance --tag ${{ steps.version.outputs.tag }}

.release-please-manifest.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
".": "0.8.0"
3+
}

release-please-config.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"packages": {
3+
".": {
4+
"release-type": "node",
5+
"package-name": "@supabase/ssr",
6+
"changelog-path": "CHANGELOG.md"
7+
}
8+
}
9+
}

0 commit comments

Comments
 (0)