Skip to content

Commit 0f2efae

Browse files
committed
allow manual CD triggering
1 parent 53af0e8 commit 0f2efae

File tree

1 file changed

+181
-180
lines changed

1 file changed

+181
-180
lines changed

.github/workflows/cd.yml

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

0 commit comments

Comments
 (0)