Skip to content

Commit 8e8d267

Browse files
committed
chore: create github release and separate publish workflow into 3 jobs
1 parent d0fc987 commit 8e8d267

File tree

1 file changed

+49
-7
lines changed

1 file changed

+49
-7
lines changed

.github/workflows/publish.yml

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ on:
66
- main
77
paths:
88
- package.json
9-
release:
10-
types: [created]
119
workflow_dispatch:
1210

1311
jobs:
14-
publish:
15-
name: Publish
12+
tag:
13+
name: Tag
1614
runs-on: ubuntu-latest
1715
permissions:
1816
contents: write
19-
id-token: write
17+
outputs:
18+
created: ${{ steps.version_tag.outputs.created }}
19+
version_tag: ${{ steps.version_tag.outputs.version_tag }}
2020
steps:
2121
- name: Checkout code
2222
uses: actions/checkout@v4
@@ -26,21 +26,63 @@ jobs:
2626
uses: oven-sh/setup-bun@v2
2727
with:
2828
bun-version: latest
29-
- name: Install dependencies
30-
run: NODE_ENV=development bun i
3129
- name: Ensure version tag exists
30+
id: version_tag
3231
run: |
3332
VERSION=$(bun -p "require('./package.json').version")
3433
VERSION_TAG="v${VERSION}"
3534
35+
echo "version_tag=${VERSION_TAG}" >> $GITHUB_OUTPUT
36+
echo "created=false" >> $GITHUB_OUTPUT
37+
3638
git fetch --tags
3739
3840
if ! git rev-parse "${VERSION_TAG}" >/dev/null 2>&1; then
3941
git config user.name "github-actions[bot]"
4042
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
4143
git tag "${VERSION_TAG}"
4244
git push origin "${VERSION_TAG}"
45+
echo "created=true" >> $GITHUB_OUTPUT
4346
echo "Created and pushed ${VERSION_TAG}."
4447
fi
48+
49+
publish:
50+
name: Publish
51+
runs-on: ubuntu-latest
52+
permissions:
53+
id-token: write
54+
steps:
55+
- name: Checkout code
56+
uses: actions/checkout@v4
57+
- name: Setup Bun
58+
uses: oven-sh/setup-bun@v2
59+
with:
60+
bun-version: latest
61+
- name: Install dependencies
62+
run: NODE_ENV=development bun i
4563
- name: Build and publish
4664
run: bunx npm publish --provenance --access public
65+
66+
release:
67+
name: Release
68+
runs-on: ubuntu-latest
69+
needs: [tag]
70+
if: needs.tag.outputs.created == 'true'
71+
permissions:
72+
contents: write
73+
steps:
74+
- name: Create release from new tag
75+
uses: actions/github-script@v7
76+
with:
77+
script: |
78+
const tag = '${{ needs.tag.outputs.version_tag }}';
79+
const prerelease = tag.includes('-');
80+
81+
await github.rest.repos.createRelease({
82+
owner: context.repo.owner,
83+
repo: context.repo.repo,
84+
tag_name: tag,
85+
name: tag,
86+
prerelease,
87+
generate_release_notes: true,
88+
});

0 commit comments

Comments
 (0)