-
Notifications
You must be signed in to change notification settings - Fork 1
107 lines (89 loc) · 3.48 KB
/
Copy pathgithubPagesDeploy.yml
File metadata and controls
107 lines (89 loc) · 3.48 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
name: BuildGitHubPages
# 在master分支发生push事件时触发。
on:
push:
branches:
- master
env: # 设置环境变量
TZ: Asia/Shanghai # 时区(设置时区可使页面中的`最近更新时间`使用该时区时间)
jobs:
BuildGitHubPages:
runs-on: ubuntu-latest
# 指定不同版本的node进行构建
strategy:
matrix:
node-version: [18.x]
steps:
- name: Checkout
uses: actions/checkout@v1 # 使用的动作。格式:userName/repoName。作用:检出仓库,获取源码。 官方actions库:https://github.com/actions
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3 # 作用:安装nodejs
with:
node-version: ${{ matrix.node-version }} # 版本
- name: vuepress-deploy # 部署vuepress
run: |
#!/bin/bash
set -e
echo ''
# env
echo "node version: $(node -v)"
echo "npm version: $(npm -v)"
# Build vuepress project
echo "==> Start building \n $BUILD_SCRIPT"
eval "$BUILD_SCRIPT"
echo "Build success"
# Change directory to the dest
echo "==> Changing directory to '$BUILD_DIR' ..."
cd $BUILD_DIR
# workaround for 'fatal: unsafe repository' error
git config --global --add safe.directory "*"
# Get respository
if [[ -z "$TARGET_REPO" ]]; then
REPOSITORY_NAME="${GITHUB_REPOSITORY}"
else
REPOSITORY_NAME="$TARGET_REPO"
fi
# Get branch
if [[ -z "$TARGET_BRANCH" ]]; then
DEPLOY_BRAN="gh-pages"
else
DEPLOY_BRAN="$TARGET_BRANCH"
fi
# Final repository
DEPLOY_REPO="https://username:${ACCESS_TOKEN}@github.com/${REPOSITORY_NAME}.git"
if [ "$TARGET_LINK" ]; then
DEPLOY_REPO="$TARGET_LINK"
fi
echo "==> Prepare to deploy"
git init
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
if [ -z "$(git status --porcelain)" ]; then
echo "The BUILD_DIR is setting error or nothing produced" && \
echo "Exiting..."
exit 0
fi
# Generate a CNAME file
if [ "$CNAME" ]; then
echo "Generating a CNAME file..."
echo $CNAME > CNAME
fi
echo "==> Starting deploying"
# Final repository
if [[ -z "$COMMIT_MESSAGE" ]]; then
COMMIT_MESSAGE="Auto deploy from Github Actions"
fi
git add .
git commit -m "$COMMIT_MESSAGE"
git push --force $DEPLOY_REPO master:$DEPLOY_BRAN
rm -fr .git
cd $GITHUB_WORKSPACE
echo "Successfully deployed!" && \
echo "See: https://github.com/$REPOSITORY_NAME/tree/$DEPLOY_BRAN"
env:
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
TARGET_REPO: xiaoliutalk/xiaoliutalk.github.io
TARGET_BRANCH: gh_pages
BUILD_SCRIPT: yarn && yarn build
BUILD_DIR: docs/.vuepress/dist/
CNAME: www.xiaoliutalk.cn