|
| 1 | +name: Daily Workflow |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + # 毎朝 9:00 JST |
| 6 | + - cron: '0 0 * * *' |
| 7 | + # Allows you to run this workflow manually from the Actions tab |
| 8 | + # https://docs.github.com/en/actions/managing-workflow-runs/manually-running-a-workflow |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +jobs: |
| 12 | + daily: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + outputs: |
| 15 | + FOUND_NEWS: ${{ steps.check_news.outputs.FOUND_NEWS }} |
| 16 | + |
| 17 | + steps: |
| 18 | + - name: ☑️ Checkout code |
| 19 | + uses: actions/checkout@v4 |
| 20 | + with: |
| 21 | + fetch-depth: 2 |
| 22 | + |
| 23 | + - name: 💎 Setup Ruby |
| 24 | + uses: ruby/setup-ruby@v1 |
| 25 | + with: |
| 26 | + bundler-cache: true |
| 27 | + |
| 28 | + - name: 📰 Run news:fetch task |
| 29 | + run: bin/rails news:fetch |
| 30 | + |
| 31 | + - name: 🆙 Commit updated news.yml |
| 32 | + id: check_news |
| 33 | + run: | |
| 34 | + git config user.name "Yohei Yasukawa" |
| 35 | + git config user.email "yohei@yasslab.jp" |
| 36 | + git checkout main |
| 37 | + git add db/news.yml |
| 38 | + if ! git diff --cached --quiet; then |
| 39 | + git commit -m '🤖 Upsert db/news.yml' |
| 40 | + git push origin main |
| 41 | + echo "🆕 Found news in db/news.yml" |
| 42 | + echo "FOUND_NEWS=true" >> $GITHUB_OUTPUT |
| 43 | + else |
| 44 | + echo "✅ No news in db/news.yml" |
| 45 | + echo "FOUND_NEWS=false" >> $GITHUB_OUTPUT |
| 46 | + fi |
| 47 | +
|
| 48 | + deploy: |
| 49 | + needs: daily |
| 50 | + if: ${{ needs.daily.outputs.FOUND_NEWS == 'true' }} |
| 51 | + # TODO: ubuntu-latest image needs to install heroku CLI to deploy. |
| 52 | + # https://github.com/AkhileshNS/heroku-deploy/issues/188 |
| 53 | + runs-on: ubuntu-22.04 |
| 54 | + |
| 55 | + steps: |
| 56 | + - name: ☑️ Checkout code |
| 57 | + uses: actions/checkout@v4 |
| 58 | + with: |
| 59 | + ref: main |
| 60 | + |
| 61 | + - name: 🚀 Deploy to Heroku |
| 62 | + uses: akhileshns/heroku-deploy@v3.14.15 |
| 63 | + with: |
| 64 | + heroku_api_key: ${{ secrets.HEROKU_API_KEY }} |
| 65 | + heroku_app_name: ${{ secrets.HEROKU_APP_NAME }} |
| 66 | + heroku_email: ${{ secrets.HEROKU_EMAIL }} |
0 commit comments