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?

More than 1 year has passed since last update.

Vercelのデプロイをwebhookで簡単に定時実行する

Last updated at Posted at 2023-10-04

前提

VercelでWebサイトをホスティングしているが、deployを毎時一回以上行わなければならない。

🤔状況:
NotionAPIを使用してブログを作ったが、NotionAPIの画像リンクは1時間で切れる(セキュリティーの都合上)ため、一時間以上開けて誰かがアクセスした時に画像が表示されない問題が発生する。その場で再度リロードするとvalidateのおかげで問題なく表示されるようになるけど、ユーザー体験としてはよくない。

↓作ったブログ

🔧解決法

vercel CLI

Tokenを発行してやる方法。知識不足すぎて理解できず泣きながらブラウザバックした。

GitHub Actionsでコミットプッシュを繰り返す方法

こちらの記事に書いてあって面白いなって思ったけど、コミット履歴はクリーンにしたいので今回は用途に合わず見送った。

webhookを使う方法(これ)

一番簡単な気がする。この記事で説明。

🔥やり方

まずProject Settingsからdeploy hookを作成する。コピっておく。

スクリーンショット 2023-10-04 23.53.20.png

次にGitHubの該当リポジトリのsecretにAPI_URL(などの任意の名前)で保存する。

最後に、yamlを書いて以下の内容でGitHub Actionsを生成する。nameは適当に好きなのにしてOK。実行間隔はcronの行をいじる。

internet.yml
name: internet yamelo

on:
  push:
    branches:
      - main
  schedule:
    - cron: "0 * * * *"
  workflow_dispatch:
  repository_dispatch:

jobs:
  build:
    name: build
    
    runs-on: ubuntu-latest
    
    steps:
    - name: Call the web hook
      run: curl -X POST ${{ secrets.API_URL }}
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?