-
Notifications
You must be signed in to change notification settings - Fork 2
131 lines (116 loc) · 3.72 KB
/
Copy pathdeploy.yml
File metadata and controls
131 lines (116 loc) · 3.72 KB
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
124
125
126
127
128
129
130
131
name: Deploy to GitHub Pages
on:
push:
branches:
- main
pull_request:
branches:
- main
types:
- opened
- synchronize
- reopened
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
pull-requests: write
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build main (production)
env:
VITE_COMMIT_HASH: ${{ github.sha }}
run: |
git checkout main
npm run build:single
- name: Copy data files to dist root
run: |
cp src/data/rptrs.json dist/rptrs.json
cp src/data/tafl_min.json dist/tafl_min.json
cp src/data/airports_min.json dist/airports_min.json
cp src/data/radioid-users.csv dist/radioid-users.csv
- name: Stage main build to dist_root
run: |
rm -rf dist_root dist_test
mkdir -p dist_root
mv dist/* dist_root/
- name: List open PRs and build previews
env:
GH_TOKEN: ${{ github.token }}
run: |
sanitize() {
echo "$1" | sed 's/\//-/g' | sed 's/[^a-zA-Z0-9_-]//g' | cut -c1-50
}
prs=$(gh pr list --base main --state open --json number,headRefName -q '.[] | "\(.number)|\(.headRefName)"')
for entry in $prs; do
num="${entry%%|*}"
branch="${entry#*|}"
[ -z "$num" ] && continue
name=$(sanitize "$branch")
[ -z "$name" ] && name="pr-$num"
echo "Building PR #$num branch=$branch -> test/$name"
git fetch origin "pull/$num/head:pr-$num" 2>/dev/null || git fetch origin "$branch" 2>/dev/null || true
git checkout "pr-$num" 2>/dev/null || git checkout "$branch"
npm run build:single
cp src/data/rptrs.json dist/rptrs.json
cp src/data/tafl_min.json dist/tafl_min.json
cp src/data/airports_min.json dist/airports_min.json
cp src/data/radioid-users.csv dist/radioid-users.csv
mkdir -p "dist_test/$name"
mv dist/* "dist_test/$name/"
done
- name: Combine artifact
run: |
mkdir -p dist
cp -r dist_root/. dist/
if [ -d dist_test ]; then
for d in dist_test/*/; do
[ -d "$d" ] || continue
name=$(basename "$d")
mkdir -p "dist/test/$name"
cp -r "$d"* "dist/test/$name/"
done
fi
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: './dist'
- name: Comment PR with preview link
if: github.event_name == 'pull_request'
run: |
branch="${{ github.head_ref }}"
name=$(echo "$branch" | sed 's/\//-/g' | sed 's/[^a-zA-Z0-9_-]//g' | cut -c1-50)
[ -z "$name" ] && name="pr-${{ github.event.pull_request.number }}"
url="https://neonplug.app/test/${name}/"
gh pr comment "${{ github.event.pull_request.number }}" --body "Preview: $url"
env:
GH_TOKEN: ${{ github.token }}
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4