Skip to content

Commit e55a89d

Browse files
committed
chore: add release
1 parent 036e3b5 commit e55a89d

9 files changed

Lines changed: 1027 additions & 46 deletions

File tree

.github/workflows/README.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# GitHub Actions Workflows
2+
3+
## Release Workflow
4+
5+
The `release.yml` workflow automatically builds and publishes the facet CLI on every push to the `main` branch.
6+
7+
### What it does
8+
9+
1. **Auto-bumps version** - Increments patch version in `cli/package.json` and `package.json`
10+
2. **Builds standalone binaries** - Creates platform-specific executables for:
11+
- Linux (x64)
12+
- macOS (ARM64)
13+
- Windows (x64)
14+
3. **Creates GitHub Release** - Publishes a new release with all binaries attached
15+
4. **Publishes to npm** - Publishes the package to npm registry
16+
17+
### Setup Requirements
18+
19+
Before this workflow can run successfully, you need to configure:
20+
21+
#### 1. NPM Token
22+
23+
1. Generate an npm access token at https://www.npmjs.com/settings/YOUR_USERNAME/tokens
24+
2. Select "Automation" token type
25+
3. Add it as a repository secret:
26+
- Go to your repository on GitHub
27+
- Navigate to Settings → Secrets and variables → Actions
28+
- Click "New repository secret"
29+
- Name: `NPM_TOKEN`
30+
- Value: Your npm token
31+
32+
#### 2. Repository Permissions
33+
34+
Ensure GitHub Actions has permission to push to main and create releases:
35+
36+
1. Go to Settings → Actions → General
37+
2. Under "Workflow permissions", select:
38+
- ✅ Read and write permissions
39+
- ✅ Allow GitHub Actions to create and approve pull requests
40+
41+
### How to Trigger a Release
42+
43+
Simply push to the `main` branch:
44+
45+
```bash
46+
git push origin main
47+
```
48+
49+
The workflow will automatically:
50+
- Bump the version
51+
- Build binaries for all platforms
52+
- Create a GitHub release with binaries
53+
- Publish to npm
54+
55+
### Manual Release (Alternative)
56+
57+
If you prefer manual releases, you can:
58+
59+
1. Update version manually in `cli/package.json`
60+
2. Create and push a git tag:
61+
```bash
62+
git tag v1.2.3
63+
git push origin v1.2.3
64+
```
65+
3. Modify the workflow trigger to use `tags` instead of `push`
66+
67+
### Workflow Jobs
68+
69+
The workflow consists of 4 jobs that run in sequence:
70+
71+
1. **version-bump** - Increments version and creates git tag
72+
2. **build-binaries** - Builds binaries on Linux, macOS, and Windows (runs in parallel)
73+
3. **create-release** - Creates GitHub release with all binaries
74+
4. **publish-npm** - Publishes package to npm registry
75+
76+
### Troubleshooting
77+
78+
**Build fails on "npm version patch"**
79+
- Check that `cli/package.json` exists and has a valid version field
80+
81+
**Binary build fails**
82+
- Ensure Bun is installed correctly (the workflow uses `oven-sh/setup-bun@v2`)
83+
- Check that `npm run build:cli` works locally
84+
85+
**npm publish fails**
86+
- Verify `NPM_TOKEN` secret is set correctly
87+
- Check that the package name in `package.json` is available on npm
88+
- Ensure you have publishing rights to the `@flanksource` scope
89+
90+
**GitHub release fails**
91+
- Verify repository has "Read and write permissions" for workflows
92+
- Check that the tag doesn't already exist
93+
94+
### Customization
95+
96+
To modify the workflow:
97+
98+
- **Change versioning strategy**: Edit the `npm version patch` command in the `version-bump` job
99+
- **Add more platforms**: Add entries to the matrix strategy in `build-binaries`
100+
- **Change trigger**: Modify the `on:` section at the top of the workflow

.github/workflows/release.yml

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
name: Release and Publish
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
permissions:
9+
contents: write
10+
packages: write
11+
12+
jobs:
13+
version-bump:
14+
name: Bump Version
15+
runs-on: ubuntu-latest
16+
outputs:
17+
new_version: ${{ steps.bump.outputs.new_version }}
18+
new_tag: ${{ steps.bump.outputs.new_tag }}
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0
24+
token: ${{ secrets.GITHUB_TOKEN }}
25+
26+
- name: Setup Node.js
27+
uses: actions/setup-node@v4
28+
with:
29+
node-version: '18'
30+
31+
- name: Configure Git
32+
run: |
33+
git config user.name "github-actions[bot]"
34+
git config user.email "github-actions[bot]@users.noreply.github.com"
35+
36+
- name: Bump version
37+
id: bump
38+
run: |
39+
cd cli
40+
npm version patch --no-git-tag-version
41+
NEW_VERSION=$(node -p "require('./package.json').version")
42+
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
43+
echo "new_tag=v$NEW_VERSION" >> $GITHUB_OUTPUT
44+
cd ..
45+
46+
# Update root package.json version to match
47+
npm version $NEW_VERSION --no-git-tag-version --allow-same-version
48+
49+
git add cli/package.json package.json package-lock.json cli/package-lock.json
50+
git commit -m "chore: bump version to $NEW_VERSION"
51+
git tag "v$NEW_VERSION"
52+
git push origin main
53+
git push origin "v$NEW_VERSION"
54+
55+
build-binaries:
56+
name: Build Binary (${{ matrix.os }})
57+
needs: version-bump
58+
runs-on: ${{ matrix.os }}
59+
strategy:
60+
matrix:
61+
include:
62+
- os: ubuntu-latest
63+
platform: linux
64+
arch: x64
65+
- os: macos-latest
66+
platform: macos
67+
arch: arm64
68+
- os: windows-latest
69+
platform: windows
70+
arch: x64
71+
steps:
72+
- name: Checkout code
73+
uses: actions/checkout@v4
74+
with:
75+
ref: ${{ needs.version-bump.outputs.new_tag }}
76+
77+
- name: Setup Node.js
78+
uses: actions/setup-node@v4
79+
with:
80+
node-version: '18'
81+
82+
- name: Setup Bun
83+
uses: oven-sh/setup-bun@v2
84+
with:
85+
bun-version: latest
86+
87+
- name: Install dependencies
88+
run: |
89+
npm install
90+
cd cli
91+
npm install
92+
93+
- name: Build CLI binary
94+
run: npm run build:cli
95+
96+
- name: Rename binary (Unix)
97+
if: matrix.platform != 'windows'
98+
run: |
99+
mv dist/facet dist/facet-${{ matrix.platform }}
100+
101+
- name: Rename binary (Windows)
102+
if: matrix.platform == 'windows'
103+
run: |
104+
mv dist/facet dist/facet-${{ matrix.platform }}.exe
105+
106+
- name: Upload binary artifact
107+
uses: actions/upload-artifact@v4
108+
with:
109+
name: facet-${{ matrix.platform }}-${{ matrix.arch }}
110+
path: |
111+
dist/facet-${{ matrix.platform }}*
112+
retention-days: 1
113+
114+
create-release:
115+
name: Create GitHub Release
116+
needs: [version-bump, build-binaries]
117+
runs-on: ubuntu-latest
118+
steps:
119+
- name: Download all artifacts
120+
uses: actions/download-artifact@v4
121+
with:
122+
path: binaries
123+
124+
- name: Display structure of downloaded files
125+
run: ls -R binaries
126+
127+
- name: Create Release
128+
env:
129+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
130+
run: |
131+
gh release create ${{ needs.version-bump.outputs.new_tag }} \
132+
--repo ${{ github.repository }} \
133+
--title "Release ${{ needs.version-bump.outputs.new_tag }}" \
134+
--notes "Release ${{ needs.version-bump.outputs.new_version }}" \
135+
binaries/facet-linux-x64/facet-linux \
136+
binaries/facet-macos-arm64/facet-macos \
137+
binaries/facet-windows-x64/facet-windows.exe
138+
139+
publish-npm:
140+
name: Publish to npm
141+
needs: [version-bump, build-binaries]
142+
runs-on: ubuntu-latest
143+
steps:
144+
- name: Checkout code
145+
uses: actions/checkout@v4
146+
with:
147+
ref: ${{ needs.version-bump.outputs.new_tag }}
148+
149+
- name: Setup Node.js
150+
uses: actions/setup-node@v4
151+
with:
152+
node-version: '18'
153+
registry-url: 'https://registry.npmjs.org'
154+
155+
- name: Install dependencies
156+
run: |
157+
npm install
158+
cd cli
159+
npm install
160+
161+
- name: Build CLI
162+
run: npm run build:cli
163+
164+
- name: Publish to npm
165+
env:
166+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
167+
run: npm publish --access public

0 commit comments

Comments
 (0)