Web Bookmark


Quick Start

在你的仓库里新建 .github/workflows 目录,然后在该目录下新建 .yml 后缀的文件,然后写入以下内容:

  1. name: Chara自用actions
  2. on: # 设置监听仓库事件
  3. push: # 监听推送
  4. branches:
  5. - master # 监听 master 分支
  6. jobs:
  7. build-and-deploy:
  8. runs-on: ubuntu-latest # 设置运行环境
  9. steps:
  10. - name: 版本检出
  11. uses: actions/checkout@v1 # 先检出版本
  12. - name: 安装node
  13. uses: actions/setup-node@v1 # 安装 node 环境
  14. - name: 安装vue-press
  15. run: |
  16. npm install # 安装依赖
  17. - name: 编译
  18. run: |
  19. git config --global user.name "KongValley" # 设置你的账户名
  20. git config --global user.email "kzp13968320676@163.com" # 设置你的登录账号
  21. npm run build
  22. - name: 代码提交到主仓库
  23. env:
  24. ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} # 这个东西我下面会讲
  25. run: |
  26. cd docs/.vuepress/dist
  27. echo 'charablog.cn' > CNAME
  28. git init
  29. git add .
  30. git commit -m 'deploy'
  31. git push -f "https://KongValley:${ACCESS_TOKEN}@github.com/KongValley/KongValley.github.io.git" master # 推送到指定仓库的指定分支

Add ACCESS_TOKEN

ACCESS_TOKEN 是我自己命名的变量名,其实它是在 https://github.com/settings/tokens 上申请的一个 Personal access tokens,权限我基本上都给了,就是 admin:repo_hook, delete_repo, repo, user, workflow 这些,然后将生成的 token 的值复制,然后到你部署这个 actions 的仓库的 settings → secrets 里
1.png
点击 Add a new secret
2.png
填入你想命名的变量名和你之前复制的 token,点击 Add secret 即可
将你的代码 push 上去之后,workflows 就会自动执行
3.png