Repository navigation
114 lines (91 loc) · 2.92 KB
/
Copy pathsync.yml
File metadata and controls
114 lines (91 loc) · 2.92 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
name: CI(sync-mw)
on:
push:
branches:
- sync-mw
pull_request:
branches:
- sync-mw
permissions:
contents: write
env:
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 10
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: pnpm
# 依赖里有多处 github: 简写,npm/pnpm 会解析成 git+ssh://git@github.com/...,
# 而 runner 没有 SSH key,导致 clone 失败(Permission denied (publickey))。
# 这里让 git 把 SSH 形式重写为 HTTPS(这些仓库都是公开库)。
# 只改变传输方式,锁文件里固定的 commit 不受影响。
- name: Use HTTPS for GitHub git dependencies
run: 'git config --global url."https://github.com/".insteadOf "git@github.com:"'
- name: Install dependencies
run: pnpm install
- name: Build (production)
run: pnpm run build
env:
NODE_ENV: production
- name: Upload dist
uses: actions/upload-artifact@v4
with:
name: dist
path: |
static/microbit
src/generated
build
deploy:
runs-on: ubuntu-latest
needs: build
if: >
github.event_name == 'push' &&
github.ref == 'refs/heads/sync-mw'
steps:
- name: Checkout repo (with push access)
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: true
- name: Download dist
uses: actions/download-artifact@v4
with:
name: dist
path: .
- name: Deploy to sync-mw-web branch
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
# Backup build folder
rm -rf /tmp/web-build
mkdir -p /tmp/web-build
cp -r build/* /tmp/web-build/
# Fetch sync-mw-web branch if exists
git fetch origin sync-mw-web 2>/dev/null || true
# Create orphan sync-mw-web branch if not exists, otherwise checkout
if git show-ref --verify --quiet refs/remotes/origin/sync-mw-web; then
git checkout sync-mw-web
else
git checkout --orphan sync-mw-web
fi
# Clean sync-mw-web branch (keep .git directory)
find . -mindepth 1 -maxdepth 1 -not -name '.git' -exec rm -rf {} +
# Copy build contents directly to root
cp -r /tmp/web-build/* .
# Add all files
git add -A
# Commit if changed
git commit -m "chore: deploy web build from sync-mw" || echo "No changes"
# Push to sync-mw-web branch
git push origin sync-mw-web --force