Skip to content

Commit c050745

Browse files
committed
fix: Make CI better
1 parent ef1c062 commit c050745

File tree

1 file changed

+75
-52
lines changed

1 file changed

+75
-52
lines changed

.github/workflows/ci.yml

Lines changed: 75 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
name: CI
22

33
on:
4-
[push, pull_request]
5-
4+
- push
5+
- pull_request
6+
- workflow_dispatch # Allow manual trigger from GitHub UI
7+
68
jobs:
79
build:
810
runs-on: ubuntu-latest
9-
11+
outputs:
12+
plugin-matrix: ${{ steps.discover-plugins.outputs.plugin-matrix }}
1013
steps:
1114
- name: Checkout repository
1215
uses: actions/checkout@v2
1316
with:
14-
submodules: recursive # Clone submodules recursively
15-
persist-credentials: true # Ensure credentials are available for pushing changes
16-
fetch-depth: 0 # Clone full history for the repository and submodules
17+
submodules: recursive
18+
persist-credentials: true
19+
fetch-depth: 0
1720

1821
- name: Set up Node.js
1922
uses: actions/setup-node@v2
@@ -23,74 +26,94 @@ jobs:
2326
- name: Install pnpm
2427
run: npm install -g pnpm
2528

26-
- name: Install and build plugins
29+
- name: Discover plugins
30+
id: discover-plugins
2731
run: |
32+
plugins=$(find plugins/* -type d -maxdepth 0)
33+
matrix=$(echo "$plugins" | jq -R -s -c 'split("\n")[:-1] | map({ plugin: . })')
34+
echo "Matrix: $matrix"
35+
echo "::set-output name=plugin-matrix::$matrix"
2836
29-
pnpm install --save-dev semantic-release @semantic-release/changelog @semantic-release/git @semantic-release/github
30-
31-
mkdir -p dist/
32-
cd plugins
33-
for d in */ ; do
34-
echo "Processing plugin: $d"
35-
cd "$d" || { echo "Failed to access $d, skipping"; continue; }
37+
process-plugin:
38+
needs: build
39+
runs-on: ubuntu-latest
40+
strategy:
41+
matrix:
42+
plugin: ${{ fromJson(needs.build.outputs.plugin-matrix) }}
43+
steps:
44+
- name: Checkout repository
45+
uses: actions/checkout@v2
46+
with:
47+
submodules: recursive
48+
fetch-depth: 0
3649

37-
pnpm install || { echo "Failed to install dependencies for $d, skipping"; cd ..; continue; }
38-
pnpm run build || { echo "Failed to build $d, skipping"; cd ..; continue; }
50+
- name: Set up Node.js
51+
uses: actions/setup-node@v2
52+
with:
53+
node-version: '20'
3954

40-
mkdir -p ../../dist/"$d"
41-
cp -r .millennium ../../dist/"$d".millennium || echo "Failed to move $d to dist"
55+
- name: Install pnpm
56+
run: npm install -g pnpm
4257

43-
cp plugin.json ../../dist/"$d"plugin.json || echo "Failed to move plugin.json to dist"
44-
cp requirements.txt ../../dist/"$d"requirements.txt || echo "Failed to move requirements.txt to dist"
58+
- name: Install dependencies and build plugin
59+
run: |
60+
cd ${{ matrix.plugin }}
61+
pnpm install
62+
pnpm run build
63+
env:
64+
NODE_ENV: production
4565

46-
cp README.md ../../dist/"$d"README.md || echo "Failed to move README.md to dist"
47-
cp README ../../dist/"$d"README || echo "Failed to move README to dist"
66+
- name: Copy files to dist
67+
run: |
68+
plugin_dir="${{ matrix.plugin }}" # Use the full plugin path
69+
plugin_dir=${plugin_dir##*/} # Extract the plugin folder name
70+
mkdir -p dist/"$plugin_dir"
4871
49-
echo "{\"commit\": \"$(git rev-parse HEAD)\", \"id\": \"$(git rev-list --max-parents=0 HEAD)\"}" > metadata.json
50-
cp metadata.json ../../dist/"$d"metadata.json || echo "Failed to move metadata.json to dist"
72+
cp -r "${{ matrix.plugin }}/plugin.json" dist/"$plugin_dir"/plugin.json
73+
cp -r "${{ matrix.plugin }}/requirements.txt" dist/"$plugin_dir"/requirements.txt
74+
cp -r "${{ matrix.plugin }}/README.md" dist/"$plugin_dir"/README.md || true
75+
cp -r "${{ matrix.plugin }}/README" dist/"$plugin_dir"/README || true
5176
77+
cd "${{ matrix.plugin }}"
5278
53-
# Get the backend folder from plugin.json and move it to dist
54-
backend=$(jq -r '.backend' plugin.json)
55-
if [ "$backend" != "null" ]; then
56-
cp -r "$backend" ../../dist/"$d""$backend" || echo "Failed to move $backend to dist"
57-
fi
79+
# Handle backend
80+
backend=$(jq -r '.backend' plugin.json)
81+
if [ "$backend" != "null" ]; then
82+
cp -r "$backend" ../../dist/"$plugin_dir"/"$backend"
83+
fi
5884
59-
# Get extra files from include list in plugin.json and move them to dist
60-
include=$(jq -r '.include' plugin.json)
61-
if [ "$include" != "null" ]; then
62-
for file in $include; do
63-
cp -r "$file" ../../dist/"$d""$file" || echo "Failed to move $file to dist"
64-
done
65-
fi
85+
# Handle include files
86+
include=$(jq -r '.include | join(" ")' plugin.json)
87+
if [ -n "$include" ]; then
88+
for file in $include; do
89+
cp -r "$file" ../../dist/"$plugin_dir"/"$file"
90+
done
91+
fi
6692
67-
cd ..
68-
done
93+
cd ../..
6994
70-
cd ..
71-
node ./scripts/release.js
95+
# Add metadata
96+
echo "{\"commit\": \"$(git rev-parse HEAD)\", \"id\": \"$(git rev-list --max-parents=0 HEAD)\"}" > dist/"$plugin_dir"/metadata.json
7297
73-
- name: Zip folders in /dist
98+
- name: Zip the plugin
7499
run: |
100+
plugin_dir="${{ matrix.plugin }}"
101+
plugin_dir=${plugin_dir##*/} # Extract the plugin folder name
75102
mkdir -p build
76103
cd dist
77-
for folder in */; do
78-
79-
out="${folder%/}"
80-
81-
# get theme name
82-
theme_id=$(jq -r '.id' "$folder"metadata.json)
83-
84-
echo "Zipping folder: $folder"
85-
zip -r "$out.zip" "$folder" || echo "Failed to zip $folder"
86-
mv "$out.zip" ../build/$theme_id.zip || echo "Failed to move $folder.zip to build"
87-
done
104+
zip -r "$plugin_dir.zip" "$plugin_dir"
105+
mv "$plugin_dir.zip" ../build/"$plugin_dir.zip"
88106
107+
finalize:
108+
needs: process-plugin
109+
runs-on: ubuntu-latest
110+
steps:
89111
- name: List built plugins
90112
run: ls -l build/
91113

92114
- name: Run Semantic Release
93115
run: |
116+
pnpm install --save-dev semantic-release @semantic-release/changelog @semantic-release/git @semantic-release/github
94117
npx semantic-release
95118
env:
96119
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)