Skip to content

Commit 60f16bd

Browse files
authored
fix: cleanup build pipeline (#1326)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added an enhanced, automated process to build and deploy the plugin across both staging and production environments. - Releases are now published immediately instead of being created as drafts, ensuring quicker access to updates. - **Chores** - Streamlined and consolidated deployment workflows for improved consistency and reliability throughout the release process. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent cacb1c1 commit 60f16bd

File tree

4 files changed

+225
-186
lines changed

4 files changed

+225
-186
lines changed

.github/workflows/build-plugin.yml

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
name: Build Plugin Component
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
RELEASE_CREATED:
7+
type: boolean
8+
required: true
9+
description: "Whether a release was created"
10+
RELEASE_TAG:
11+
type: string
12+
required: false
13+
description: "Name of the tag when a release is created"
14+
TAG:
15+
type: string
16+
required: false
17+
description: "Tag for the build (e.g. PR number or version)"
18+
BUCKET_PATH:
19+
type: string
20+
required: true
21+
description: "Path in the bucket where artifacts should be stored"
22+
BASE_URL:
23+
type: string
24+
required: true
25+
description: "Base URL for the plugin builds"
26+
secrets:
27+
CF_ACCESS_KEY_ID:
28+
required: true
29+
CF_SECRET_ACCESS_KEY:
30+
required: true
31+
CF_BUCKET_PREVIEW:
32+
required: true
33+
CF_ENDPOINT:
34+
required: true
35+
GITHUB_TOKEN:
36+
required: true
37+
jobs:
38+
build-plugin:
39+
name: Build and Deploy Plugin
40+
defaults:
41+
run:
42+
working-directory: plugin
43+
runs-on: ubuntu-latest
44+
steps:
45+
- name: Checkout repo
46+
uses: actions/checkout@v4
47+
with:
48+
fetch-depth: 0
49+
50+
- name: Install Node
51+
uses: actions/setup-node@v4
52+
with:
53+
node-version-file: ".nvmrc"
54+
55+
- uses: pnpm/action-setup@v4
56+
name: Install pnpm
57+
with:
58+
run_install: false
59+
60+
- name: Get pnpm store directory
61+
id: pnpm-cache
62+
shell: bash
63+
run: |
64+
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
65+
66+
- name: Get API Version
67+
id: vars
68+
run: |
69+
GIT_SHA=$(git rev-parse --short HEAD)
70+
IS_TAGGED=$(git describe --tags --abbrev=0 --exact-match || echo '')
71+
PACKAGE_LOCK_VERSION=$(jq -r '.version' package.json)
72+
API_VERSION=$([[ -n "$IS_TAGGED" ]] && echo "$PACKAGE_LOCK_VERSION" || echo "${PACKAGE_LOCK_VERSION}+${GIT_SHA}")
73+
echo "API_VERSION=${API_VERSION}" >> $GITHUB_OUTPUT
74+
75+
- uses: actions/cache@v4
76+
name: Setup pnpm cache
77+
with:
78+
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
79+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
80+
restore-keys: |
81+
${{ runner.os }}-pnpm-store-
82+
83+
- name: Install dependencies
84+
run: |
85+
cd ${{ github.workspace }}
86+
pnpm install --frozen-lockfile --filter @unraid/connect-plugin
87+
88+
- name: Download Unraid UI Components
89+
uses: actions/download-artifact@v4
90+
with:
91+
name: unraid-wc-ui
92+
path: ${{ github.workspace }}/plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/unraid-components/uui
93+
merge-multiple: true
94+
- name: Download Unraid Web Components
95+
uses: actions/download-artifact@v4
96+
with:
97+
pattern: unraid-wc-rich
98+
path: ${{ github.workspace }}/plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/unraid-components/nuxt
99+
merge-multiple: true
100+
- name: Download Unraid API
101+
uses: actions/download-artifact@v4
102+
with:
103+
name: unraid-api
104+
path: ${{ github.workspace }}/plugin/api/
105+
- name: Download PNPM Store
106+
uses: actions/download-artifact@v4
107+
with:
108+
name: packed-pnpm-store
109+
path: ${{ github.workspace }}/plugin/
110+
- name: Extract Unraid API
111+
run: |
112+
mkdir -p ${{ github.workspace }}/plugin/source/dynamix.unraid.net/usr/local/unraid-api
113+
tar -xzf ${{ github.workspace }}/plugin/api/unraid-api.tgz -C ${{ github.workspace }}/plugin/source/dynamix.unraid.net/usr/local/unraid-api
114+
- name: Build Plugin and TXZ Based on Event and Tag
115+
id: build-plugin
116+
run: |
117+
cd ${{ github.workspace }}/plugin
118+
ls -al
119+
pnpm run build:txz
120+
pnpm run build:plugin --tag="${{ inputs.TAG }}" --base-url="${{ inputs.BASE_URL }}"
121+
122+
- name: Ensure Plugin Files Exist
123+
run: |
124+
ls -al ./deploy
125+
if [ ! -f ./deploy/*.plg ]; then
126+
echo "Error: .plg file not found in plugin/deploy/"
127+
exit 1
128+
fi
129+
130+
if [ ! -f ./deploy/*.txz ]; then
131+
echo "Error: .txz file not found in plugin/deploy/"
132+
exit 1
133+
fi
134+
135+
- name: Upload to GHA
136+
uses: actions/upload-artifact@v4
137+
with:
138+
name: unraid-plugin
139+
path: plugin/deploy/
140+
141+
- name: Upload Release Assets
142+
if: inputs.RELEASE_CREATED == 'true'
143+
env:
144+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
145+
run: |
146+
# For each file in release directory
147+
for file in deploy/*; do
148+
echo "Uploading $file to release..."
149+
gh release upload "${inputs.RELEASE_TAG}" "$file" --clobber
150+
done
151+
152+
- name: Workflow Dispatch and wait
153+
if: inputs.RELEASE_CREATED == 'true'
154+
uses: the-actions-org/workflow-dispatch@v4.0.0
155+
with:
156+
workflow: release-production.yml
157+
inputs: '{ "version": "${{ steps.vars.outputs.API_VERSION }}" }'
158+
token: ${{ secrets.WORKFLOW_TRIGGER_PAT }}
159+
160+
- name: Upload to Cloudflare
161+
if: inputs.RELEASE_CREATED == 'false'
162+
env:
163+
AWS_ACCESS_KEY_ID: ${{ secrets.CF_ACCESS_KEY_ID }}
164+
AWS_SECRET_ACCESS_KEY: ${{ secrets.CF_SECRET_ACCESS_KEY }}
165+
AWS_DEFAULT_REGION: auto
166+
run: |
167+
# Sync the deploy directory to the Cloudflare bucket with explicit content encoding and public-read ACL
168+
aws s3 sync deploy/ s3://${{ secrets.CF_BUCKET_PREVIEW }}/${{ inputs.BUCKET_PATH }} \
169+
--endpoint-url ${{ secrets.CF_ENDPOINT }} \
170+
--checksum-algorithm CRC32 \
171+
--no-guess-mime-type \
172+
--content-encoding none \
173+
--acl public-read
174+
175+
- name: Comment URL
176+
if: github.event_name == 'pull_request'
177+
uses: thollander/actions-comment-pull-request@v3
178+
with:
179+
comment-tag: prlink
180+
mode: recreate
181+
message: |
182+
This plugin has been deployed to Cloudflare R2 and is available for testing.
183+
Download it at this URL:
184+
```
185+
${{ inputs.BASE_URL }}/tag/${{ inputs.TAG }}/dynamix.unraid.net.plg
186+
```

0 commit comments

Comments
 (0)