-
Notifications
You must be signed in to change notification settings - Fork 1
123 lines (96 loc) · 2.81 KB
/
deploy-all.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
name: Build
run-name: Build Code
on:
push:
branches: ['main']
permissions:
contents: write
concurrency:
group: 'build-deploy'
cancel-in-progress: true
# You should only need to touch these two variables
env:
buildCommand: |
npm ci
npm run build
buildOutput: dist # optionally "dist" if build step is needed
jobs:
build-main:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Build App
run: ${{ env.buildCommand }}
- name: Minify Code
uses: Lenni009/minify-js@main
with:
directory: ${{ env.buildOutput }}
overwrite: true
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: main
path: ${{ env.buildOutput }}
getPRs:
runs-on: ubuntu-latest
outputs:
prData: ${{ steps.data.outputs.pullRequestData }}
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Setup Deno
uses: denoland/setup-deno@v1
- name: Get PR Data
id: data
run: |
data=$(deno run --allow-net .github/workflows/getPRs.ts ${{ github.repository }} ${{ secrets.GITHUB_TOKEN }}) # output: pullRequestData: {ref: string, number: number}[]
echo "pullRequestData=$data" >> "$GITHUB_OUTPUT"
build-pr:
runs-on: ubuntu-latest
needs: getPRs
# GH Actions outputs are strings, so we can just compare this to an empty array string. `.length` does not seem to work when parsing the array.
if: needs.getPRs.outputs.prData != '[]'
strategy:
matrix:
data: ${{ fromJSON(needs.getPRs.outputs.prData) }}
steps:
- name: Checkout PR branch
uses: actions/checkout@v4
with:
ref: ${{ matrix.data.ref }}
- name: Add Base Path to Vite Config
run: echo 'VITE_BASE_PATH=/pr/${{ matrix.data.number }}/' > .env
- name: Build App
run: ${{ env.buildCommand }}
- name: Minify Code
uses: Lenni009/minify-js@main
with:
directory: ${{ env.buildOutput }}
overwrite: true
- name: Upload App
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.data.number }}
path: ${{ env.buildOutput }}
deploy:
runs-on: ubuntu-latest
if: ${{ !cancelled() && !failure() }}
needs: ['build-main', 'build-pr']
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Download App
uses: actions/download-artifact@v4
with:
path: dist/pr
- name: Move Main Deployment
run: |
cd dist
cp -r pr/main/* .
rm -rf pr/main
touch .nojekyll
- name: Deploy
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: dist