diff --git a/.github/workflows/scheduler_daily.yml b/.github/workflows/scheduler_daily.yml new file mode 100644 index 0000000..f4ee59f --- /dev/null +++ b/.github/workflows/scheduler_daily.yml @@ -0,0 +1,69 @@ +name: Daily Update + +# 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 20 * * *' + + # [DEBUG ONLY] Every 5 minutes + # https://github.blog/changelog/2019-11-01-github-actions-scheduled-jobs-maximum-frequency-is-changing + #- cron: '*/5 * * * *' + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: 📥 Download codes from GitHub + uses: actions/checkout@v3 + with: + fetch-depth: 2 + + - name: 💎 Set up Ruby + uses: ruby/setup-ruby@v1 + #with: + # bundler-cache: true + #ruby-version: 3.2 # Not necessary if .ruby-version is given + + - name: 🧪 Install Ruby gems + run: | + bundle install + + - name: 📊 Update dojo stats of Japan + run: | + bundle exec ruby update_profile.rb + + - name: 🆙 Update profile if updated + run: | + 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 _data/stats.yml + git commit -m '🤖 Update dojo stats' + git push origin main + fi + env: + GITHUB_TOKEN: + + - name: 🔧 Build & Test + run: | + JEKYLL_ENV=production bundle exec jekyll build + JEKYLL_ENV=production bundle exec jekyll doctor + SKIP_BUILD=true bundle exec rake test + + - name: 🚀 Deploy to GitHub Pages + if: github.ref == 'refs/heads/main' && job.status == 'success' + uses: peaceiris/actions-gh-pages@v3 + with: + personal_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./_site diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 83d08de..a1a8733 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -25,6 +25,10 @@ jobs: with: bundler-cache: true + - name: 🧪 Install gems + run: | + bundle install + - name: 🔧 Build & Test run: | JEKYLL_ENV=test bundle exec jekyll build @@ -49,8 +53,6 @@ jobs: - name: 🧪 Install gems run: | - bundle config set with 'test' - bundle config set path 'vendor/bundle' bundle install - name: 🔧 Build diff --git a/_data/stats.yml b/_data/stats.yml new file mode 100644 index 0000000..0a77479 --- /dev/null +++ b/_data/stats.yml @@ -0,0 +1,2 @@ +--- +active_dojos: 180 diff --git a/index.html b/index.html index 503af36..a263855 100644 --- a/index.html +++ b/index.html @@ -192,7 +192,7 @@

DojoCon Japan とは?

CoderDojo とは?

-

CoderDojo は7〜17歳を対象とした非営利のプログラミング道場です。2011年にアイルランドで始まり、世界では100カ国・2,000の道場、日本には180以上の道場があります。

+

CoderDojo は7〜17歳を対象とした非営利のプログラミング道場です。2011年にアイルランドで始まり、世界では100カ国・2,000の道場、日本には{{ site.data.stats['active_dojos'] }}以上の道場があります。

diff --git a/update_profile.rb b/update_profile.rb new file mode 100755 index 0000000..7d9d032 --- /dev/null +++ b/update_profile.rb @@ -0,0 +1,13 @@ +#!/usr/bin/env ruby + +require 'net/http' +require 'json' +require 'yaml' + +BASE_URL = 'https://coderdojo.jp' +DOJO_STATS = JSON.parse Net::HTTP.get(URI.parse "#{BASE_URL}/stats.json"), symbolize_names: true +STATS_PATH = '_data/stats.yml' + +stats = YAML.load_file(STATS_PATH) +stats['active_dojos'] = DOJO_STATS[:active_dojos] +YAML.dump stats, File.open(STATS_PATH, 'w')