diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml index 353205cd..919909da 100644 --- a/.github/workflows/update.yml +++ b/.github/workflows/update.yml @@ -42,8 +42,9 @@ jobs: git config --global init.defaultBranch main git config --global extensions.partialClone true bundle exec ruby update.rb ./website ~/.cache releases + id: update_releases - uses: stefanzweifel/git-auto-commit-action@v4 name: Commit and update new releases with: - commit_message: Update Releases + commit_message: ${{ fromJSON(steps.update_releases.outputs.commit_message)}} commit_author: 'github-actions[bot] ' diff --git a/update.rb b/update.rb index 1e76d335..eac44141 100644 --- a/update.rb +++ b/update.rb @@ -1,4 +1,5 @@ require 'yaml' +require 'set' require 'date' require 'json' require 'rugged' @@ -68,6 +69,26 @@ def get_output_file(ecosystem, product) "#{OUTPUT_DIR}/#{ecosystem}/#{product}.json" end +def generate_commit_message + products = Set.new + ret = nil + msg = "" + r = Rugged::Repository.new '.' + r.status() do |f, s| + p = Pathname.new(f).dirname + if p.to_s === 'releases/git' + ret = true + product = File.basename(f, '.json') + products << product + old_version_list = JSON.parse(r.blob_at(r.head.target.oid, f).content).keys.to_set + new_version_list = JSON.parse(File.read(f)).keys.to_set + new_versions = (new_version_list - old_version_list) + msg += "#{product}: #{new_versions.join(', ')}" + end + end + ret ? "Updates: #{products.join(', ')}\n\n#{msg}": false +end + Dir.glob("#{WEBSITE_DIR}/products/*.md").each do |product_file| data = YAML.safe_load_file product_file, permitted_classes: [Date] next unless data['auto'] @@ -81,3 +102,10 @@ Dir.glob("#{WEBSITE_DIR}/products/*.md").each do |product_file| update_git_releases(get_cache_dir('git', product), get_output_file('git', product), data['auto']) end end + +def github_actions_step_output(msg) + puts "::set-output name=commit_message::#{JSON.dump(msg)}" +end + +msg = generate_commit_message +github_actions_step_output(msg) if msg