Skip to content

Commit 6f8a8d2

Browse files
committed
feat: add release workflow
1 parent 15d0d59 commit 6f8a8d2

File tree

2 files changed

+127
-2
lines changed

2 files changed

+127
-2
lines changed

.github/workflows/release.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
permissions:
9+
contents: write # Need write access to create releases
10+
11+
jobs:
12+
create-release:
13+
name: Create GitHub Release
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
19+
- name: Create Release
20+
uses: softprops/action-gh-release@v2
21+
with:
22+
tag_name: ${{ github.ref_name }}
23+
name: Release ${{ github.ref_name }}
24+
draft: false
25+
prerelease: false
26+
generate_release_notes: true
27+
body: |
28+
## 🚀 Usage
29+
```yaml
30+
- uses: tkstang/github-typescript@${{ github.ref_name }}
31+
with:
32+
ts-file: .github/scripts/my-script.ts
33+
node-version: "22"
34+
args: |
35+
{
36+
"key": "value"
37+
}
38+
```
39+
40+
## 📋 Full Changelog
41+
See below for auto-generated release notes.
42+
43+
update-major-tag:
44+
name: Update Major Version Tag
45+
runs-on: ubuntu-latest
46+
needs: create-release
47+
if: startsWith(github.ref, 'refs/tags/v') && !contains(github.ref, '-')
48+
steps:
49+
- name: Checkout
50+
uses: actions/checkout@v4
51+
with:
52+
fetch-depth: 0
53+
54+
- name: Update major version tag
55+
run: |
56+
# Extract major version from tag (e.g., v1.2.3 -> v1)
57+
TAG_NAME=${GITHUB_REF#refs/tags/}
58+
MAJOR_VERSION=$(echo $TAG_NAME | cut -d. -f1)
59+
60+
echo "Updating $MAJOR_VERSION to point to $TAG_NAME"
61+
62+
# Create or update the major version tag
63+
git config user.name "github-actions[bot]"
64+
git config user.email "github-actions[bot]@users.noreply.github.com"
65+
66+
# Delete existing major tag if it exists
67+
git tag -d $MAJOR_VERSION 2>/dev/null || true
68+
git push origin :refs/tags/$MAJOR_VERSION 2>/dev/null || true
69+
70+
# Create new major tag pointing to current commit
71+
git tag $MAJOR_VERSION
72+
git push origin $MAJOR_VERSION

README.md

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ jobs:
3838
with:
3939
ts-file: .github/scripts/fetch-status.ts
4040
node-version: '22'
41-
args: ${{ toJson({ url: 'https://example.com/health' }) }}
41+
args: |
42+
{
43+
"url": "https://example.com/health"
44+
}
4245
4346
- name: Show result
4447
run: echo '${{ steps.run.outputs.result }}'
@@ -56,7 +59,7 @@ jobs:
5659
| Name | Required | Default | Description |
5760
| ------------------- | -------- | ---------: | -------------------------------------------------------------------------------------------- |
5861
| `ts-file` | ✅ | — | Path to your TypeScript entry file (relative to `working-directory`). |
59-
| `args` | | `"{}"` | JSON string passed as `args` to your script's default export. |
62+
| `args` | | `"{}"` | JSON string passed as `args` to your script's default export. Use multiline YAML format for complex objects. |
6063
| `working-directory` | | `"."` | Directory where bundling and imports resolve; bundle outputs go to `./.github-script-build`. |
6164
| `node-version` | | `"22"` | Node target for bundling (affects `esbuild --target=nodeXX`). |
6265
| `esbuild-version` | | `"0.24.0"` | esbuild version used to bundle. |
@@ -211,6 +214,36 @@ Cache key factors:
211214

212215
## Usage patterns
213216

217+
**Pass static arguments:**
218+
219+
```yaml
220+
- uses: tkstang/github-typescript@v1
221+
with:
222+
ts-file: .github/scripts/my-task.ts
223+
args: |
224+
{
225+
"environment": "production",
226+
"retries": 3,
227+
"endpoints": ["api1", "api2"]
228+
}
229+
```
230+
231+
**Pass dynamic arguments from step outputs:**
232+
233+
```yaml
234+
- name: Get deployment info
235+
id: deploy
236+
run: |
237+
echo "version=1.2.3" >> $GITHUB_OUTPUT
238+
echo "region=us-east-1" >> $GITHUB_OUTPUT
239+
echo "config={\"database\":\"prod\",\"replicas\":3}" >> $GITHUB_OUTPUT
240+
241+
- uses: tkstang/github-typescript@v1
242+
with:
243+
ts-file: .github/scripts/deploy.ts
244+
args: '${{ toJson(steps.deploy.outputs) }}'
245+
```
246+
214247
**Return JSON result:**
215248

216249
```yaml
@@ -272,6 +305,26 @@ Cache key factors:
272305

273306
- **Cannot find module 'axios'** → ensure you installed deps where `working-directory` can see them and that the wrapper's build step sets `NODE_PATH` accordingly.
274307
- **`TypeError: run is not a function`** → your script must **default export** a function (`export default async function run(...) {}`).
308+
- **YAML parsing errors with `args`** → for static objects, use multiline YAML format:
309+
```yaml
310+
args: |
311+
{
312+
"key": "value",
313+
"array": ["item1", "item2"]
314+
}
315+
```
316+
For dynamic values from step outputs or variables, use quoted `toJson()`:
317+
```yaml
318+
# Pass all step outputs as an object
319+
args: '${{ toJson(steps.previous.outputs) }}'
320+
321+
# Pass workflow variables
322+
args: '${{ toJson(vars) }}'
323+
324+
# If you need to parse a JSON string first, use fromJson() (but not with toJson())
325+
# Example: steps.data.outputs.config = '{"key": "value"}'
326+
- run: echo "Key is ${{ fromJson(steps.data.outputs.config).key }}"
327+
```
275328
- **Output too large** → use artifacts instead of step outputs, or switch `result-encoding` to `string` if you only need a short message.
276329
- **Cache misses** → narrow `hashFiles(...)` to your scripts subdir and lockfile; keep Node/esbuild versions consistent.
277330

0 commit comments

Comments
 (0)