11name : bundled_gems
22
33on :
4+ push :
5+ paths :
6+ - ' .github/workflows/bundled_gems.yml'
7+ - ' gems/bundled_gems'
8+ pull_request :
9+ paths :
10+ - ' .github/workflows/bundled_gems.yml'
11+ - ' gems/bundled_gems'
412 schedule :
513 - cron : ' 45 6 * * *'
614
715jobs :
816 update :
9- if : ${{ github.repository == 'ruby/ruby' }}
17+ if : ${{ github.event_name != 'schedule' || github. repository == 'ruby/ruby' }}
1018 name : update ${{ github.workflow }}
1119 runs-on : ubuntu-latest
1220 steps :
@@ -18,17 +26,62 @@ jobs:
1826 - name : Set ENV
1927 run : |
2028 echo "GNUMAKEFLAGS=-j$((1 + $(nproc --all)))" >> $GITHUB_ENV
29+ echo "TODAY=$(date +%F)" >> $GITHUB_ENV
2130
2231 - uses : actions/checkout@v2
2332
24- - name : Update ${{ github.workflow }}
33+ - uses : actions/cache@v2
34+ with :
35+ path : .downloaded-cache
36+ key : downloaded-cache-${{ github.sha }}
37+ restore-keys : |
38+ downloaded-cache
39+
40+ - name : Download previous gems list
41+ run : |
42+ data=bundled_gems.json
43+ mkdir -p .downloaded-cache
44+ ln -s .downloaded-cache/$data .
45+ curl -O -R -z ./$data https://stdgems.org/$data
46+
47+ - name : Update bundled gems list
48+ run : |
49+ ruby -i~ tool/update-bundled_gems.rb gems/bundled_gems
50+
51+ - name : Maintain updated gems list in NEWS
2552 run : |
26- ruby -i~ tool/update-bundled_gems.rb gems/${{ github.workflow }}
53+ require 'json'
54+ news = File.read("NEWS.md")
55+ prev = news[/since the \*+(\d+\.\d+\.\d+)\*+/, 1]
56+ prevs = [prev, prev.sub(/\.\d+\z/, '')]
57+ %W[bundled].each do |type|
58+ last = JSON.parse(File.read("#{type}_gems.json"))['gems'].filter_map do |g|
59+ v = g['versions'].values_at(*prevs).compact.first
60+ g = g['gem']
61+ g = 'RubyGems' if g == 'rubygems'
62+ [g, v] if v
63+ end.to_h
64+ changed = File.foreach("gems/#{type}_gems").filter_map do |l|
65+ next if l.start_with?("#")
66+ g, v = l.split(" ", 3)
67+ [g, v] unless last[g] == v
68+ end
69+ changed, added = changed.partition {|g, _| last[g]}
70+ news.sub!(/^\*\s+The following #{type} gems? are updated\.(\n\s+\*\s+)\K.*(?:\1.*)*/) do
71+ changed.map {|g, v|"#{g} #{v}"}.join($1)
72+ end or exit
73+ news.sub!(/^\*\s+The following default gems are now bundled.*(\n\s+\*\s+)\K.*(?:\1.*)*/) do
74+ added.map {|g, v|"#{g} #{v}"}.join($1)
75+ end if added
76+ File.write("NEWS.md", news)
77+ end
78+ shell : ruby {0}
2779
2880 - name : Check diffs
2981 id : diff
3082 run : |
31- git diff --no-ext-diff --ignore-submodules --exit-code
83+ git add -- NEWS.md
84+ git diff --no-ext-diff --ignore-submodules --quiet -- gems/bundled_gems
3285 continue-on-error : true
3386
3487 - name : Install libraries
3891 sudo apt-get install --no-install-recommends -q -y build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev bison autoconf ruby
3992 if : ${{ steps.diff.outcome == 'failure' }}
4093
41- - uses : actions/cache@v2
42- with :
43- path : .downloaded-cache
44- key : downloaded-cache
45-
4694 - name : Build
4795 run : |
4896 ./autogen.sh
@@ -53,19 +101,31 @@ jobs:
53101 - name : Test bundled gems
54102 run : |
55103 make -s test-bundled-gems
104+ git add -- gems/bundled_gems
56105 timeout-minutes : 30
57106 env :
58107 RUBY_TESTOPTS : " -q --tty=no"
59108 TEST_BUNDLED_GEMS_ALLOW_FAILURES : " "
60109 if : ${{ steps.diff.outcome == 'failure' }}
61110
111+ - name : Show diffs
112+ id : show
113+ run : |
114+ git diff --cached --color --no-ext-diff --ignore-submodules --exit-code --
115+ continue-on-error : true
116+
62117 - name : Commit
63118 run : |
64119 git pull --ff-only origin ${GITHUB_REF#refs/heads/}
65- git commit --message="Update ${{ github.workflow }} at $(date +%F)" gems/$file
120+ message="Update bundled gems list at "
121+ if [ ${{ steps.diff.outcome }} = success ]; then
122+ git commit --message="${message}${GITHUB_SHA:0:30} [ci skip]"
123+ else
124+ git commit --message="${message}${TODAY}"
125+ fi
66126 git push origin ${GITHUB_REF#refs/heads/}
67127 env :
6812869129 GIT_AUTHOR_NAME : git
70130 GIT_COMMITTER_NAME : git
71- if : ${{ steps.diff .outcome == 'failure' }}
131+ if : ${{ github.repository == 'ruby/ruby' && !startsWith(github.event_name, 'pull') && steps.show .outcome == 'failure' }}
0 commit comments