Skip to content

Commit e9f9223

Browse files
committed
♻️ Refactor GitHub Actions workflow for conditional deployment
主な改善: - デプロイを独立したジョブに分離し、GitHub Actionsのベストプラクティスに準拠 - job outputs を使用した適切なジョブ間データ共有の実装 - $GITHUB_ENV から $GITHUB_OUTPUT への移行(GitHub推奨の最新仕様) - 重複した bundle install を削除(bundler-cache: true で自動実行) - 環境変数名を FOUND_NEWS に統一(一貫性のある大文字表記) - heroku-deploy アクションを最新版(v3.14.15)に更新 効果: - ニュースが見つからない場合はデプロイジョブ自体がスキップされ、実行時間を短縮 - ワークフローの構造が明確になり、保守性が向上 - GitHub Actions の最新仕様に準拠し、将来的な互換性を確保
1 parent 7b0f1ce commit e9f9223

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

.github/workflows/daily.yml

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ on:
1111
jobs:
1212
daily:
1313
runs-on: ubuntu-latest
14+
outputs:
15+
FOUND_NEWS: ${{ steps.check_news.outputs.FOUND_NEWS }}
1416

1517
steps:
1618
- name: ☑️ Checkout code
@@ -23,13 +25,11 @@ jobs:
2325
with:
2426
bundler-cache: true
2527

26-
- name: 🧪 Install dependencies
27-
run: bundle install
28-
2928
- name: 📰 Run news:fetch task
3029
run: bin/rails news:fetch
3130

3231
- name: 🆙 Commit updated news.yml
32+
id: check_news
3333
run: |
3434
git config user.name "Yohei Yasukawa"
3535
git config user.email "[email protected]"
@@ -39,26 +39,26 @@ jobs:
3939
git commit -m '🤖 Upsert db/news.yml'
4040
git push origin main
4141
echo "🆕 Found news in db/news.yml"
42-
echo "FOUND_NEWS=true" >> $GITHUB_ENV
42+
echo "FOUND_NEWS=true" >> $GITHUB_OUTPUT
4343
else
4444
echo "✅ No news in db/news.yml"
45-
echo "FOUND_NEWS=false" >> $GITHUB_ENV
45+
echo "FOUND_NEWS=false" >> $GITHUB_OUTPUT
4646
fi
4747
48-
- name: ✅ Do nothing if no news found
49-
if: ${{ env.FOUND_NEWS == 'false' }}
50-
run: |
51-
echo "No news found."
52-
53-
- name: 🚀 Deploy to Heroku if news found
54-
if: ${{ env.FOUND_NEWS == 'true' }}
55-
# TODO: This workflows depend on Ubuntu version.
56-
# https://github.com/AkhileshNS/heroku-deploy/issues/186
57-
runs-on: ubuntu-22.04
58-
steps:
59-
- uses: actions/checkout@v3
60-
- uses: akhileshns/heroku-deploy@v3.13.15
61-
with:
62-
heroku_api_key: ${{ secrets.HEROKU_API_KEY }}
63-
heroku_app_name: ${{ secrets.HEROKU_APP_NAME }}
64-
heroku_email: ${{ secrets.HEROKU_EMAIL }}
48+
deploy:
49+
needs: daily
50+
if: ${{ needs.daily.outputs.FOUND_NEWS == 'true' }}
51+
runs-on: ubuntu-latest
52+
53+
steps:
54+
- name: ☑️ Checkout code
55+
uses: actions/checkout@v4
56+
with:
57+
ref: main
58+
59+
- name: 🚀 Deploy to Heroku
60+
uses: akhileshns/heroku-deploy@v3.14.15
61+
with:
62+
heroku_api_key: ${{ secrets.HEROKU_API_KEY }}
63+
heroku_app_name: ${{ secrets.HEROKU_APP_NAME }}
64+
heroku_email: ${{ secrets.HEROKU_EMAIL }}

0 commit comments

Comments
 (0)