1- # ─────────────────────────────────────────────────────────────
2- # Moonfin Plugin — CI Build Workflow
3- # ─────────────────────────────────────────────────────────────
4- #
5- # Triggers:
6- # • Push to master → build + package ZIP artifact
7- # • PR to master → build + upload result artifact
8- #
9- # Security:
10- # Uses pull_request (not pull_request_target) so untrusted fork
11- # code never runs with write access. PR comments are posted by
12- # a separate workflow (comment.yml) triggered via workflow_run.
13- #
14- # Build flow:
15- # 1. Frontend install (npm ci)
16- # 2. Frontend build (node build.js) — skipped if (1) fails
17- # 3. Sync web files (cp to backend/Web/) — skipped if (2) fails
18- # 4. Backend build (dotnet build) — skipped if (2) fails
19- # 5. Gate step — fails the job if any of (1)-(4) didn't succeed
20- #
21- # Error handling:
22- # Build steps (1), (2), (4) use continue-on-error so the job keeps
23- # running even on failure. Their output is captured to log files via
24- # tee. The gate step (5) re-fails the job so the overall status is
25- # correct. On PRs, build results (outcomes + logs) are uploaded as
26- # an artifact for the comment.yml workflow to pick up.
27- #
28- # Packaging (master only, after successful build):
29- # Reads version + ABI from the .csproj, creates a release ZIP with
30- # the DLL + meta.json, and uploads it as a workflow artifact.
31- # ─────────────────────────────────────────────────────────────
32-
331name : Build
342
353on :
@@ -50,73 +18,22 @@ jobs:
5018 - name : Checkout
5119 uses : actions/checkout@v4
5220
53- - name : Setup Node.js
54- uses : actions/setup-node@v4
55- with :
56- node-version : 20
57-
5821 - name : Setup .NET
5922 uses : actions/setup-dotnet@v4
6023 with :
6124 dotnet-version : 8.0.x
6225
63- # ── Frontend ──────────────────────────────────────────────
64- # continue-on-error: lets the job continue so we can upload
65- # build results even when a step fails.
66- # set -o pipefail: ensures the pipe returns the command's exit
67- # code, not tee's (which always succeeds).
68- # 2>&1 | tee: captures stdout+stderr to a log file for the
69- # PR comment, while still printing to the Actions console.
70- - name : Install frontend dependencies
71- id : frontend_install
72- continue-on-error : true
73- working-directory : frontend
74- run : |
75- set -o pipefail
76- npm ci 2>&1 | tee "${{ runner.temp }}/frontend-install.log"
77-
78- - name : Build frontend
79- if : steps.frontend_install.outcome == 'success'
80- id : frontend_build
81- continue-on-error : true
82- working-directory : frontend
83- run : |
84- set -o pipefail
85- node build.js 2>&1 | tee "${{ runner.temp }}/frontend-build.log"
86-
87- # ── Sync web files into backend ───────────────────────────
88- - name : Sync web files
89- if : steps.frontend_build.outcome == 'success'
90- run : |
91- mkdir -p backend/Web
92- cp frontend/dist/plugin.js backend/Web/plugin.js
93- cp frontend/dist/plugin.css backend/Web/plugin.css
94-
95- # ── Backend ───────────────────────────────────────────────
9626 - name : Build backend
97- if : steps.frontend_build.outcome == 'success'
9827 id : backend_build
9928 continue-on-error : true
10029 run : |
10130 set -o pipefail
10231 dotnet build backend/Moonfin.Server.csproj -c Release 2>&1 | tee "${{ runner.temp }}/backend-build.log"
10332
104- # ── Gate ───────────────────────────────────────────────────
105- # continue-on-error masks failures from the job status. This
106- # gate step re-fails the job when any build step didn't
107- # succeed (covers both 'failure' and 'skipped' outcomes).
10833 - name : Fail if build failed
109- id : build_gate
110- if : |
111- steps.frontend_install.outcome != 'success' ||
112- steps.frontend_build.outcome != 'success' ||
113- steps.backend_build.outcome != 'success'
34+ if : steps.backend_build.outcome != 'success'
11435 run : exit 1
11536
116- # ── Upload build results for PR comment workflow ──────────
117- # Always runs on PRs so the comment.yml workflow can post
118- # results even on failure. Writes step outcomes + PR number
119- # to a metadata file alongside the log files.
12037 - name : Save build results
12138 if : always() && github.event_name == 'pull_request'
12239 run : |
@@ -126,16 +43,13 @@ jobs:
12643 {
12744 "pr_number": ${{ github.event.pull_request.number }},
12845 "sha": "${{ github.event.pull_request.head.sha }}",
129- "frontend_install": "${{ steps.frontend_install.outcome }}",
130- "frontend_build": "${{ steps.frontend_build.outcome }}",
13146 "backend_build": "${{ steps.backend_build.outcome }}"
13247 }
13348 EOF
13449
135- # Copy any log files that exist
136- for f in frontend-install.log frontend-build.log backend-build.log; do
137- [ -f "${{ runner.temp }}/$f" ] && cp "${{ runner.temp }}/$f" "${{ runner.temp }}/build-results/"
138- done
50+ if [ -f "${{ runner.temp }}/backend-build.log" ]; then
51+ cp "${{ runner.temp }}/backend-build.log" "${{ runner.temp }}/build-results/"
52+ fi
13953
14054 - name : Upload build results
14155 if : always() && github.event_name == 'pull_request'
14458 name : build-results
14559 path : ${{ runner.temp }}/build-results/
14660
147- # ── Package (master only) ─────────────────────────────────
14861 - name : Read version from csproj
14962 if : github.event_name == 'push' && steps.backend_build.outcome == 'success'
15063 id : version
@@ -171,6 +84,13 @@ jobs:
17184 mkdir -p release
17285 cp backend/bin/Release/net8.0/Moonfin.Server.dll release/
17386
87+ if [ -f frontend/index.html ]; then
88+ mkdir -p release/frontend
89+ cp -R frontend/. release/frontend/
90+ rm -rf release/frontend/node_modules
91+ rm -f release/frontend/package.json release/frontend/package-lock.json
92+ fi
93+
17494 cat > release/meta.json <<EOF
17595 {
17696 "category": "General",
@@ -208,7 +128,7 @@ jobs:
208128 - name : Build summary (master)
209129 if : github.event_name == 'push' && steps.backend_build.outcome == 'success'
210130 run : |
211- echo "## ✅ Build Successful" >> $GITHUB_STEP_SUMMARY
131+ echo "## Build Successful" >> $GITHUB_STEP_SUMMARY
212132 echo "" >> $GITHUB_STEP_SUMMARY
213133 echo "| Property | Value |" >> $GITHUB_STEP_SUMMARY
214134 echo "|---|---|" >> $GITHUB_STEP_SUMMARY
0 commit comments