Skip to content

Commit 51e66dd

Browse files
authored
Merge pull request #1 from DLhugly/monorepo-restructure
Monorepo restructure
2 parents 81db503 + c2c4015 commit 51e66dd

96 files changed

Lines changed: 6494 additions & 490 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 257 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,257 @@
1+
name: ClifCode Release & Publish
2+
3+
on:
4+
push:
5+
tags:
6+
- "clifcode-v*"
7+
workflow_dispatch:
8+
inputs:
9+
version:
10+
description: "Version to publish (e.g. 0.1.0)"
11+
required: true
12+
13+
permissions:
14+
contents: write
15+
16+
env:
17+
CARGO_TERM_COLOR: always
18+
19+
jobs:
20+
# --------------------------------------------------
21+
# Build native binaries on each platform
22+
# --------------------------------------------------
23+
build:
24+
strategy:
25+
fail-fast: false
26+
matrix:
27+
include:
28+
- target: aarch64-apple-darwin
29+
os: macos-14
30+
name: cli-darwin-arm64
31+
- target: x86_64-apple-darwin
32+
os: macos-14
33+
name: cli-darwin-x64
34+
- target: aarch64-unknown-linux-gnu
35+
os: ubuntu-latest
36+
name: cli-linux-arm64
37+
cross: true
38+
- target: x86_64-unknown-linux-gnu
39+
os: ubuntu-latest
40+
name: cli-linux-x64
41+
- target: aarch64-pc-windows-msvc
42+
os: windows-latest
43+
name: cli-win32-arm64
44+
- target: x86_64-pc-windows-msvc
45+
os: windows-latest
46+
name: cli-win32-x64
47+
48+
runs-on: ${{ matrix.os }}
49+
timeout-minutes: 30
50+
51+
steps:
52+
- uses: actions/checkout@v4
53+
54+
- name: Determine version
55+
id: version
56+
shell: bash
57+
run: |
58+
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
59+
echo "version=${{ github.event.inputs.version }}" >> "$GITHUB_OUTPUT"
60+
else
61+
TAG="${GITHUB_REF#refs/tags/clifcode-v}"
62+
echo "version=$TAG" >> "$GITHUB_OUTPUT"
63+
fi
64+
65+
- name: Bump version
66+
shell: bash
67+
working-directory: clif-code-tui
68+
run: |
69+
VERSION="${{ steps.version.outputs.version }}"
70+
sed -i.bak "s/^version = \".*\"/version = \"$VERSION\"/" Cargo.toml
71+
rm -f Cargo.toml.bak
72+
73+
- name: Setup Rust
74+
uses: dtolnay/rust-toolchain@stable
75+
with:
76+
targets: ${{ matrix.target }}
77+
78+
- name: Rust Cache
79+
uses: swatinem/rust-cache@v2
80+
with:
81+
workspaces: clif-code-tui -> target
82+
cache-on-failure: true
83+
84+
- name: Install cross (Linux ARM64)
85+
if: matrix.cross
86+
run: cargo install cross --git https://github.com/cross-rs/cross
87+
88+
- name: Build
89+
working-directory: clif-code-tui
90+
shell: bash
91+
run: |
92+
if [[ "${{ matrix.cross }}" == "true" ]]; then
93+
cross build --release --target ${{ matrix.target }}
94+
else
95+
cargo build --release --target ${{ matrix.target }}
96+
fi
97+
98+
- name: Strip binary (Unix)
99+
if: runner.os != 'Windows'
100+
shell: bash
101+
run: |
102+
strip clif-code-tui/target/${{ matrix.target }}/release/clifcode || true
103+
104+
- name: Prepare artifact (Unix)
105+
if: runner.os != 'Windows'
106+
shell: bash
107+
run: |
108+
mkdir -p dist
109+
cp clif-code-tui/target/${{ matrix.target }}/release/clifcode dist/clifcode-${{ matrix.target }}
110+
111+
- name: Prepare artifact (Windows)
112+
if: runner.os == 'Windows'
113+
shell: bash
114+
run: |
115+
mkdir -p dist
116+
cp clif-code-tui/target/${{ matrix.target }}/release/clifcode.exe dist/clifcode-${{ matrix.target }}.exe
117+
118+
- name: Upload artifact
119+
uses: actions/upload-artifact@v4
120+
with:
121+
name: ${{ matrix.name }}
122+
path: dist/
123+
124+
- name: Upload to GitHub Release
125+
if: startsWith(github.ref, 'refs/tags/')
126+
uses: softprops/action-gh-release@v2
127+
with:
128+
files: dist/*
129+
env:
130+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
131+
132+
# --------------------------------------------------
133+
# Publish platform-specific npm packages
134+
# --------------------------------------------------
135+
publish-platform:
136+
needs: build
137+
strategy:
138+
fail-fast: false
139+
matrix:
140+
include:
141+
- artifact: cli-darwin-arm64
142+
package: cli-darwin-arm64
143+
binary: clifcode-aarch64-apple-darwin
144+
- artifact: cli-darwin-x64
145+
package: cli-darwin-x64
146+
binary: clifcode-x86_64-apple-darwin
147+
- artifact: cli-linux-arm64
148+
package: cli-linux-arm64
149+
binary: clifcode-aarch64-unknown-linux-gnu
150+
- artifact: cli-linux-x64
151+
package: cli-linux-x64
152+
binary: clifcode-x86_64-unknown-linux-gnu
153+
- artifact: cli-win32-arm64
154+
package: cli-win32-arm64
155+
binary: clifcode-aarch64-pc-windows-msvc.exe
156+
- artifact: cli-win32-x64
157+
package: cli-win32-x64
158+
binary: clifcode-x86_64-pc-windows-msvc.exe
159+
160+
runs-on: ubuntu-latest
161+
steps:
162+
- uses: actions/checkout@v4
163+
164+
- uses: actions/setup-node@v4
165+
with:
166+
node-version: 22
167+
registry-url: https://registry.npmjs.org
168+
169+
- name: Determine version
170+
id: version
171+
run: |
172+
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
173+
echo "version=${{ github.event.inputs.version }}" >> "$GITHUB_OUTPUT"
174+
else
175+
TAG="${GITHUB_REF#refs/tags/clifcode-v}"
176+
echo "version=$TAG" >> "$GITHUB_OUTPUT"
177+
fi
178+
179+
- name: Download artifact
180+
uses: actions/download-artifact@v4
181+
with:
182+
name: ${{ matrix.artifact }}
183+
path: artifact/
184+
185+
- name: Prepare package
186+
run: |
187+
VERSION="${{ steps.version.outputs.version }}"
188+
PKG_DIR="clif-code-tui/npm/@clifcode/${{ matrix.package }}"
189+
190+
# Patch version
191+
cd "$PKG_DIR"
192+
node -e "
193+
const pkg = require('./package.json');
194+
pkg.version = '$VERSION';
195+
require('fs').writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
196+
"
197+
198+
# Copy binary
199+
mkdir -p bin
200+
IS_WIN=$([[ "${{ matrix.binary }}" == *.exe ]] && echo true || echo false)
201+
if [[ "$IS_WIN" == "true" ]]; then
202+
cp "$GITHUB_WORKSPACE/artifact/${{ matrix.binary }}" bin/clifcode.exe
203+
else
204+
cp "$GITHUB_WORKSPACE/artifact/${{ matrix.binary }}" bin/clifcode
205+
chmod +x bin/clifcode
206+
fi
207+
208+
- name: Publish
209+
working-directory: clif-code-tui/npm/@clifcode/${{ matrix.package }}
210+
run: npm publish --access public
211+
env:
212+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
213+
214+
# --------------------------------------------------
215+
# Publish main wrapper package
216+
# --------------------------------------------------
217+
publish-main:
218+
needs: publish-platform
219+
runs-on: ubuntu-latest
220+
steps:
221+
- uses: actions/checkout@v4
222+
223+
- uses: actions/setup-node@v4
224+
with:
225+
node-version: 22
226+
registry-url: https://registry.npmjs.org
227+
228+
- name: Determine version
229+
id: version
230+
run: |
231+
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
232+
echo "version=${{ github.event.inputs.version }}" >> "$GITHUB_OUTPUT"
233+
else
234+
TAG="${GITHUB_REF#refs/tags/clifcode-v}"
235+
echo "version=$TAG" >> "$GITHUB_OUTPUT"
236+
fi
237+
238+
- name: Patch version
239+
working-directory: clif-code-tui/npm/clifcode
240+
run: |
241+
VERSION="${{ steps.version.outputs.version }}"
242+
node -e "
243+
const pkg = require('./package.json');
244+
pkg.version = '$VERSION';
245+
if (pkg.optionalDependencies) {
246+
for (const dep of Object.keys(pkg.optionalDependencies)) {
247+
pkg.optionalDependencies[dep] = '$VERSION';
248+
}
249+
}
250+
require('fs').writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
251+
"
252+
253+
- name: Publish
254+
working-directory: clif-code-tui/npm/clifcode
255+
run: npm publish --access public
256+
env:
257+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

0 commit comments

Comments
 (0)