chore: Update GitHub Actions workflow to allow manaul publish #14
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI | |
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 | |
git config user.email [email protected] | |
git add lib/name_formatter/version.rb | |
git commit -m "Bump version to ${{ github.event.inputs.version }}" | |
git push | |
- 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 }} | |