【问题标题】:github pages issue when using github actions and github-pages-deploy-action?使用 github 操作和 github-pages-deploy-action 时出现 github 页面问题?
【发布时间】:2020-03-05 01:40:26
【问题描述】:

我有一个简单的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/

我相信我的回购设置和秘密是正确的,但我一定遗漏了一些小东西。任何帮助将不胜感激。

【问题讨论】:

  • 您是否在存储库设置中启用了 GitHub 页面并选择部署 gh-pages 分支?
  • 是的 - 项目设置有 'gh-pages' 分支作为 github 页面的来源。
  • 不 - 这是一个不同的仓库:github.com/emeraldjava/emeraldjava.github.io
  • 嗯——很奇怪,来自这个问题stackoverflow.com/questions/20422279/…。我在 github 浏览器编辑器中手动编辑了 gh-pages index.html 文件,所有后续的 Action 构建似乎都已发布,即使这样我删除了 gh-pages 分支。

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


【解决方案1】:

这是因为您使用了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 作业在进行新部署时触发。希望对您有所帮助!

【讨论】:

  • 谢谢 - 我误读了 GITHUB_TOKEN 和 ACCESS_TOKEN 的交互方式。
猜你喜欢
  • 2020-08-10
  • 2017-02-18
  • 2020-11-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多