From 0cbf22bf9fe8174da1e811a612bfbff9d6ca8932 Mon Sep 17 00:00:00 2001 From: Nemo Date: Fri, 25 Mar 2022 15:19:24 +0530 Subject: [PATCH] Initial Automation --- .bundle/config | 4 ++++ .github/workflows/update.yml | 19 ++++++++++++++++--- .gitignore | 1 + Gemfile | 7 +++++++ Gemfile.lock | 13 +++++++++++++ update.rb | 34 ++++++++++++++++++++++++++++------ 6 files changed, 69 insertions(+), 9 deletions(-) create mode 100644 .bundle/config create mode 100644 Gemfile create mode 100644 Gemfile.lock diff --git a/.bundle/config b/.bundle/config new file mode 100644 index 00000000..c59e5395 --- /dev/null +++ b/.bundle/config @@ -0,0 +1,4 @@ +--- +BUNDLE_PATH: "/home/runner/work/release-data/release-data/vendor/bundle" +BUNDLE_DEPLOYMENT: "true" +BUNDLE_JOBS: "4" diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml index 0b7f45ff..78b7d8e9 100644 --- a/.github/workflows/update.yml +++ b/.github/workflows/update.yml @@ -10,11 +10,18 @@ jobs: name: Update data runs-on: ubuntu-latest steps: + - name: Get current week + uses: josStorer/get-current-time@v2 + id: current-time + with: + # 2022-01 to 2022-52 for eg + format: YYYY-ww - name: Cache Repositories uses: actions/cache@v3 with: path: ~/.cache - key: cache + # The cache is reset on the first build of every week this way. + key: "${{ steps.current-time.outputs.formattedTime }}" - uses: actions/checkout@v3 name: Clone self repository with: @@ -25,10 +32,16 @@ jobs: repository: endoflife-date/endoflife.date path: website submodules: false + - uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.1 + bundler-cache: true - name: Update Release data run: | - mkdir -p ~/.cache/{npm,git,oci} releases/{npm,git,oci} - ruby update.rb website ~/.cache releases + mkdir -p ~/.cache/{npm,git,oci} releases/{npm,git,oci} && \ + git config --global init.defaultBranch main + git config --global extensions.partialClone true + bundle exec ruby update.rb ./website ~/.cache releases - uses: stefanzweifel/git-auto-commit-action@v4 name: Commit and update new releases with: diff --git a/.gitignore b/.gitignore index 0154e4c9..d5bcbb2d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ website +vendor diff --git a/Gemfile b/Gemfile new file mode 100644 index 00000000..ef84856e --- /dev/null +++ b/Gemfile @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +# gem "rails" + +gem "rugged", "~> 1.4" diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 00000000..20c3ff29 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,13 @@ +GEM + remote: https://rubygems.org/ + specs: + rugged (1.4.2) + +PLATFORMS + x86_64-linux + +DEPENDENCIES + rugged (~> 1.4) + +BUNDLED WITH + 2.3.5 diff --git a/update.rb b/update.rb index ddad531d..0e004696 100644 --- a/update.rb +++ b/update.rb @@ -1,30 +1,52 @@ require 'yaml' require 'date' +require 'json' +require 'rugged' WEBSITE_DIR=ARGV[0] CACHE_DIR=ARGV[1] OUTPUT_DIR=ARGV[2] -def update_git_releases(product, url) +def fetch_git_releases(repo_dir, url) pwd = Dir.pwd - repo_dir = "#{CACHE_DIR}/git/#{product}" puts "Fetching #{url}" unless Dir.exist? repo_dir `git init --bare #{repo_dir}` end Dir.chdir repo_dir - `git config extensions.partialClone true` - `git fetch --auto-gc --auto-maintenance --progress --prune --prune-tags --quiet --tags --filter=blob:none "#{url}"` + `git fetch --quiet --tags --filter=blob:none "#{url}"` Dir.chdir pwd end -Dir.glob("#{WEBSITE_DIR}products/*.md").each do |product_file| +def update_git_releases(repo_dir, output_file) + data = {} + repo = Rugged::Repository.bare repo_dir + repo.tags.each do |tag| + if tag.target.is_a? Rugged::Tag::Annotation + data[tag.name] = tag.target.tagger[:time].strftime('%F') + else + begin + data[tag.name] = tag.target.time.strftime('%F') + rescue + puts "[WARN] No timestamp for #{tag.name}" + end + end + end + File.open(output_file, 'w') do |file| + file.write(JSON.pretty_generate data) + end +end + +Dir.glob("#{WEBSITE_DIR}/products/*.md").each do |product_file| data = YAML.load_file product_file, permitted_classes: [Date] data['auto'].each_entry do |ecosystem, url| product = File.basename product_file, ".md" + cache_dir = "#{CACHE_DIR}/#{ecosystem}/#{product}" + output_file = "#{OUTPUT_DIR}/#{ecosystem}/#{product}.json" case ecosystem when 'git' - update_git_releases(product, url) + fetch_git_releases(cache_dir, url) + update_git_releases(cache_dir, output_file) else puts "No support for #{ecosystem} yet (#{url})" end