-
Notifications
You must be signed in to change notification settings - Fork 162
164 lines (161 loc) · 6.36 KB
/
main.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
name: Build
on:
push:
branches:
- master
schedule:
- cron: "0 12 * * *"
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
# - name: Tune GitHub-hosted runner network
# # https://github.com/actions/runner-images/issues/1187
# uses: smorimoto/tune-github-hosted-runner-network@v1
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: pnpm/action-setup@v4
with:
run_install: false
- uses: actions/setup-node@v4
with:
node-version-file: ".node-version"
cache: "pnpm"
- name: Get current date
id: date
run: |
echo "date=$(date +'%Y-%m-%d %H:%M:%S')" >> $GITHUB_OUTPUT
echo "year=$(date +'%Y')" >> $GITHUB_OUTPUT
echo "month=$(date +'%m')" >> $GITHUB_OUTPUT
echo "day=$(date +'%d')" >> $GITHUB_OUTPUT
echo "hour=$(date +'%H')" >> $GITHUB_OUTPUT
echo "minute=$(date +'%M')" >> $GITHUB_OUTPUT
echo "second=$(date +'%S')" >> $GITHUB_OUTPUT
- name: Restore cache.db
uses: actions/cache/restore@v4
id: cache-db-restore
with:
path: |
.cache
key: ${{ runner.os }}-v3-${{ steps.date.outputs.year }}-${{ steps.date.outputs.month }}-${{ steps.date.outputs.day }} ${{ steps.date.outputs.hour }}:${{ steps.date.outputs.minute }}:${{ steps.date.outputs.second }}
# If source files changed but packages didn't, rebuild from a prior cache.
restore-keys: |
${{ runner.os }}-v3-${{ steps.date.outputs.year }}-${{ steps.date.outputs.month }}-${{ steps.date.outputs.day }} ${{ steps.date.outputs.hour }}:${{ steps.date.outputs.minute }}:
${{ runner.os }}-v3-${{ steps.date.outputs.year }}-${{ steps.date.outputs.month }}-${{ steps.date.outputs.day }} ${{ steps.date.outputs.hour }}:
${{ runner.os }}-v3-${{ steps.date.outputs.year }}-${{ steps.date.outputs.month }}-${{ steps.date.outputs.day }}
${{ runner.os }}-v3-${{ steps.date.outputs.year }}-${{ steps.date.outputs.month }}-
${{ runner.os }}-v3-${{ steps.date.outputs.year }}-
${{ runner.os }}-v3-
- run: pnpm install
- run: pnpm run build
- name: Pre-deploy check
# If the public directory doesn't exist, the build should fail.
# If the public directory is empty, the build should fail.
run: |
if [ ! -d public ]; then
echo "public directory not found"
exit 1
fi
if [ ! "$(ls -A public)" ]; then
echo "public directory is empty"
exit 1
fi
- uses: actions/upload-artifact@v4
with:
name: build-artifact-${{ github. ref_name }}
path: public
if-no-files-found: error
retention-days: 1
compression-level: 4
include-hidden-files: false
- name: Cache cache.db
if: always()
uses: actions/cache/save@v4
with:
path: |
.cache
key: ${{ runner.os }}-v3-${{ steps.date.outputs.year }}-${{ steps.date.outputs.month }}-${{ steps.date.outputs.day }} ${{ steps.date.outputs.hour }}:${{ steps.date.outputs.minute }}:${{ steps.date.outputs.second }}
deploy_to_cloudflare_pages:
needs:
- build
name: Deploy to Cloudflare Pages
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
steps:
- name: Get NPM cache directory path
id: npm_cache_path
shell: sh
run: echo dir=$(npm config get cache) >> $GITHUB_OUTPUT
- name: Cache NPM cache
uses: actions/cache@v4
with:
path: |
${{ steps.npm_cache_path.outputs.dir }}
node_modules
key: ${{ runner.os }}-deploy-to-cloudflare-npm
- uses: actions/download-artifact@v4
with:
name: build-artifact-${{ github.ref_name }}
path: public
- name: Deploy to Cloudflare Pages
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: pages deploy public --project-name=sukkaw-ruleset --commit-dirty=true --branch=main
wranglerVersion: '3.81.0'
deploy_to_github_gitlab:
needs:
- build
name: Deploy to GitHub and GitLab
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
name: build-artifact-${{ github.ref_name }}
path: public
- name: Upload Dist to GitLab
run: |
git clone --filter=tree:0 https://${GITLAB_TOKEN_NAME}:${GITLAB_TOKEN}@gitlab.com/SukkaW/ruleset.skk.moe.git ./deploy-git
cd ./deploy-git
git config --global push.default matching
git config --global user.email "${GITLAB_EMAIL}"
git config --global user.name "${GITLAB_USER}"
rm -rf ./*
cp -rf ../public/* ./
git add --all .
git commit -m "deploy: https://github.com/SukkaW/Surge/commit/${GITHUB_SHA}"
git push --quiet --force origin HEAD:master
cd ..
rm -rf ./deploy-git
env:
GITLAB_EMAIL: ${{ secrets.GITLAB_EMAIL }}
GITLAB_USER: ${{ secrets.GITLAB_USER }}
GITLAB_TOKEN_NAME: ${{ secrets.GITLAB_TOKEN_NAME }}
GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }}
- name: Upload Dist to GitHub
continue-on-error: true
run: |
git clone --filter=tree:0 https://${GH_USER}:${GH_TOKEN}@github.com/SukkaLab/ruleset.skk.moe.git ./deploy-git
cd ./deploy-git
git config --global push.default matching
git config --global user.email "${GH_EMAIL}"
git config --global user.name "${GH_USER}"
rm -rf ./*
cp -rf ../public/* ./
echo "ruleset.skk.moe" > CNAME
git add --all .
git commit -m "deploy: https://github.com/SukkaW/Surge/commit/${GITHUB_SHA}"
git push --quiet --force origin HEAD:master
cd ..
rm -rf ./deploy-git
env:
GH_EMAIL: ${{ secrets.GIT_EMAIL }}
GH_USER: ${{ secrets.GIT_USER }}
GH_TOKEN: ${{ secrets.GIT_TOKEN }}