Skip to content

Commit

Permalink
Automated update on GitHub Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
rosylilly committed Jan 15, 2025
1 parent 328de1e commit 9e20c62
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 28 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: update

on:
push:

schedule:
# Run at 11:30 JST
- cron: '30 2 * * *'

jobs:
update:
runs-on: ubuntu-latest

permissions:
contents: write

steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true

- name: Restore cache of data
uses: actions/cache@v4
with:
path: cache
key: cache-${{ runner.os }}-${{ hashFiles('data/md5') }}

- name: Download or Restore archive
run: |
if [ -f cache/src.zip ]; then mv cache/src.zip data/src.zip; fi
./bin/zengin download || true
mkdir -p cache
cp data/src.zip cache/src.zip
- name: Update archive
run: ./bin/zengin update

- name: Commit
run: ./bin/zengin commit
# run on master branch only
if: github.ref == 'refs/heads/master'
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ gem 'rubyzip'
gem 'thor'
gem 'ruby-progressbar'
gem 'oj'
gem 'circleci'
gem 'csv'
gem 'nkf'
22 changes: 14 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
GEM
remote: https://rubygems.org/
specs:
circleci (2.0.3)
bigdecimal (3.1.9)
csv (3.3.2)
moji (1.6)
oj (3.10.1)
rake (13.0.1)
nkf (0.2.0)
oj (3.16.9)
bigdecimal (>= 3.0)
ostruct (>= 0.2)
ostruct (0.6.1)
rake (13.2.1)
romaji (0.2.4)
rake (>= 0.8.0)
ruby-progressbar (1.10.1)
rubyzip (2.1.0)
thor (1.0.1)
ruby-progressbar (1.13.0)
rubyzip (2.4.1)
thor (1.3.2)

PLATFORMS
ruby

DEPENDENCIES
circleci
csv
moji
nkf
oj
romaji
ruby-progressbar
rubyzip
thor

BUNDLED WITH
2.1.4
2.6.2
24 changes: 5 additions & 19 deletions bin/zengin
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ require 'moji'
require 'romaji'
require 'oj'
require 'yaml'
require 'circleci'

CircleCi.configure do |config|
config.token = ENV['ZENGINCI_TOKEN']
end

class ZenginCLI < Thor
include Thor::Invocation
Expand Down Expand Up @@ -87,27 +82,23 @@ class ZenginCLI < Thor
end
end

desc 'ci', 'ci job'
def ci
desc 'commit', 'commit changes'
def commit
now = Time.now
puts "Check and commit updates..."

inside(ROOT_DIR) do
run('git config user.email "[email protected]"')
run('git config user.name "zeny-man"')
run('git config user.name "github-actions[bot]"')
run('git config user.email "41898282+github-actions[bot]@users.noreply.github.com"')

run('git add data')
changed = run(%Q{git commit -m "Update: #{now.strftime('%Y / %m / %d')}"})
if changed
run(%Q{git tag -f #{now.strftime('%Y-%m-%d')}})

remote = "[email protected]:#{ENV['CIRCLE_PROJECT_USERNAME']}/#{ENV['CIRCLE_PROJECT_REPONAME']}.git"
remote = "[email protected]:zengin-code/source-data.git"
run("git push #{remote} master")
run("git push -f --tags #{remote}")

trigger_build('zengin-rb')
trigger_build('zengin-js')
trigger_build('zengin-py')
end
end
end
Expand Down Expand Up @@ -172,11 +163,6 @@ class ZenginCLI < Thor
end
strigified
end

def trigger_build(project)
ci = CircleCi::Project.new('zengin-code', project)
ci.build_branch('master', {}, build_parameters: { 'RELEASE_BUILD' => 'TRUE' })
end
end

ZenginCLI.start(ARGV)

0 comments on commit 9e20c62

Please sign in to comment.