From 09f8d7e2aeadaff9ab3c069961315a4efc9d1629 Mon Sep 17 00:00:00 2001 From: Yohei Yasukawa Date: Sun, 14 Sep 2025 15:18:05 +0900 Subject: [PATCH 1/5] Rename workflow to be DRY for other future daily tasks: fetch_news -> daily.yml --- .github/workflows/{fetch_news.yml => daily.yml} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename .github/workflows/{fetch_news.yml => daily.yml} (97%) diff --git a/.github/workflows/fetch_news.yml b/.github/workflows/daily.yml similarity index 97% rename from .github/workflows/fetch_news.yml rename to .github/workflows/daily.yml index 01c36a8c0..156df89eb 100644 --- a/.github/workflows/fetch_news.yml +++ b/.github/workflows/daily.yml @@ -1,4 +1,4 @@ -name: Fetch News +name: Daily Workflow on: schedule: From c961d5c6a03c8ae26fa6922b295fb583dc1d6b8a Mon Sep 17 00:00:00 2001 From: Yohei Yasukawa Date: Sun, 14 Sep 2025 15:34:07 +0900 Subject: [PATCH 2/5] Remove no-need option: `.ruby-version` is set by default https://github.com/ruby/setup-ruby#usage --- .github/workflows/daily.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/daily.yml b/.github/workflows/daily.yml index 156df89eb..69424b104 100644 --- a/.github/workflows/daily.yml +++ b/.github/workflows/daily.yml @@ -17,7 +17,6 @@ jobs: - name: Set up Ruby uses: ruby/setup-ruby@v1 with: - ruby-version: .ruby-version bundler-cache: true - name: Install dependencies From 6227ea1052fab753917f5eb70a42dc86a9ad1d5d Mon Sep 17 00:00:00 2001 From: Yohei Yasukawa Date: Sun, 14 Sep 2025 15:36:14 +0900 Subject: [PATCH 3/5] bundle install works well by default; for example, it runs in parallel based on the num of available processors https://bundler.io/v2.7/man/bundle-install.1.html --- .github/workflows/daily.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/daily.yml b/.github/workflows/daily.yml index 69424b104..4b6b96f62 100644 --- a/.github/workflows/daily.yml +++ b/.github/workflows/daily.yml @@ -20,7 +20,7 @@ jobs: bundler-cache: true - name: Install dependencies - run: bundle install --jobs 4 --retry 3 + run: bundle install - name: Run news:fetch task run: bin/rails news:fetch From 7b0f1ce5ff725dfe4637641732a8fed434e26801 Mon Sep 17 00:00:00 2001 From: Yohei Yasukawa Date: Sun, 14 Sep 2025 15:59:00 +0900 Subject: [PATCH 4/5] Run deploy job when daily task(s) finished and found news in Actions --- .github/workflows/daily.yml | 74 +++++++++++++++++++++++++------------ 1 file changed, 50 insertions(+), 24 deletions(-) diff --git a/.github/workflows/daily.yml b/.github/workflows/daily.yml index 4b6b96f62..277ecdbb1 100644 --- a/.github/workflows/daily.yml +++ b/.github/workflows/daily.yml @@ -4,35 +4,61 @@ on: schedule: # 毎朝 9:00 JST - cron: '0 0 * * *' + # Allows you to run this workflow manually from the Actions tab + # https://docs.github.com/en/actions/managing-workflow-runs/manually-running-a-workflow workflow_dispatch: jobs: - fetch: + daily: runs-on: ubuntu-latest steps: - - name: Checkout repository - uses: actions/checkout@v4 + - name: ☑️ Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 2 - - name: Set up Ruby - uses: ruby/setup-ruby@v1 + - name: 💎 Setup Ruby + uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + + - name: 🧪 Install dependencies + run: bundle install + + - name: 📰 Run news:fetch task + run: bin/rails news:fetch + + - name: 🆙 Commit updated news.yml + run: | + git config user.name "Yohei Yasukawa" + git config user.email "yohei@yasslab.jp" + git checkout main + git add db/news.yml + if ! git diff --cached --quiet; then + git commit -m '🤖 Upsert db/news.yml' + git push origin main + echo "🆕 Found news in db/news.yml" + echo "FOUND_NEWS=true" >> $GITHUB_ENV + else + echo "✅ No news in db/news.yml" + echo "FOUND_NEWS=false" >> $GITHUB_ENV + fi + + - name: ✅ Do nothing if no news found + if: ${{ env.FOUND_NEWS == 'false' }} + run: | + echo "No news found." + + - name: 🚀 Deploy to Heroku if news found + if: ${{ env.FOUND_NEWS == 'true' }} + # TODO: This workflows depend on Ubuntu version. + # https://github.com/AkhileshNS/heroku-deploy/issues/186 + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + - uses: akhileshns/heroku-deploy@v3.13.15 with: - bundler-cache: true - - - name: Install dependencies - run: bundle install - - - name: Run news:fetch task - run: bin/rails news:fetch - - - name: Commit updated news.yml - run: | - git config user.name "github-actions[bot]" - git config user.email "github-actions[bot]@users.noreply.github.com" - git add db/news.yml - if ! git diff --cached --quiet; then - git commit -m "chore: update news.yml via GitHub Actions" - git push - else - echo "No changes in db/news.yml" - fi + heroku_api_key: ${{ secrets.HEROKU_API_KEY }} + heroku_app_name: ${{ secrets.HEROKU_APP_NAME }} + heroku_email: ${{ secrets.HEROKU_EMAIL }} From e9f922338a78c5b378352eb2289cbb19414286bf Mon Sep 17 00:00:00 2001 From: Yohei Yasukawa Date: Sun, 14 Sep 2025 16:10:52 +0900 Subject: [PATCH 5/5] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Refactor=20GitHub=20Ac?= =?UTF-8?q?tions=20workflow=20for=20conditional=20deployment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 主な改善: - デプロイを独立したジョブに分離し、GitHub Actionsのベストプラクティスに準拠 - job outputs を使用した適切なジョブ間データ共有の実装 - $GITHUB_ENV から $GITHUB_OUTPUT への移行(GitHub推奨の最新仕様) - 重複した bundle install を削除(bundler-cache: true で自動実行) - 環境変数名を FOUND_NEWS に統一(一貫性のある大文字表記) - heroku-deploy アクションを最新版(v3.14.15)に更新 効果: - ニュースが見つからない場合はデプロイジョブ自体がスキップされ、実行時間を短縮 - ワークフローの構造が明確になり、保守性が向上 - GitHub Actions の最新仕様に準拠し、将来的な互換性を確保 --- .github/workflows/daily.yml | 44 ++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/.github/workflows/daily.yml b/.github/workflows/daily.yml index 277ecdbb1..fc007bd21 100644 --- a/.github/workflows/daily.yml +++ b/.github/workflows/daily.yml @@ -11,6 +11,8 @@ on: jobs: daily: runs-on: ubuntu-latest + outputs: + FOUND_NEWS: ${{ steps.check_news.outputs.FOUND_NEWS }} steps: - name: ☑️ Checkout code @@ -23,13 +25,11 @@ jobs: with: bundler-cache: true - - name: 🧪 Install dependencies - run: bundle install - - name: 📰 Run news:fetch task run: bin/rails news:fetch - name: 🆙 Commit updated news.yml + id: check_news run: | git config user.name "Yohei Yasukawa" git config user.email "yohei@yasslab.jp" @@ -39,26 +39,26 @@ jobs: git commit -m '🤖 Upsert db/news.yml' git push origin main echo "🆕 Found news in db/news.yml" - echo "FOUND_NEWS=true" >> $GITHUB_ENV + echo "FOUND_NEWS=true" >> $GITHUB_OUTPUT else echo "✅ No news in db/news.yml" - echo "FOUND_NEWS=false" >> $GITHUB_ENV + echo "FOUND_NEWS=false" >> $GITHUB_OUTPUT fi - - name: ✅ Do nothing if no news found - if: ${{ env.FOUND_NEWS == 'false' }} - run: | - echo "No news found." - - - name: 🚀 Deploy to Heroku if news found - if: ${{ env.FOUND_NEWS == 'true' }} - # TODO: This workflows depend on Ubuntu version. - # https://github.com/AkhileshNS/heroku-deploy/issues/186 - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v3 - - uses: akhileshns/heroku-deploy@v3.13.15 - with: - heroku_api_key: ${{ secrets.HEROKU_API_KEY }} - heroku_app_name: ${{ secrets.HEROKU_APP_NAME }} - heroku_email: ${{ secrets.HEROKU_EMAIL }} + deploy: + needs: daily + if: ${{ needs.daily.outputs.FOUND_NEWS == 'true' }} + runs-on: ubuntu-latest + + steps: + - name: ☑️ Checkout code + uses: actions/checkout@v4 + with: + ref: main + + - name: 🚀 Deploy to Heroku + uses: akhileshns/heroku-deploy@v3.14.15 + with: + heroku_api_key: ${{ secrets.HEROKU_API_KEY }} + heroku_app_name: ${{ secrets.HEROKU_APP_NAME }} + heroku_email: ${{ secrets.HEROKU_EMAIL }}