1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Astroを使ったGitHub Pagesがビルドできなくなった時の対処法

Posted at

はじめに

公式で公開されている方法を使ってAstroで作成したブログをGitHub Pagesで公開していたのですが、ファイルを更新してもビルドが通らない、という現象に遭遇しました。

これはよくないということで対処してみたのですが、結構格闘する羽目になったので、その時の対処法を記録しておきます。

対処法

結論から言うと、GitHub Actionの設定ファイル、(.github/workflows/deploy.yamlのようなもの)を以下のように変更することで解決することができました。

name: Deploy to GitHub Pages

on:
  push:
    branches: [ master ]
  workflow_dispatch:

permissions:
  contents: read
  pages: write
  id-token: write

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Install, build, and upload your site
        # v1→v2
        uses: withastro/action@v2
  deploy:
    needs: build
    runs-on: ubuntu-latest
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    steps:
      - name: Deploy to GitHub Pages
        id: deployment
        # v1→v4
        uses: actions/deploy-pages@v4

これでGitHub Pagesへデプロイできるようになりました。

上記の通り変更は二か所だったのですが、どこを直せばいいのかが調べても中々分からず、GitHub Actionのエラーログとにらめっこしてなんとか原因をつかみました。

withastro/action@v1はどうやらactions/upload-artifact@v2を使っているようです。しかし、最近actions/upload-artifact@v2が廃止され、actions/upload-artifact@v3を用いないといけなくなったそうです。

Error: This request has been automatically failed because it uses a deprecated version of `actions/upload-artifact: v3`. Learn more: https://github.blog/changelog/2024-04-16-deprecation-notice-v3-of-the-artifact-actions/

なので、withastro/action@v2に変更してこれに対応する必要があったわけです。

最初はactions/upload-artifact@v3を明示的に書いてどうにかしようとしたのですが、結局withastro/action@v1が存在しているとactions/upload-artifact@v2を呼び出そうとするようで永遠にエラーが解消されませんでした。

おわりに

Astroは静的なサイトジェネレータとして人気なので、GitHub Pagesで公開する人も多いと思います。しかし、最近の仕様変更で今回のようなエラーが発生する可能性が出て来たようです。

上記のようにGitHub Actionの設定ファイルを変更することで解決できるので、同じようなエラーに遭遇した方は参考にしてみてください。

それではまた。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?