使用github操作和github-pages-deploy-action时github页面问题?

时间:2019-11-08 12:05:45

标签: github-pages github-actions github-pages-deploy-action

我有一个简单的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页没有显示吗?命中时出现404错误

https://emeraldjava.github.io/emeraldjava/

我相信我的回购设置和机密是正确的,但是我必须缺少一些小东西。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:2)

发生这种情况是因为您使用了GITHUB_TOKEN变量。由于内置令牌不会触发GitHub Pages部署作业,因此存在open issue with GitHub。这意味着您将看到文件已正确提交,但它们将不可见。

要解决此问题,您可以使用GitHub访问令牌。您可以学习如何生成一个here。需要正确确定作用域的范围,以便具有推送到公共存储库的权限。您可以将此令牌存储在存储库的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的轮廓。使用访问令牌将允许GitHub Pages作业在进行新部署时触发。希望对您有所帮助!