Skip to content

Scheduler (Daily) #1113

Scheduler (Daily)

Scheduler (Daily) #1113

name: Scheduler (Daily)
# NOTE: GitHub Action's scheduler is always set to UTC+0. So 9am should be set at 0am for JST (UTC+9)
# https://docs.github.com/en/actions/reference/events-that-trigger-workflows#scheduled-events-schedule
# '0 23 * * *' == 8am in JST (UTC+9)
# '0 0 * * *' == 9am in JST (UTC+9)
# '0 1 * * *' == 10am in JST (UTC+9)
# '59 23 * * *' task will be completed after 9am in JST
on:
schedule:
- cron: '59 23 * * *'
# 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:
build:
runs-on: ubuntu-latest
steps:
- name: ☑️ Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: 💎 Set up Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
#ruby-version: 2.7 # Not necessary if .ruby-version is given
- name: 🧪 Install Ruby gems with 'actions' group
run: |
bundle config set with 'actions'
bundle config set path 'vendor/bundle'
bundle install --jobs 4 --retry 3
- name: 🔔 Notify daily updates in Gumroad by using Emoji
run: bundle exec rake share_gumroad_updates
env:
SLACK_GUMROAD: ${{ secrets.SLACK_GUMROAD }}
GUMROAD_ACCESS_TOKEN: ${{ secrets.GUMROAD_ACCESS_TOKEN }}
- name: 📅 Share event summary today from given calendar
run: bundle exec rake share_calendar_events
env:
SLACK_CALENDAR: ${{ secrets.SLACK_CALENDAR }}
GOOGLE_CALENDAR_IDS: ${{ secrets.GOOGLE_CALENDAR_IDS }}
GOOGLE_SECRETS: ${{ secrets.GOOGLE_SECRETS }}
GOOGLE_TOKENS: ${{ secrets.GOOGLE_TOKENS }}
- name: ♨️ Fetch Japanese holidays to cache
run: |
bundle exec rake fetch_japanese_holidays
echo "NEW_HOLIDAY=false" >> $GITHUB_ENV
if [ -n "$(git status --porcelain)" ]; then
git config --global user.name "Yohei Yasukawa"
git config --global user.email "yohei@yasslab.jp"
git checkout main
git add holidays.json
git commit -m '🤖 Upsert holiday data by GitHub Actions'
git push origin main
echo "NEW_HOLIDAY=true" >> $GITHUB_ENV
echo "Found new holiday(s)."
else
echo "No new holiday(s) found."
fi
env:
GITHUB_TOKEN:
- name: ✅ No new holidays found
if: ${{ env.NEW_HOLIDAY == 'false' }}
run: |
echo "No new holiday(s) found."
- name: 🚀 Deploy to Heroku if recent article(s) found
if: ${{ env.NEW_HOLIDAY == 'true' }}
uses: akhileshns/heroku-deploy@v3.12.13
with:
branch: 'main'
usedocker: false
heroku_api_key: ${{ secrets.HEROKU_API_KEY }}
heroku_app_name: 'yasslab-jp'
heroku_email: 'yohei@yasslab.jp'
healthcheck: 'https://yasslab.jp/health'
#- name: 🚨 Notify if tasks in GitHub Actions failed
# env:
# IDOBATA_GITHUB_ACTIONS: ${{ secrets.IDOBATA_GITHUB_ACTIONS }}
# if: failure() && (env.IDOBATA_GITHUB_ACTIONS != null)
# uses: mahaker/actions-idobata@v1.1.2
# with:
# hookUrl: ${{ secrets.IDOBATA_GITHUB_ACTIONS }}
# format: 'markdown'
# message: |
# <span class='label label-danger'>failed</span> @yasulab :warning: GitHub Actions のタスク実行に失敗しました >< :sweat_drops: ([build](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}))