github 三种不同的 token

GITHUB_TOKEN

该 token 为用于 GitHub actions 的内置 token, 可用于对执行 actions 的仓库进行访问操作, 直接使用 secrets.GITHUB_TOKEN 即可在 GitHub actions 中使用.

GitHub Actions使用方式:

- name: Deploy
        uses: peaceiris/actions-gh-pages@v3
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }} # 另外还支持 github_token 和 deploy_key (https://github.com/peaceiris/actions-gh-pages#readme)

deploy_key

该 key 针对仓库, 是公钥加私钥形式, 可使用 SSH key, 配置方式如下

  1. 生成 SSH Key 打开 terminal 输入下面的命令生成 id_rsa 和 id_rsa.pub 文件:
ssh-keygen -t rsa -C [email protected]

其中 [email protected] 就是 GitHub 账号的邮箱。

  1. 填写 Deploy Keys 和 Secrets

打开源码仓库,在设置中找到「Secrets」

第 1/3 步:添加 DEPLOY_KEY 内容是 id_rsa 文件的全部内容。

第 2/3 步:添加 EMAIL 内容是 GitHub 邮箱。

第 3/3 步:添加 NAME 内容是 GitHub 账号名。

打开 deploy 目标仓库,在设置中找到「Deploy Keys」

第 1/1 步:添加 deploy_key.pub 内容是 id_rsa.pub 文件的全部内容。

GitHub Actions使用方式:

- name: Deploy
        uses: peaceiris/actions-gh-pages@v3
        with:
          deploy_key: ${{ secrets.DEPLOY_KEY }} # 另外还支持 github_token 和 personal_token (https://github.com/peaceiris/actions-gh-pages#readme)

personal access token

token 的生成需要到这里:个人头像 -> Settings -> Developer settings -> Personal access tokens,点击 Generate new token。这一步需要输入密码,然后可以根据需要定制token的权限

该token的权限最大, 可对账户进行操作, 在生成时可以选在token的权限范围, 越小越好.

GitHub Actions使用方式(将生成的token添加到对应仓库的secret中):

- name: Deploy
        uses: peaceiris/actions-gh-pages@v3
        with:
          personal_token: ${{ secrets.PERSONAL_ACCESS_KEY_TO_DEPLOY_BLOG }} # 另外还支持 github_token 和 deploy_key (https://github.com/peaceiris/actions-gh-pages#readme)