Skip to content

chore: Update GitHub Actions workflow to include conditional commit a… #17

chore: Update GitHub Actions workflow to include conditional commit a…

chore: Update GitHub Actions workflow to include conditional commit a… #17

Workflow file for this run

name: CI
permissions:
contents: write
on:
push:
branches:
- main
pull_request:
branches:
- main
release:
types:
- published
workflow_dispatch:
inputs:
version:
description: 'Version to release'
required: true
publish:
description: 'Publish to RubyGems?'
type: boolean
default: false
jobs:
lint:
name: Lint 🚨
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v4
- name: Install Ruby 💎
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.3
- name: Install dependencies 📦
run: |
echo 'gem: --no-document' >> ~/.gemrc
gem install standardrb
- name: Run linter 🚨
run: standardrb
test:
name: Test 🧪
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
ruby:
- 3.4.0-preview1
- 3.3
- 3.0
env:
BUNDLE_GEMFILE: Gemfile
steps:
- name: Checkout 🛎️
uses: actions/checkout@v4
- name: Install Ruby 💎
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Install dependencies 📦
run: bundle install
- name: Run tests 🧪
run: bundle exec ruby -Ilib test/*.rb
publish:
if: >
(github.event_name == 'release' && github.event.action == 'published') ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.publish == 'true')
needs:
- lint
- test
name: Build and Publish Gem 🚀
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.3
- name: Update version 🔄
if: github.event_name == 'workflow_dispatch'
run: |
sed -i "s/VERSION = .*/VERSION = \"${{ github.event.inputs.version }}\"/" lib/name_formatter/version.rb
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
if [[ -n $(git status -s) ]]; then
echo "Changes detected. Committing and pushing..."
git add lib/name_formatter/version.rb
git commit -m "Bump version to ${{ github.event.inputs.version }}"
git push
else
echo "No changes detected. Version is already up-to-date."
fi
- name: Verify gem version 🤝
run: |
version=$(ruby -r ./lib/name_formatter/version.rb -e "puts NameFormatterModule::VERSION")
if [ "$version" != "${{ github.event.inputs.version }}" ]; then
echo "Version mismatch: $version != ${{ github.event.inputs.version }}"
exit 1
fi
- name: Install dependencies 📦
run: |
echo 'gem: --no-document' >> ~/.gemrc
gem install bundler
bundle install
- name: Build Gem 📦
run: gem build *.gemspec
- name: Publish Gem 🚀
run: |
mkdir -p $HOME/.gem
touch $HOME/.gem/credentials
chmod 0600 $HOME/.gem/credentials
printf -- "---\n:rubygems_api_key: ${RUBYGEMS_API_KEY}" > $HOME/.gem/credentials
gem push *.gem
env:
RUBYGEMS_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}