0
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?

More than 1 year has passed since last update.

GitHub Pagesでデプロイしたサイトにカスタムドメインを割り当てると、次のGitHub Actionsでデプロイした際にカスタムドメインが消える

Posted at

GitHub PagesでNuxt3で作成したサイトを公開していたのですが、カスタムドメインを割り当てたら、Actionsによる自動デプロイ時にカスタムドメインが勝手に削除されてしまいました。

調査していたところ、以下の投稿を見つけました。
https://github.com/facebook/docusaurus/issues/3889

読んでみたところ、CNAMEファイルなるものを追加する必要があるようです。

If you use a static site generator to build your site locally and push the generated files to GitHub, pull the commit that added the CNAME file to your local repository. For more information, see "Troubleshooting custom domains and GitHub Pages."

引用:https://docs.github.com/en/pages/configuring-a-custom-domain-for-your-github-pages-site/managing-a-custom-domain-for-your-github-pages-site#configuring-a-subdomain

対策

Actions用yml修正

GitHub Actions用のymlファイルにCNAMEファイル作成コマンドを追加します

cd.yml
・・・
      - name: Generate
        run: yarn generate

      - name: create CNAME
        run: touch dist/CNAME && echo ${{ secrets.CNAME }} >> dist/CNAME

      - name: Deploy
        uses: peaceiris/actions-gh-pages@v3
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_dir: ./dist

※yarn generateで作成されるdistディレクトリをデプロイするため、その中にCNAMEファイルを作成します

環境変数追加

Settingsで環境変数を追加します

image.png

ymlプッシュ

対応したymlファイルをプッシュします。
Actionsでデプロイが実行されたときに、自動でサブドメインが登録されます!

image.png

ちなみに

※以前、以下の記事を書いたときに書き忘れてたみたいです。。。
 該当のリポジトリを見たらCNAMEファイルありました:sweat:

0
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
0
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?