11---
2- name : CD
3-
4- on :
5- workflow_dispatch :
6- push :
7- tags : ["v*"]
8-
9- concurrency :
10- group : ${{ github.workflow }}-${{ github.ref }}
11- cancel-in-progress : true
12-
13- jobs :
14- ci-data :
15- runs-on : ubuntu-latest
16- outputs :
17- result : ${{ steps.fetch.outputs.result }}
18- steps :
19- - id : fetch
20- uses : oxidize-rb/actions/fetch-ci-data@v1
21- with :
22- supported-ruby-platforms : |
23- # Excluding:
24- # `arm-linux`: Cranelift doesn't support 32-bit architectures
25- # `x64-mingw32`: `x64-mingw-ucrt` should be used for Ruby 3.1+ (https://github.com/rake-compiler/rake-compiler-dock?tab=readme-ov-file#windows)
26- # 3.0 is deprecated as stable ruby version according to:
27- # https://github.com/oxidize-rb/actions/blob/main/fetch-ci-data/evaluate.rb#L54
28- exclude: [arm-linux, x64-mingw32]
29- stable-ruby-versions : |
30- exclude: [head]
31-
32- build :
33- name : Build native gems
34- needs : ci-data
35- runs-on : ubuntu-latest
36- strategy :
37- fail-fast : false
38- matrix :
39- ruby-platform : ${{ fromJSON(needs.ci-data.outputs.result).supported-ruby-platforms }}
40- steps :
41- - uses : actions/checkout@v4
42-
43- - uses : ruby/setup-ruby@v1
44- with :
45- ruby-version : " 3.4"
46-
47- - uses : oxidize-rb/actions/cross-gem@v1
48- id : cross-gem
49- with :
50- platform : ${{ matrix.ruby-platform }}
51- ruby-versions : ${{ join(fromJSON(needs.ci-data.outputs.result).stable-ruby-versions, ',') }}
52-
53- - uses : actions/upload-artifact@v4
54- with :
55- name : cross-gem-${{ matrix.ruby-platform }}
56- path : pkg/*-${{ matrix.ruby-platform }}.gem
57- if-no-files-found : error
58-
59- - name : Smoke gem install
60- if : matrix.ruby-platform == 'ignore-for-now-x86_64-linux' # GitHub actions architecture
61- run : |
62- gem install pkg/fast_code_owners-*.gem --verbose
63- script="puts FastCodeOwners::VERSION"
64- ruby -rfast_code_owners -e "$script" | grep 0.1.0
65- echo "✅ Successfully gem installed"
66-
67- release :
68- name : Release
69- needs : build
70- runs-on : ubuntu-latest
71- steps :
72- - uses : actions/checkout@v4
73-
74- - uses : oxidize-rb/actions/setup-ruby-and-rust@v1
75- with :
76- ruby-version : " 3.4"
77- bundler-cache : true
78- cargo-cache : true
79- cache-version : v1
80-
81- - uses : actions/download-artifact@v4
82- with :
83- pattern : cross-gem-*
84- merge-multiple : true
85- path : pkg/
86-
87- - name : Package source gem
88- run : bundle exec rake pkg:ruby
89-
90- - name : Ensure version matches the tag
91- run : |
92- GEM_VERSION=$(grep -Eo "[0-9]+\.[0-9]+\.[0-9]+[-0-9]*" lib/code_ownership/version.rb | head -n 1)
93- if [ "v$GEM_VERSION" != "${{ github.ref_name }}" ]; then
94- echo "Gem version does not match tag"
95- echo " v$GEM_VERSION != ${{ github.ref_name }}"
96- exit 1
97- fi
98-
99- - name : Push Gem
100- working-directory : pkg/
101- env :
102- GEM_HOST_API_KEY : ${{ secrets.RUBYGEMS_API_KEY }}
103- run : |
104- mkdir -p $HOME/.gem
105- touch $HOME/.gem/credentials
106- chmod 0600 $HOME/.gem/credentials
107- printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
108- ls -l
109- for i in *.gem; do
110- if [ -f "$i" ]; then
111- if ! gem push "$i" >push.out; then
112- gemerr=$?
113- sed 's/^/::error:: /' push.out
114- if ! grep -q "Repushing of gem" push.out; then
115- exit $gemerr
116- fi
2+ name : CD
3+
4+ on :
5+ workflow_call :
6+
7+ concurrency :
8+ group : ${{ github.workflow }}-${{ github.ref }}
9+ cancel-in-progress : true
10+
11+ jobs :
12+ ci-data :
13+ runs-on : ubuntu-latest
14+ outputs :
15+ result : ${{ steps.fetch.outputs.result }}
16+ steps :
17+ - id : fetch
18+ uses : oxidize-rb/actions/fetch-ci-data@v1
19+ with :
20+ supported-ruby-platforms : |
21+ # Excluding:
22+ # `arm-linux`: Cranelift doesn't support 32-bit architectures
23+ # `x64-mingw32`: `x64-mingw-ucrt` should be used for Ruby 3.1+ (https://github.com/rake-compiler/rake-compiler-dock?tab=readme-ov-file#windows)
24+ # `x64-mingw-ucrt`: Rust target not available in rake-compiler-dock
25+ # `aarch64-linux-musl`: Rust target not available in rake-compiler-dock
26+ # 3.0 is deprecated as stable ruby version according to:
27+ # https://github.com/oxidize-rb/actions/blob/main/fetch-ci-data/evaluate.rb#L54
28+ exclude: [arm-linux, x64-mingw32, x64-mingw-ucrt, aarch64-linux-musl]
29+ stable-ruby-versions : |
30+ exclude: [head]
31+
32+ build :
33+ name : Build native gems
34+ needs : ci-data
35+ runs-on : ubuntu-latest
36+ strategy :
37+ fail-fast : false
38+ matrix :
39+ ruby-platform : ${{ fromJSON(needs.ci-data.outputs.result).supported-ruby-platforms }}
40+ steps :
41+ - uses : actions/checkout@v4
42+
43+ - uses : ruby/setup-ruby@v1
44+ with :
45+ ruby-version : " 3.4"
46+
47+ - uses : oxidize-rb/actions/cross-gem@v1
48+ id : cross-gem
49+ with :
50+ platform : ${{ matrix.ruby-platform }}
51+ ruby-versions : ${{ join(fromJSON(needs.ci-data.outputs.result).stable-ruby-versions, ',') }}
52+ cache-save-always : false
53+ cargo-cache-clean : false # Add this to disable cargo-cache usage
54+ env :
55+ # Add a unique identifier to prevent cache conflicts
56+ ACTIONS_CACHE_KEY_SUFFIX : " -${{ matrix.ruby-platform }}-${{ github.run_id }}"
57+
58+ - uses : actions/upload-artifact@v4
59+ with :
60+ name : cross-gem-${{ matrix.ruby-platform }}
61+ path : pkg/*-${{ matrix.ruby-platform }}.gem
62+ if-no-files-found : error
63+ retention-days : 30 # Keep artifacts for 30 days
64+
65+ - name : Smoke test gem install
66+ if : matrix.ruby-platform == 'x86_64-linux' # Enable for Linux x64
67+ run : |
68+ # Install the platform-specific gem
69+ gem install pkg/code_ownership-*-${{ matrix.ruby-platform }}.gem --verbose
70+
71+ # Test that it works
72+ ruby -e "require 'code_ownership'; puts 'Version: ' + CodeOwnership::VERSION"
73+
74+ # Run a simple functionality test
75+ ruby -e "require 'code_ownership'; CodeOwnership.file_owner_team_names('lib/code_ownership.rb')" || true
76+
77+ echo "✅ Successfully tested ${{ matrix.ruby-platform }} gem"
78+
79+ release :
80+ name : Release
81+ needs : build
82+ runs-on : ubuntu-latest
83+ permissions :
84+ contents : write # Required for creating releases
85+ steps :
86+ - uses : actions/checkout@v4
87+
88+ - uses : oxidize-rb/actions/setup-ruby-and-rust@v1
89+ with :
90+ ruby-version : " 3.4"
91+ bundler-cache : true
92+ cargo-cache : false
93+
94+ - uses : actions/download-artifact@v4
95+ with :
96+ pattern : cross-gem-*
97+ merge-multiple : true
98+ path : pkg/
99+
100+ - name : Package source gem
101+ run : bundle exec rake pkg:ruby
102+
103+ - name : Push Gem
104+ id : push-gem
105+ working-directory : pkg/
106+ env :
107+ GEM_HOST_API_KEY : ${{ secrets.RUBYGEMS_API_KEY }}
108+ run : |
109+ set -e # Exit on error
110+
111+ # Setup credentials
112+ mkdir -p $HOME/.gem
113+ touch $HOME/.gem/credentials
114+ chmod 0600 $HOME/.gem/credentials
115+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
116+
117+ # List all gems to be pushed
118+ echo "📦 Gems to be pushed:"
119+ ls -la *.gem
120+
121+ # Extract version from the Ruby version file
122+ GEM_VERSION=$(ruby -r ../lib/code_ownership/version.rb -e "puts CodeOwnership::VERSION")
123+ echo "gem_version=${GEM_VERSION}" >> $GITHUB_OUTPUT
124+ echo "🏷️ Detected gem version: ${GEM_VERSION}"
125+
126+ # Track results
127+ NEW_VERSION=false
128+ PUSHED_GEMS=()
129+ SKIPPED_GEMS=()
130+
131+ for i in *.gem; do
132+ if [ -f "$i" ]; then
133+ echo "⏳ Attempting to push $i..."
134+ if ! gem push "$i" >push.out 2>&1; then
135+ gemerr=$?
136+ if grep -q "Repushing of gem" push.out; then
137+ echo "⏭️ Gem $i already exists on RubyGems, skipping..."
138+ SKIPPED_GEMS+=("$i")
139+ else
140+ echo "❌ Failed to push $i:"
141+ cat push.out
142+ exit $gemerr
117143 fi
144+ else
145+ echo "✅ Successfully pushed $i"
146+ PUSHED_GEMS+=("$i")
147+ NEW_VERSION=true
118148 fi
119- done
120-
121- - name : Create GitHub release
122- uses : ncipollo/release-action@v1
123- with :
124- allowUpdates : true
125- generateReleaseNotes : true
126- draft : true
127- omitBodyDuringUpdate : true
128- omitNameDuringUpdate : true
129- omitPrereleaseDuringUpdate : true
130- skipIfReleaseExists : true
149+ fi
150+ done
151+
152+ # Summary
153+ echo "📊 Push Summary:"
154+ echo " - Pushed: ${#PUSHED_GEMS[@]} gems"
155+ echo " - Skipped: ${#SKIPPED_GEMS[@]} gems"
156+
157+ # Set outputs
158+ echo "new_version=${NEW_VERSION}" >> $GITHUB_OUTPUT
159+ echo "pushed_count=${#PUSHED_GEMS[@]}" >> $GITHUB_OUTPUT
160+ echo "skipped_count=${#SKIPPED_GEMS[@]}" >> $GITHUB_OUTPUT
161+
162+ - name : Create GitHub Release
163+ if : ${{ steps.push-gem.outputs.new_version == 'true' }}
164+ env :
165+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
166+ run : |
167+ # Create release with more detailed information
168+ RELEASE_NOTES="## CodeOwnership v${{ steps.push-gem.outputs.gem_version }}
169+
170+ ### 📦 Published Gems
171+ - Source gem: code_ownership-${{ steps.push-gem.outputs.gem_version }}.gem
172+ - Platform gems: Published for all supported platforms
173+
174+ ### 🎯 Supported Platforms
175+ $(ls pkg/*.gem | grep -E '\-(x86|arm|aarch)' | sed 's/.*-\([^-]*\)\.gem/- \1/')
176+
177+ ---
178+ "
179+
180+ gh release create "v${{ steps.push-gem.outputs.gem_version }}" \
181+ --title "v${{ steps.push-gem.outputs.gem_version }}" \
182+ --notes "$RELEASE_NOTES" \
183+ --generate-notes \
184+ pkg/*.gem
0 commit comments