Skip to content

Commit 13067ca

Browse files
committed
add release action
1 parent 94455cc commit 13067ca

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

.github/workflows/release.yml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
release:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
19+
- name: Setup Node.js
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: 22
23+
cache: npm
24+
25+
- name: Install dependencies
26+
run: npm ci --ignore-scripts
27+
28+
- name: Run tests
29+
run: npm test
30+
31+
- name: Build
32+
run: npm run build
33+
34+
- name: Extract version from package.json
35+
id: pkg
36+
run: |
37+
VERSION=$(node -p "require('./package.json').version")
38+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
39+
40+
- name: Create npm tarball
41+
run: npm pack
42+
43+
- name: Check if release already exists
44+
id: check_release
45+
run: |
46+
TAG="v${{ steps.pkg.outputs.version }}"
47+
if gh release view "$TAG" > /dev/null 2>&1; then
48+
echo "exists=true" >> "$GITHUB_OUTPUT"
49+
else
50+
echo "exists=false" >> "$GITHUB_OUTPUT"
51+
fi
52+
env:
53+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
54+
55+
- name: Generate release notes
56+
if: steps.check_release.outputs.exists == 'false'
57+
id: notes
58+
run: |
59+
TAG="v${{ steps.pkg.outputs.version }}"
60+
GENERATED=$(gh api repos/${{ github.repository }}/releases/generate-notes \
61+
-f tag_name="$TAG" \
62+
-f target_commitish=main \
63+
--jq '.body')
64+
TARBALL_URL="https://github.com/${{ github.repository }}/releases/download/${TAG}/flame-cli-${{ steps.pkg.outputs.version }}.tgz"
65+
BODY="${GENERATED}
66+
67+
## Install
68+
69+
\`\`\`bash
70+
npm install -g ${TARBALL_URL}
71+
\`\`\`"
72+
73+
{
74+
echo "body<<RELEASE_NOTES_EOF"
75+
echo "$BODY"
76+
echo "RELEASE_NOTES_EOF"
77+
} >> "$GITHUB_OUTPUT"
78+
env:
79+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
80+
81+
- name: Create GitHub Release
82+
if: steps.check_release.outputs.exists == 'false'
83+
run: |
84+
TAG="v${{ steps.pkg.outputs.version }}"
85+
gh release create "$TAG" \
86+
flame-cli-${{ steps.pkg.outputs.version }}.tgz \
87+
--title "$TAG" \
88+
--notes "${{ steps.notes.outputs.body }}"
89+
env:
90+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)