Try   HackMD

解決 GitHub Actions 部署到 GitHub Pages 遇到 Permission denied 的問題

問題描述

在今年(2023)全新建立的專案,執行到 JamesIves/github-pages-deploy-action 步驟時會失敗,根據 log 可以得知是在 GitHub Actions 執行到 git push 時遇到 403 錯誤。

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

/usr/bin/git commit -m Deploying to page from @ ngseke/test@075776ff3f9a7b27bb5809efe605152205deabe5 🚀 quiet no-verify
/usr/bin/git push force ***github.com/ngseke/test.git github-pages-deploy-action/8rb7mcfwb:page
remote: Permission to ngseke/test.git denied to github-actions[bot].
fatal: unable to access 'https://github.com/ngseke/test.git/': The requested URL returned error: 403

這是 GitHub 在 2023 年 2 月的這個變動所導致的,原先 GITHUB_TOKEN 會一律預設得到 read/write 的權限,但後來改成了 read-only 才使得 git push 失敗,因此只需要手動調整權限即可。

現有專案則會維持原本的權限,不需要額外設定。

解決方法

  1. 到 Repository → Settings 分頁 → 左側欄 ActionsGeneral

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

  2. Workflow permissions 區塊 → 選中 Read and write permissions → 點擊 Save

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

  3. 再次 Re-run workflow 應該就可以成功部署