From 6b082aac17890c0bff56eee89646c59b53ee3f55 Mon Sep 17 00:00:00 2001 From: Nemo Date: Thu, 24 Mar 2022 15:26:07 +0530 Subject: [PATCH] Initial commit for workflow --- .editorconfig | 13 +++++++++++++ .github/workflows/update.yml | 36 ++++++++++++++++++++++++++++++++++++ update.rb | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 .editorconfig create mode 100644 .github/workflows/update.yml create mode 100644 update.rb diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..19fa9dfa --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ +; This file is for unifying the coding style for different editors and IDEs. +; More information at http://EditorConfig.org + +root = true +; Use 2 spaces for indentation in all files + +[*] +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +indent_style = space +indent_size = 2 +insert_final_newline = true diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml new file mode 100644 index 00000000..0b7f45ff --- /dev/null +++ b/.github/workflows/update.yml @@ -0,0 +1,36 @@ +name: Update Data +on: + push: + schedule: + # “At minute 17 past hour 6 and 18.” + # https://crontab.guru/#17_6,18_*_*_* + - cron: '17 6,18 * * *' +jobs: + update: + name: Update data + runs-on: ubuntu-latest + steps: + - name: Cache Repositories + uses: actions/cache@v3 + with: + path: ~/.cache + key: cache + - uses: actions/checkout@v3 + name: Clone self repository + with: + ref: ${{ github.head_ref }} + - uses: actions/checkout@v3 + name: Clone website + with: + repository: endoflife-date/endoflife.date + path: website + submodules: false + - name: Update Release data + run: | + mkdir -p ~/.cache/{npm,git,oci} releases/{npm,git,oci} + ruby update.rb website ~/.cache releases + - uses: stefanzweifel/git-auto-commit-action@v4 + name: Commit and update new releases + with: + commit_message: Update Releases + commit_author: actions-user <65916846+actions-user@users.noreply.github.com> diff --git a/update.rb b/update.rb new file mode 100644 index 00000000..ddad531d --- /dev/null +++ b/update.rb @@ -0,0 +1,32 @@ +require 'yaml' +require 'date' + +WEBSITE_DIR=ARGV[0] +CACHE_DIR=ARGV[1] +OUTPUT_DIR=ARGV[2] + +def update_git_releases(product, 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}"` + Dir.chdir pwd +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" + case ecosystem + when 'git' + update_git_releases(product, url) + else + puts "No support for #{ecosystem} yet (#{url})" + end + end if data['auto'] +end