Skip to content

Commit 075f457

Browse files
feat(ci): add reusable package-release workflow
Add reusable GitHub Actions workflow for semantic-release of TypeScript packages: - Based on python-nix-template pattern, adapted for TypeScript/bun - Uses cycjimmy/semantic-release-action@v4 with semantic-release v24 - Supports workflow_dispatch and workflow_call triggers - Supports dry-run mode for testing releases - Uses bun instead of uv/yarn for package management - Removed Python-specific steps (uv build, PyPI publish) - Outputs: version, released, tag for downstream workflows
1 parent 9efa88c commit 075f457

File tree

1 file changed

+144
-0
lines changed

1 file changed

+144
-0
lines changed
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
name: Package Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
package-path:
7+
description: "Path to the package directory"
8+
required: true
9+
type: string
10+
package-name:
11+
description: "Name of the package"
12+
required: true
13+
type: string
14+
release-dry-run:
15+
description: "Whether to run the release in dry-run mode"
16+
required: false
17+
type: boolean
18+
default: false
19+
debug-enabled:
20+
description: "Enable tmate debug session"
21+
required: false
22+
type: boolean
23+
default: false
24+
checkout-ref:
25+
description: "Git ref to checkout"
26+
required: false
27+
type: string
28+
default: ""
29+
30+
workflow_call:
31+
inputs:
32+
package-path:
33+
description: "Path to the package directory"
34+
required: true
35+
type: string
36+
package-name:
37+
description: "Name of the package"
38+
required: true
39+
type: string
40+
release-dry-run:
41+
description: "Whether to run the release in dry-run mode"
42+
required: false
43+
type: string
44+
default: "false"
45+
debug-enabled:
46+
description: "Enable tmate debug session"
47+
required: false
48+
type: boolean
49+
default: false
50+
checkout-ref:
51+
description: "Git ref to checkout"
52+
required: false
53+
type: string
54+
default: ""
55+
secrets:
56+
GITHUB_TOKEN:
57+
required: true
58+
outputs:
59+
version:
60+
description: "Released version"
61+
value: ${{ jobs.release.outputs.version }}
62+
released:
63+
description: "Whether a new release was published"
64+
value: ${{ jobs.release.outputs.released }}
65+
tag:
66+
description: "Git tag created for the release"
67+
value: ${{ jobs.release.outputs.tag }}
68+
69+
defaults:
70+
run:
71+
shell: bash
72+
73+
permissions:
74+
contents: write
75+
id-token: write
76+
77+
jobs:
78+
release:
79+
runs-on: ubuntu-latest
80+
permissions:
81+
contents: write
82+
id-token: write
83+
outputs:
84+
version: ${{ steps.semantic-release.outputs.new_release_version }}
85+
released: ${{ steps.semantic-release.outputs.new_release_published || 'false' }}
86+
tag: ${{ steps.semantic-release.outputs.new_release_git_tag }}
87+
steps:
88+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # ratchet:actions/checkout@v4
89+
with:
90+
fetch-depth: 0
91+
ref: ${{ inputs.checkout-ref != '' && inputs.checkout-ref || github.ref }}
92+
persist-credentials: false
93+
94+
- name: Setup Bun
95+
uses: oven-sh/setup-bun@v2
96+
with:
97+
bun-version: "1.1.38"
98+
99+
- name: Install dependencies
100+
if: ${{ inputs.release-dry-run == 'true' }}
101+
run: |
102+
bun install
103+
git log --oneline --branches --tags
104+
105+
- name: Test semantic-release (dry-run)
106+
if: ${{ inputs.release-dry-run == 'true' }}
107+
env:
108+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
109+
working-directory: ${{ inputs.package-path }}
110+
run: |
111+
unset GITHUB_ACTIONS
112+
bun run test-release
113+
114+
- name: Run semantic-release
115+
id: semantic-release
116+
uses: cycjimmy/semantic-release-action@b1b432f13acb7768e0c8efdec416d363a57546f2 # ratchet:cycjimmy/semantic-release-action@v4
117+
with:
118+
working_directory: ${{ inputs.package-path }}
119+
dry_run: ${{ inputs.release-dry-run == 'true' }}
120+
semantic_version: 24
121+
extra_plugins: |
122+
@semantic-release/changelog
123+
@semantic-release/git
124+
semantic-release-major-tag
125+
semantic-release-monorepo
126+
conventional-changelog-conventionalcommits
127+
ci: ${{ inputs.release-dry-run == 'false' }}
128+
env:
129+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
130+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
131+
GITHUB_ACTIONS: ${{ inputs.release-dry-run == 'false' }}
132+
133+
- name: Setup tmate debug session
134+
uses: mxschmitt/action-tmate@e5c7151931ca95bad1c6f4190c730ecf8c7dde48 # ratchet:mxschmitt/action-tmate@v3
135+
if: ${{ inputs.debug-enabled }}
136+
137+
- name: Log release information
138+
run: |
139+
if [ "${{ steps.semantic-release.outputs.new_release_published }}" == "true" ]; then
140+
echo "Package ${{ inputs.package-name }} released version ${{ steps.semantic-release.outputs.new_release_version }}"
141+
echo "Tag: ${{ steps.semantic-release.outputs.new_release_git_tag }}"
142+
else
143+
echo "No release needed for ${{ inputs.package-name }}"
144+
fi

0 commit comments

Comments
 (0)