Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
308 changes: 181 additions & 127 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -1,130 +1,184 @@
---
name: CD

on:
workflow_dispatch:
push:
tags: ["v*"]

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)
# 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]
stable-ruby-versions: |
exclude: [head]

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: "3.4"

- 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, ',') }}

- uses: actions/upload-artifact@v4
with:
name: cross-gem-${{ matrix.ruby-platform }}
path: pkg/*-${{ matrix.ruby-platform }}.gem
if-no-files-found: error

- name: Smoke gem install
if: matrix.ruby-platform == 'ignore-for-now-x86_64-linux' # GitHub actions architecture
run: |
gem install pkg/fast_code_owners-*.gem --verbose
script="puts FastCodeOwners::VERSION"
ruby -rfast_code_owners -e "$script" | grep 0.1.0
echo "✅ Successfully gem installed"

release:
name: Release
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: oxidize-rb/actions/setup-ruby-and-rust@v1
with:
ruby-version: "3.4"
bundler-cache: true
cargo-cache: true
cache-version: v1

- 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: Ensure version matches the tag
run: |
GEM_VERSION=$(grep -Eo "[0-9]+\.[0-9]+\.[0-9]+[-0-9]*" lib/code_ownership/version.rb | head -n 1)
if [ "v$GEM_VERSION" != "${{ github.ref_name }}" ]; then
echo "Gem version does not match tag"
echo " v$GEM_VERSION != ${{ github.ref_name }}"
exit 1
fi

- name: Push Gem
working-directory: pkg/
env:
GEM_HOST_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
run: |
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
ls -l
for i in *.gem; do
if [ -f "$i" ]; then
if ! gem push "$i" >push.out; then
gemerr=$?
sed 's/^/::error:: /' push.out
if ! grep -q "Repushing of gem" push.out; then
exit $gemerr
fi
name: CD

on:
workflow_call:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manual kickoff (for now).


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: |
exclude: [head]

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: "3.4"

- 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'; CodeOwnership.file_owner_team_names('lib/code_ownership.rb')" || true

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: "3.4"
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
done

- name: Create GitHub release
uses: ncipollo/release-action@v1
with:
allowUpdates: true
generateReleaseNotes: true
draft: true
omitBodyDuringUpdate: true
omitNameDuringUpdate: true
omitPrereleaseDuringUpdate: true
skipIfReleaseExists: true
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
47 changes: 23 additions & 24 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,30 @@ jobs:
uses: oxidize-rb/actions/fetch-ci-data@v1
with:
stable-ruby-versions: |
# See https://github.com/bytecodealliance/wasmtime-rb/issues/286
# for details.
exclude: [head]
# See https://github.com/bytecodealliance/wasmtime-rb/issues/286
# for details.
exclude: [head]
rspec:
runs-on: ${{ matrix.os }}
needs: ci-data
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest", "macos-latest"]
ruby: ${{ fromJSON(needs.ci-data.outputs.result).stable-ruby-versions }}
steps:
- uses: actions/checkout@v4
- uses: oxidize-rb/actions/setup-ruby-and-rust@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
cargo-cache: true
cache-version: v5

- name: Compile rust ext
run: bundle exec rake compile:release

- name: Run ruby tests
run: bundle exec rake spec
runs-on: ${{ matrix.os }}
needs: ci-data
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest", "macos-latest"]
ruby: ${{ fromJSON(needs.ci-data.outputs.result).stable-ruby-versions }}
rust: ["stable"]
steps:
- uses: actions/checkout@v4
- uses: oxidize-rb/actions/setup-ruby-and-rust@v1
with:
ruby-version: ${{ matrix.ruby }}
rustup-toolchain: ${{ matrix.rust }}
bundler-cache: true
cargo-cache: false
- name: Run ruby tests
run: bundle exec rake
- name: Compile rust ext
run: bundle exec rake compile:release
static_type_check:
name: "Type Check"
runs-on: ubuntu-latest
Expand Down
Loading
Loading