Skip to content

Commit

Permalink
GitHub Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
storyxc committed Jul 10, 2023
1 parent 0a81c39 commit de94121
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
26 changes: 26 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 自定义当前执行文件的名称
name: document
# 整个流程在main分支发生push事件时触发
on:
push:
branches:
- main
jobs:
build-and-deploy:
runs-on: ubuntu-latest # 运行在ubuntu-latest环境的虚拟机中
strategy:
matrix:
node-version: [20.x]
steps:
# 获取仓库源码
- name: Checkout
uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }} # 步骤2
uses: actions/setup-node@v3 # 作用:安装nodejs
with:
node-version: ${{ matrix.node-version }} # 版本
# 构建和部署
- name: Deploy
env: # 环境变量
GH_TOKEN: ${{ secrets.GH_TOKEN }} # 在仓库中配置的token
run: npm install && npm run deploy
33 changes: 33 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env sh

# 确保脚本抛出遇到的错误
set -e

# 生成静态文件
npm run build

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

# 如果是发布到自定义域名
echo 'blog.storyxc.com' > CNAME

if [ -z "${GH_TOKEN}" ]; then
echo "GH_TOKEN is not set"
exit 1
else
msg='github actions自动部署'
githubUrl=https://storyxc:${GH_TOKEN}@github.com/storyxc/document.git
git config --global user.name "storyxc"
git config --global user.email "[email protected]"
fi

git init
git add -A
git commit -m "${msg}"

git push -f "$githubUrl" master:gh-pages

cd -

rm -rf docs/.vuepress/dist
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"main": "index.js",
"scripts": {
"dev": "vuepress dev docs",
"build": "vuepress build docs"
"build": "vuepress build docs",
"deploy": "bash deploy.sh"
},
"keywords": [],
"author": "",
Expand Down

0 comments on commit de94121

Please sign in to comment.