deploy: 优化部署脚本
This commit is contained in:
parent
8c1d787797
commit
47eaf6b34b
|
|
@ -9,7 +9,7 @@ on:
|
||||||
- master
|
- master
|
||||||
|
|
||||||
env: # 设置环境变量
|
env: # 设置环境变量
|
||||||
TZ: Asia/Shanghai # 时区(设置时区可使页面中的`最近更新时间`使用时区时间)
|
TZ: Asia/Shanghai # 时区(设置时区可使页面中的`最近更新时间`使用该时区时间)
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build: # 自定义名称
|
build: # 自定义名称
|
||||||
|
|
@ -17,7 +17,7 @@ jobs:
|
||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
node-version: [12.x]
|
node-version: [14.x]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout # 步骤1
|
- name: Checkout # 步骤1
|
||||||
|
|
@ -26,16 +26,17 @@ jobs:
|
||||||
uses: actions/setup-node@v1 # 作用:安装nodejs
|
uses: actions/setup-node@v1 # 作用:安装nodejs
|
||||||
with:
|
with:
|
||||||
node-version: ${{ matrix.node-version }} # 版本
|
node-version: ${{ matrix.node-version }} # 版本
|
||||||
- name: build-commit-push # 步骤3
|
- name: build-and-deploy # 步骤3
|
||||||
run: |
|
run: |
|
||||||
remote_addr=`git remote get-url --push origin`
|
remote_addr=`git remote get-url --push origin`
|
||||||
commit_info=`git describe --all --always --long`
|
commit_info=`git describe --all --always --long`
|
||||||
user_name=`git log -1 --pretty=format:'%an'`
|
user_name=`git log -1 --pretty=format:'%an'`
|
||||||
user_email=`git log -1 --pretty=format:'%ae'`
|
user_email=`git log -1 --pretty=format:'%ae'`
|
||||||
npm install
|
deploy_branch=gh-pages
|
||||||
npm run build
|
yarn
|
||||||
|
yarn build
|
||||||
cd docs/.vuepress/dist
|
cd docs/.vuepress/dist
|
||||||
git config --global init.defaultBranch hp-pages
|
git config --global init.defaultBranch $deploy_branch
|
||||||
git init
|
git init
|
||||||
git config user.name ${user_name}
|
git config user.name ${user_name}
|
||||||
git config user.email ${user_email}
|
git config user.email ${user_email}
|
||||||
|
|
@ -44,7 +45,6 @@ jobs:
|
||||||
remote_addr=`echo $remote_addr | awk -F'://' '{print $2}'`
|
remote_addr=`echo $remote_addr | awk -F'://' '{print $2}'`
|
||||||
remote_addr=https://${user_name}:${{secrets.GITHUB_TOKEN}}@${remote_addr}
|
remote_addr=https://${user_name}:${{secrets.GITHUB_TOKEN}}@${remote_addr}
|
||||||
git remote add origin ${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
deploy.sh
39
deploy.sh
|
|
@ -3,41 +3,22 @@
|
||||||
# 确保脚本抛出遇到的错误
|
# 确保脚本抛出遇到的错误
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
|
||||||
|
push_addr=`git remote get-url --push origin` # git提交地址,也可以手动设置,比如:push_addr=git@github.com:xugaoyi/vuepress-theme-vdoing.git
|
||||||
|
commit_info=`git describe --all --always --long`
|
||||||
|
dist_path=docs/.vuepress/dist # 打包生成的文件夹路径
|
||||||
|
push_branch=gh-pages # 推送的分支
|
||||||
|
|
||||||
# 生成静态文件
|
# 生成静态文件
|
||||||
npm run build
|
npm run build
|
||||||
|
|
||||||
# 进入生成的文件夹
|
# 进入生成的文件夹
|
||||||
cd docs/.vuepress/dist
|
cd $dist_path
|
||||||
|
|
||||||
# deploy to github pages
|
|
||||||
echo 'b.xugaoyi.com' > CNAME
|
|
||||||
|
|
||||||
if [ -z "$GITHUB_TOKEN" ]; then
|
|
||||||
msg='deploy'
|
|
||||||
githubUrl=git@github.com: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 "894072666@qq.com"
|
|
||||||
fi
|
|
||||||
git init
|
git init
|
||||||
git add -A
|
git add -A
|
||||||
git commit -m "${msg}"
|
git commit -m "deploy, $commit_info"
|
||||||
git push -f $githubUrl master:gh-pages # 推送到github gh-pages分支
|
git push -f $push_addr HEAD:$push_branch
|
||||||
|
|
||||||
# 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`设置的私密环境变量
|
|
||||||
# codingUrl=git@e.coding.net: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
|
|
||||||
|
|
||||||
cd -
|
cd -
|
||||||
rm -rf docs/.vuepress/dist
|
rm -rf $dist_path
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
b.xugaoyi.com
|
||||||
Loading…
Reference in New Issue