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