Skip to content

Commit 202be62

Browse files
ci: add prerelease workflows (#236)
1 parent 2ee6ed5 commit 202be62

3 files changed

Lines changed: 110 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: prerelease-canary
2+
3+
permissions:
4+
contents: read
5+
id-token: write
6+
7+
on:
8+
push:
9+
branches:
10+
- main
11+
12+
jobs:
13+
publish:
14+
if: github.repository_owner == 'prismicio'
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v6
18+
- uses: actions/setup-node@v6
19+
with:
20+
node-version: 24
21+
registry-url: "https://registry.npmjs.org"
22+
- name: "Deprecate previous canary"
23+
run: |
24+
PACKAGE_NAME=$(jq -r ".name" package.json)
25+
PREVIOUS_VERSION=$(npm view "$PACKAGE_NAME" dist-tags.canary 2>/dev/null)
26+
if [ -n "$PREVIOUS_VERSION" ]; then
27+
npm deprecate "$PACKAGE_NAME@$PREVIOUS_VERSION" "Replaced by newer canary version"
28+
fi
29+
env:
30+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
31+
- run: npm ci
32+
- name: "Generate new version"
33+
run: |
34+
SHORT_SHA=$(git rev-parse --short HEAD)
35+
CURRENT_VERSION=$(jq -r '.version' package.json)
36+
VERSION="${CURRENT_VERSION}-canary.${SHORT_SHA}"
37+
npm version $VERSION --no-git-tag-version
38+
- run: npm publish --provenance --tag canary
39+
env:
40+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: prerelease-pr-cleanup
2+
3+
permissions:
4+
contents: read
5+
id-token: write
6+
7+
on:
8+
pull_request:
9+
types: [closed]
10+
11+
jobs:
12+
cleanup:
13+
if: github.repository_owner == 'prismicio'
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v6
17+
- uses: actions/setup-node@v6
18+
with:
19+
node-version: 24
20+
registry-url: "https://registry.npmjs.org"
21+
- name: "Deprecate PR prerelease"
22+
run: |
23+
PACKAGE_NAME=$(jq -r ".name" package.json)
24+
TAG="pr-${{ github.event.number }}"
25+
VERSION=$(npm view "$PACKAGE_NAME" dist-tags."$TAG" 2>/dev/null || echo "")
26+
if [ -n "$VERSION" ]; then
27+
npm deprecate "$PACKAGE_NAME@$VERSION" "PR ${{ github.event.number }} was closed"
28+
npm dist-tag rm "$PACKAGE_NAME" "$TAG"
29+
fi
30+
env:
31+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: prerelease-pr
2+
3+
permissions:
4+
contents: read
5+
id-token: write
6+
7+
on:
8+
pull_request:
9+
10+
jobs:
11+
publish:
12+
if: github.repository_owner == 'prismicio'
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v6
16+
- uses: actions/setup-node@v6
17+
with:
18+
node-version: 24
19+
registry-url: "https://registry.npmjs.org"
20+
- name: "Deprecate previous PR prerelease"
21+
run: |
22+
PACKAGE_NAME=$(jq -r ".name" package.json)
23+
TAG="pr-${{ github.event.number }}"
24+
PREVIOUS_VERSION=$(npm view "$PACKAGE_NAME" dist-tags."$TAG" 2>/dev/null)
25+
if [ -n "$PREVIOUS_VERSION" ]; then
26+
npm deprecate "$PACKAGE_NAME@$PREVIOUS_VERSION" "Replaced by newer prerelease version"
27+
fi
28+
env:
29+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
30+
- run: npm ci
31+
- name: "Generate new version"
32+
run: |
33+
SHORT_SHA=$(git rev-parse --short HEAD)
34+
CURRENT_VERSION=$(jq -r '.version' package.json)
35+
VERSION="${CURRENT_VERSION}-pr.${{ github.event.number }}.${SHORT_SHA}"
36+
npm version $VERSION --no-git-tag-version
37+
- run: npm publish --provenance --tag pr-${{ github.event.number }}
38+
env:
39+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

0 commit comments

Comments
 (0)