Skip to content

Commit

Permalink
deploy: 优化部署脚本
Browse files Browse the repository at this point in the history
  • Loading branch information
xugaoyi committed Jul 11, 2022
1 parent 8c1d787 commit 47eaf6b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 38 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ on:
- master

env: # 设置环境变量
TZ: Asia/Shanghai # 时区(设置时区可使页面中的`最近更新时间`使用时区时间
TZ: Asia/Shanghai # 时区(设置时区可使页面中的`最近更新时间`使用该时区时间

jobs:
build: # 自定义名称
runs-on: ubuntu-latest # 运行在虚拟机环境ubuntu-latest

strategy:
matrix:
node-version: [12.x]
node-version: [14.x]

steps:
- name: Checkout # 步骤1
Expand All @@ -26,16 +26,17 @@ jobs:
uses: actions/setup-node@v1 # 作用:安装nodejs
with:
node-version: ${{ matrix.node-version }} # 版本
- name: build-commit-push # 步骤3
- name: build-and-deploy # 步骤3
run: |
remote_addr=`git remote get-url --push origin`
commit_info=`git describe --all --always --long`
user_name=`git log -1 --pretty=format:'%an'`
user_email=`git log -1 --pretty=format:'%ae'`
npm install
npm run build
deploy_branch=gh-pages
yarn
yarn build
cd docs/.vuepress/dist
git config --global init.defaultBranch hp-pages
git config --global init.defaultBranch $deploy_branch
git init
git config user.name ${user_name}
git config user.email ${user_email}
Expand All @@ -44,7 +45,6 @@ jobs:
remote_addr=`echo $remote_addr | awk -F'://' '{print $2}'`
remote_addr=https://${user_name}:${{secrets.GITHUB_TOKEN}}@${remote_addr}
git remote add origin ${remote_addr}
git push origin HEAD:gh-pages --force # 推送到github gh-pages分支
git push origin HEAD:$deploy_branch --force # 推送到github $deploy_branch分支
# 如只提交到github pages可以使用github-pages-deploy-action,详见: https://github.com/JamesIves/github-pages-deploy-action

# 只提交到github pages也可以使用github-pages-deploy-action,详见: https://github.com/JamesIves/github-pages-deploy-action
39 changes: 10 additions & 29 deletions deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,22 @@
# 确保脚本抛出遇到的错误
set -e


push_addr=`git remote get-url --push origin` # git提交地址,也可以手动设置,比如:[email protected]:xugaoyi/vuepress-theme-vdoing.git
commit_info=`git describe --all --always --long`
dist_path=docs/.vuepress/dist # 打包生成的文件夹路径
push_branch=gh-pages # 推送的分支

# 生成静态文件
npm run build

# 进入生成的文件夹
cd docs/.vuepress/dist

# deploy to github pages
echo 'b.xugaoyi.com' > CNAME
cd $dist_path

if [ -z "$GITHUB_TOKEN" ]; then
msg='deploy'
[email protected]:xugaoyi/vuepress-theme-vdoing.git
else
msg='来自github actions的自动部署'
githubUrl=https://xugaoyi:${GITHUB_TOKEN}@github.com/xugaoyi/vuepress-theme-vdoing.git
git config --global user.name "xugaoyi"
git config --global user.email "[email protected]"
fi
git init
git add -A
git commit -m "${msg}"
git push -f $githubUrl master:gh-pages # 推送到github gh-pages分支

# deploy to coding pages
# echo 'www.xugaoyi.com\nxugaoyi.com' > CNAME # 自定义域名
# echo 'google.com, pub-7828333725993554, DIRECT, f08c47fec0942fa0' > ads.txt # 谷歌广告相关文件

# if [ -z "$CODING_TOKEN" ]; then # -z 字符串 长度为0则为true;$CODING_TOKEN来自于github仓库`Settings/Secrets`设置的私密环境变量
# [email protected]:xgy/xgy.git
# else
# codingUrl=https://HmuzsGrGQX:${CODING_TOKEN}@e.coding.net/xgy/xgy.git
# fi
# git add -A
# git commit -m "${msg}"
# git push -f $codingUrl master # 推送到coding
git commit -m "deploy, $commit_info"
git push -f $push_addr HEAD:$push_branch

cd -
rm -rf docs/.vuepress/dist
rm -rf $dist_path
1 change: 1 addition & 0 deletions docs/.vuepress/public/CNAME
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
b.xugaoyi.com

0 comments on commit 47eaf6b

Please sign in to comment.