github 使用 github 操作和 github-pages-deploy-action 时出现页面问题?
github pages issue when using github actions and github-pages-deploy-action?
我有一个简单的 github repo 存放我的简历的内容。我使用 hackmyresume 生成 index.html。我正在使用 Github 操作来 运行 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_TOKEN
变量。由于内置令牌不会触发 GitHub 页面部署作业,因此存在 open issue with GitHub。这意味着您会看到文件已正确提交,但它们将不可见。
要解决此问题,您可以使用 GitHub 访问令牌。您可以学习如何生成一个 here。它需要正确的范围,以便它有权推送到 public 存储库。您可以将此令牌存储在存储库的 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 repo 存放我的简历的内容。我使用 hackmyresume 生成 index.html。我正在使用 Github 操作来 运行 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_TOKEN
变量。由于内置令牌不会触发 GitHub 页面部署作业,因此存在 open issue with GitHub。这意味着您会看到文件已正确提交,但它们将不可见。
要解决此问题,您可以使用 GitHub 访问令牌。您可以学习如何生成一个 here。它需要正确的范围,以便它有权推送到 public 存储库。您可以将此令牌存储在存储库的 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 作业在进行新部署时触发。希望对您有所帮助!