Skip to content

Ruby Gem

Ruby Gem #1325

Workflow file for this run

name: Ruby Gem
on:
push:
pull_request:
schedule:
# * is a special character in YAML so you have to quote this string, runs once a week o Sunday at 04:00 UTC
- cron: '0 4 * * 0'
jobs:
test:
name: Test
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
# Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
# ruby: ['2.6', '3.1', '3.3', '3.4', head, jruby-9.3.15, jruby, jruby-head, truffleruby, truffleruby-head]
# truffleruby, truffleruby-head fully excluded because of incompatibility with most current bundler releases
# jruby-9.4.12.0 is used to run test with Java 8
ruby: ['2.6', '2.7', '3.1', '3.2', '3.4', head, jruby-9.4.12.0, jruby, jruby-head]
exclude:
# Exclude combinations of os and version
- os: windows-latest
ruby: truffleruby
- os: windows-latest
ruby: truffleruby-head
runs-on: ${{ matrix.os }}
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v5
- name: Set up JDK 21 if jruby-head or jruby is used which is JRuby 10++ now
if: matrix.ruby == 'jruby-head' || matrix.ruby == 'jruby'
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'temurin'
# see https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: false # runs 'bundle install' and caches installed gems automatically
- name: Run tests
env:
DEBUG: true
run: |
# !!! These commands must be executable in windows, macos and linux !!!
# Use the last version of bundler that supports Ruby < 3.0
java -version
ruby --version
ruby -e "puts 'Ruby platform = ' + RUBY_PLATFORM"
gem install bundler -v 2.4.22
bundle --version
which bundler
gem update bundler
bundle --version
which bundler
bundle install
bundle exec rake test 2>&1 | tee log/test.log
- name: Archive test log
if: always()
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.os }}_${{ matrix.ruby }}
path: |
log/test.log
test_*.jar
build:
name: Build + Publish
runs-on: ubuntu-latest
needs: test
if: github.ref == 'refs/heads/main'
permissions:
contents: write
packages: write
steps:
- uses: actions/checkout@v5
- uses: ruby/setup-ruby@v1
with:
ruby-version: '3.1'
- name: Build
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
gem build jarbler.gemspec
JARBLER_RELEASE=`ls jarbler-*.gem | sed 's/jarbler-//' | sed 's/\.gem//'`
echo "JARBLER_RELEASE=$JARBLER_RELEASE" >> $GITHUB_ENV
# Ensure that exit code != 0 does not stop the build
set +e
echo "Check for existing release tag"
gh release view $JARBLER_RELEASE -R ${{ github.repository }}
if [[ $? -eq 0 ]]; then
echo "Github release tag $JARBLER_RELEASE already exists"
else
echo "Github release tag $JARBLER_RELEASE does not exist yet"
gh release create $JARBLER_RELEASE "./jarbler-${JARBLER_RELEASE}.gem#jarbler-${JARBLER_RELEASE}.gem: use also 'gem install jarbler'" --notes "Continuous development" --title "Jarbler $JARBLER_RELEASE"
if [ $? -eq 0 ]; then
echo "Release created"
else
echo "gh release create failed"
exit 1
fi
fi
echo "Checking rubygems.org for RELEASE=$JARBLER_RELEASE"
gem search jarbler | grep jarbler | grep $JARBLER_RELEASE
if [[ $? -eq 0 ]]; then
echo "RELEASE=$JARBLER_RELEASE already exists on rubygems.org, no push executed"
else
echo "RELEASE=$JARBLER_RELEASE does not exist on rubygems.org yet"
echo "Manual execution of 'gem push jarbler-${JARBLER_RELEASE}.gem' required! This will fix the CI at next run"
echo "Download the release from Github and execute 'gem push jarbler-${JARBLER_RELEASE}.gem'"
exit 1
# rdoc --all --ri --op doc
# gem push *.gem
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# GH_TOKEN: ${{ github.token }}
# GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
- name: Put gem file into artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: jarbler-${{ env.JARBLER_RELEASE }}.gem
path: jarbler-${{ env.JARBLER_RELEASE }}.gem