Skip to content

Commit 49c169a

Browse files
committed
ci: publish packages
1 parent 9d79add commit 49c169a

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed

.github/workflows/release.yml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
name: Detect and Publish Packages
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
workflow_dispatch:
9+
10+
jobs:
11+
detect-changes:
12+
name: Detect modified packages
13+
runs-on: ubuntu-latest
14+
outputs:
15+
matrix: ${{ steps.set-matrix.outputs.matrix }}
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
21+
22+
- name: Detect mode
23+
id: detect-mode
24+
run: |
25+
echo "manual=${{ github.event_name == 'workflow_dispatch' }}" >> "$GITHUB_OUTPUT"
26+
27+
- name: Determine projects to publish
28+
id: set-matrix
29+
run: |
30+
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
31+
matrix='["js/react", "js/vue", "styles", "crates/core", "crates/leptos"]'
32+
else
33+
CHANGED=$(git diff --name-only origin/main HEAD)
34+
declare -a packages
35+
36+
while read -r file; do
37+
[[ "$file" == js/react/* ]] && packages+=("js/react")
38+
[[ "$file" == js/vue/* ]] && packages+=("js/vue")
39+
[[ "$file" == styles/* ]] && packages+=("styles")
40+
[[ "$file" == crates/core/* ]] && packages+=("crates/core")
41+
[[ "$file" == crates/leptos/* ]] && packages+=("crates/leptos")
42+
done <<< "$CHANGED"
43+
44+
unique=($(echo "${packages[@]}" | tr ' ' '\n' | sort -u | jq -R . | jq -s .))
45+
matrix=$(jq -c . <<< "$unique")
46+
fi
47+
48+
echo "matrix=$matrix" >> "$GITHUB_OUTPUT"
49+
50+
publish:
51+
name: Publish Changed Projects
52+
needs: detect-changes
53+
runs-on: ubuntu-latest
54+
if: needs.detect-changes.outputs.matrix != '[]'
55+
strategy:
56+
matrix:
57+
package: ${{ fromJson(needs.detect-changes.outputs.matrix) }}
58+
59+
steps:
60+
- uses: actions/checkout@v4
61+
62+
- name: Setup Node.js
63+
if: startsWith(matrix.package, 'js/') || matrix.package == 'styles'
64+
uses: actions/setup-node@v4
65+
with:
66+
node-version: 20
67+
registry-url: https://registry.npmjs.org/
68+
69+
- name: Setup pnpm
70+
if: startsWith(matrix.package, 'js/') || matrix.package == 'styles'
71+
uses: pnpm/action-setup@v3
72+
with:
73+
version: 9
74+
75+
- name: Setup Rust
76+
if: startsWith(matrix.package, 'crates/')
77+
uses: actions-rs/toolchain@v1
78+
with:
79+
toolchain: stable
80+
override: true
81+
82+
- name: Install deps (JS)
83+
if: startsWith(matrix.package, 'js/') || matrix.package == 'styles'
84+
run: pnpm install --frozen-lockfile
85+
86+
- name: Build and Publish JS
87+
if: startsWith(matrix.package, 'js/') || matrix.package == 'styles'
88+
run: |
89+
cd "${{ matrix.package }}"
90+
pnpm run build
91+
npm publish --access public
92+
env:
93+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
94+
95+
- name: Publish Rust crate
96+
if: startsWith(matrix.package, 'crates/')
97+
run: |
98+
cd "${{ matrix.package }}"
99+
cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }}

0 commit comments

Comments
 (0)