Skip to content

Commit 7d6933b

Browse files
authored
Merge pull request #1 from coderdojo-japan/automate-to-update-profile-upon-dojo-stats
Automate to update profile upon dojo stats
2 parents c9b5ecd + 930301a commit 7d6933b

File tree

5 files changed

+89
-3
lines changed

5 files changed

+89
-3
lines changed

.github/workflows/scheduler_daily.yml

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Daily Update
2+
3+
# NOTE: GitHub Action's scheduler is always set to UTC+0. So 9am should be set at 0am for JST (UTC+9)
4+
# https://docs.github.com/en/actions/reference/events-that-trigger-workflows#scheduled-events-schedule
5+
6+
# '0 23 * * *' == 8am in JST (UTC+9)
7+
# '0 0 * * *' == 9am in JST (UTC+9)
8+
# '0 1 * * *' == 10am in JST (UTC+9)
9+
# '59 23 * * *' task will be completed after 9am in JST
10+
on:
11+
schedule:
12+
- cron: '59 20 * * *'
13+
14+
# [DEBUG ONLY] Every 5 minutes
15+
# https://github.blog/changelog/2019-11-01-github-actions-scheduled-jobs-maximum-frequency-is-changing
16+
#- cron: '*/5 * * * *'
17+
18+
# Allows you to run this workflow manually from the Actions tab
19+
workflow_dispatch:
20+
21+
jobs:
22+
build:
23+
runs-on: ubuntu-latest
24+
25+
steps:
26+
- name: 📥 Download codes from GitHub
27+
uses: actions/checkout@v3
28+
with:
29+
fetch-depth: 2
30+
31+
- name: 💎 Set up Ruby
32+
uses: ruby/setup-ruby@v1
33+
#with:
34+
# bundler-cache: true
35+
#ruby-version: 3.2 # Not necessary if .ruby-version is given
36+
37+
- name: 🧪 Install Ruby gems
38+
run: |
39+
bundle install
40+
41+
- name: 📊 Update dojo stats of Japan
42+
run: |
43+
bundle exec ruby update_profile.rb
44+
45+
- name: 🆙 Update profile if updated
46+
run: |
47+
if [ -n "$(git status --porcelain)" ]; then
48+
git config --global user.name "Yohei Yasukawa"
49+
git config --global user.email "[email protected]"
50+
git checkout main
51+
git add _data/stats.yml
52+
git commit -m '🤖 Update dojo stats'
53+
git push origin main
54+
fi
55+
env:
56+
GITHUB_TOKEN:
57+
58+
- name: 🔧 Build & Test
59+
run: |
60+
JEKYLL_ENV=production bundle exec jekyll build
61+
JEKYLL_ENV=production bundle exec jekyll doctor
62+
SKIP_BUILD=true bundle exec rake test
63+
64+
- name: 🚀 Deploy to GitHub Pages
65+
if: github.ref == 'refs/heads/main' && job.status == 'success'
66+
uses: peaceiris/actions-gh-pages@v3
67+
with:
68+
personal_token: ${{ secrets.GITHUB_TOKEN }}
69+
publish_dir: ./_site

.github/workflows/test.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ jobs:
2525
with:
2626
bundler-cache: true
2727

28+
- name: 🧪 Install gems
29+
run: |
30+
bundle install
31+
2832
- name: 🔧 Build & Test
2933
run: |
3034
JEKYLL_ENV=test bundle exec jekyll build
@@ -49,8 +53,6 @@ jobs:
4953

5054
- name: 🧪 Install gems
5155
run: |
52-
bundle config set with 'test'
53-
bundle config set path 'vendor/bundle'
5456
bundle install
5557
5658
- name: 🔧 Build

_data/stats.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
active_dojos: 180

index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ <h3 class="headline rich_font" style='margin-top: 70px;'>DojoCon Japan とは?
192192

193193
<h3 class="headline rich_font" style='margin-top: 70px;'>CoderDojo とは?</h3>
194194
<div class="desc">
195-
<p>CoderDojo は7〜17歳を対象とした非営利のプログラミング道場です。2011年にアイルランドで始まり、世界では100カ国・2,000の道場、<a href='https://coderdojo.jp/'>日本には180以上の道場</a>があります。</p>
195+
<p>CoderDojo は7〜17歳を対象とした非営利のプログラミング道場です。2011年にアイルランドで始まり、世界では100カ国・2,000の道場、<a href='https://coderdojo.jp/'>日本には{{ site.data.stats['active_dojos'] }}以上の道場</a>があります。</p>
196196
</div>
197197
</div>
198198
</div>

update_profile.rb

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env ruby
2+
3+
require 'net/http'
4+
require 'json'
5+
require 'yaml'
6+
7+
BASE_URL = 'https://coderdojo.jp'
8+
DOJO_STATS = JSON.parse Net::HTTP.get(URI.parse "#{BASE_URL}/stats.json"), symbolize_names: true
9+
STATS_PATH = '_data/stats.yml'
10+
11+
stats = YAML.load_file(STATS_PATH)
12+
stats['active_dojos'] = DOJO_STATS[:active_dojos]
13+
YAML.dump stats, File.open(STATS_PATH, 'w')

0 commit comments

Comments
 (0)