From 9e20c627c9c21d00c6b4b2d354f2b3cb066075fd Mon Sep 17 00:00:00 2001 From: Sho KUSANO Date: Wed, 15 Jan 2025 18:38:26 +0900 Subject: [PATCH 1/3] Automated update on GitHub Actions --- .github/workflows/update.yml | 42 ++++++++++++++++++++++++++++++++++++ Gemfile | 3 ++- Gemfile.lock | 22 ++++++++++++------- bin/zengin | 24 +++++---------------- 4 files changed, 63 insertions(+), 28 deletions(-) create mode 100644 .github/workflows/update.yml diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml new file mode 100644 index 00000000..f99efdcf --- /dev/null +++ b/.github/workflows/update.yml @@ -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' \ No newline at end of file diff --git a/Gemfile b/Gemfile index 8aa15d46..3a1d457e 100644 --- a/Gemfile +++ b/Gemfile @@ -6,4 +6,5 @@ gem 'rubyzip' gem 'thor' gem 'ruby-progressbar' gem 'oj' -gem 'circleci' +gem 'csv' +gem 'nkf' \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index 4805894a..933d3b8c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,22 +1,28 @@ 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 @@ -24,4 +30,4 @@ DEPENDENCIES thor BUNDLED WITH - 2.1.4 + 2.6.2 diff --git a/bin/zengin b/bin/zengin index b3c7c05c..706f118d 100755 --- a/bin/zengin +++ b/bin/zengin @@ -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 @@ -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 "zeny-man@zeny.io"') - 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 = "git@github.com:#{ENV['CIRCLE_PROJECT_USERNAME']}/#{ENV['CIRCLE_PROJECT_REPONAME']}.git" + remote = "git@github.com: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 @@ -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) From e5ea74e29c293d149b2efcf5d56846e230140dd7 Mon Sep 17 00:00:00 2001 From: Sho KUSANO Date: Wed, 15 Jan 2025 18:41:03 +0900 Subject: [PATCH 2/3] Fix errors --- .github/workflows/update.yml | 1 + bin/zengin | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml index f99efdcf..fc77c3f4 100644 --- a/.github/workflows/update.yml +++ b/.github/workflows/update.yml @@ -18,6 +18,7 @@ jobs: - uses: actions/checkout@v4 - uses: ruby/setup-ruby@v1 with: + ruby-version: 3.3 bundler-cache: true - name: Restore cache of data diff --git a/bin/zengin b/bin/zengin index 706f118d..89341413 100755 --- a/bin/zengin +++ b/bin/zengin @@ -15,6 +15,7 @@ require 'moji' require 'romaji' require 'oj' require 'yaml' +require 'digest/md5' class ZenginCLI < Thor include Thor::Invocation From 3b51b94efe358cf8674856e9e360e9c7c4df8f75 Mon Sep 17 00:00:00 2001 From: Sho KUSANO Date: Wed, 15 Jan 2025 18:42:20 +0900 Subject: [PATCH 3/3] Remove circleci config --- .circleci/config.yml | 44 -------------------------------------------- README.md | 2 +- bin/zengin | 2 +- 3 files changed, 2 insertions(+), 46 deletions(-) delete mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 045bb5f1..00000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,44 +0,0 @@ -version: 2 - -jobs: - build: - working_directory: ~/source-data - docker: - - image: circleci/ruby:latest - steps: - - checkout - - restore_cache: - keys: - - v1-bundle-{{ .Branch }}-{{ checksum "Gemfile.lock" }} - - v1-bundle-{{ .Branch }}- - - restore_cache: - keys: - - v1-cache - - run: - name: Dependency - command: | - gem install --no-document bundler - bundle install --jobs=8 --deployment --path=vendor - - save_cache: - key: v1-bundle-{{ .Branch }}-{{ checksum "Gemfile.lock" }} - paths: - - ~/source-data/.bundle - - ~/source-data/vendor/bundle - - run: - name: Restore cache of archive - command: | - if [ -f cache/src.zip ]; then mv cache/src.zip data/src.zip; fi - ./bin/zengin download - mkdir -p cache - cp data/src.zip cache/src.zip - - save_cache: - key: v1-cache - paths: - - ~/source-data/cache - - run: - name: Update archive - command: ./bin/zengin update - - run: - name: Deployment - command: | - if [ "${CIRCLE_BRANCH}" = "master" ]; then ./bin/zengin ci; fi diff --git a/README.md b/README.md index 6900d4c6..c5366077 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # ZenginCode source data -[![Circle CI](https://img.shields.io/circleci/project/zengin-code/source-data.svg)](https://circleci.com/gh/zengin-code/source-data) +[![update](https://github.com/zengin-code/source-data/actions/workflows/update.yml/badge.svg)](https://github.com/zengin-code/source-data/actions/workflows/update.yml) Bank codes and Branch codes for Japanese. diff --git a/bin/zengin b/bin/zengin index 89341413..4338c979 100755 --- a/bin/zengin +++ b/bin/zengin @@ -44,7 +44,7 @@ class ZenginCLI < Thor md5_path = File.join(ROOT_DIR, 'data/md5') src = File.read(csv) - old_md5 = File.exists?(md5_path) ? File.read(md5_path).strip : '' + old_md5 = File.exist?(md5_path) ? File.read(md5_path).strip : '' now_md5 = Digest::MD5.hexdigest(src) if old_md5 != now_md5