Add MFA support #29
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 | |
permissions: | |
contents: write | |
on: | |
push: | |
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 π€ | |
if: ${{ github.event.inputs.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: Install OTP CLI π± | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y oathtool | |
- 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 | |
OTP=$(oathtool --totp --base32 $RUBYGEMS_OTP_SECRET) | |
gem push --verbose --otp=$OTP *.gem | |
env: | |
RUBYGEMS_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }} | |
RUBYGEMS_OTP_SECRET: ${{ secrets.RUBYGEMS_OTP_SECRET }} | |