我有简单的github repo我在这里存放我的简历内容。我使用 hackmyresume 生成index.html。我正在使用 Github Actions 运行 npm 构建,它应该将生成的内容发布到 gh-pages 分支。
我的工作流程文件有
on:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Deploy with github-pages
uses: JamesIves/github-pages-deploy-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BASE_BRANCH: master # The branch the action should deploy from.
BRANCH: gh-pages # The branch the action should deploy to.
FOLDER: target # The folder the action should deploy.
BUILD_SCRIPT: npm install && npm run-script build
构建命令是
"build": "hackmyresume BUILD ./src/main/resources/json/fresh/resume.json target/index.html -t compact",
我可以看到生成的 html 文件被提交到 github 分支
https://github.com/emeraldjava/emeraldjava/blob/gh-pages/index.html
但是 gh-page 没有接收到这个?当我点击时出现 404 错误
https://emeraldjava.github.io/emeraldjava/
我相信我的存储库设置和 secret 是正确的,但我一定错过了一些小东西。任何帮助将不胜感激。
最佳答案
发生这种情况是因为您使用了 GITHUB_TOKEN
变量。有一个open issue with GitHub由于内置 token 不会触发 GitHub Pages 部署作业。这意味着您将看到文件已正确提交,但它们不可见。
要解决此问题,您可以使用 GitHub 访问 token 。您可以学习如何生成一个here 。它需要正确确定范围,以便有权推送到公共(public)存储库。您可以将此 token 存储在存储库的 Settings > Secrets
菜单中(将其命名为 ACCESS_TOKEN
),然后在您的配置中引用它,如下所示:
on:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Deploy with github-pages
uses: JamesIves/github-pages-deploy-action@master
env:
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
BASE_BRANCH: master # The branch the action should deploy from.
BRANCH: gh-pages # The branch the action should deploy to.
FOLDER: target # The folder the action should deploy.
BUILD_SCRIPT: npm install && npm run-script build
您可以找到这些变量的概要 here 。使用访问 token 将允许 GitHub Pages 作业在进行新部署时触发。我希望这有帮助!
关于github-pages - 使用 github actions 和 github-pages-deploy-action 时,github 页面出现问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58766278/