-
Notifications
You must be signed in to change notification settings - Fork 0
107 lines (96 loc) · 3.06 KB
/
deploy-public.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
name: Deploy public
on:
push:
branches: ["main"]
workflow_dispatch:
inputs:
hugoVersion:
description: 'Hugo version to use'
required: false
default: '0.128.0'
type: string
baseUrl:
description: 'Site base URL'
required: false
type: string
environment:
description: 'Hugo environment'
required: false
default: 'production'
type: string
permissions:
contents: write
actions: read
jobs:
build:
runs-on: ubuntu-latest
env:
HUGO_VERSION: ${{ inputs.hugoVersion || '0.128.0' }}
steps:
- name: Install Hugo CLI
run: |
wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \
&& sudo dpkg -i ${{ runner.temp }}/hugo.deb
- name: Install Dart Sass
run: sudo snap install dart-sass
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Node.js dependencies
run: "[[ -f package-lock.json || -f npm-shrinkwrap.json ]] && npm ci || true"
- name: Build with Hugo
env:
HUGO_CACHEDIR: ${{ runner.temp }}/hugo_cache
HUGO_ENVIRONMENT: ${{ inputs.environment || 'production' }}
run: |
hugo --minify --gc --cleanDestinationDir
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: hugo-public
path: ./public
retention-days: 1
push_public:
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: hugo-public
path: ./public
- name: Setup Git and sync public branch
run: |
git config user.name "github-actions"
git config user.email "actions@github.com"
# 获取当前提交信息
COMMIT_MSG=$(git log -1 --pretty=%B)
COMMIT_HASH=$(git rev-parse --short HEAD)
# 如果 public 分支不存在则创建
if ! git show-ref --verify --quiet refs/remotes/origin/public; then
git checkout --orphan public
git rm -rf .
cp -r public/* .
git add .
git commit -m "Initial public branch from main ${COMMIT_HASH}"
git push origin public
else
# 更新现有 public 分支
git fetch origin public
git checkout public
git reset --soft origin/public
rm -rf ./*
cp -r public/* .
git add .
if git diff --staged --quiet; then
echo "No changes detected"
exit 0
fi
git commit -m "Update from main ${COMMIT_HASH}" -m "Source commit message:" -m "${COMMIT_MSG}"
git push origin public
fi