name: Ruby Gem CI/CD on: push: branches: [ "main" ] pull_request: branches: [ "main" ] jobs: build-and-publish: name: Build and Publish Gem runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Set up Ruby 3.2.2 uses: ruby/setup-ruby@v1 with: ruby-version: '3.2.2' - name: Install dependencies run: bundle install - name: Build Gem run: gem build *.gemspec - name: Push to RubyGems run: | mkdir -p $HOME/.gem touch $HOME/.gem/credentials chmod 0600 $HOME/.gem/credentials printf -- "---\n:rubygems_api_key: ${RUBYGEMS_AUTH_TOKEN}\n" > $HOME/.gem/credentials gem push *.gem env: RUBYGEMS_AUTH_TOKEN: ${{ secrets.RUBYGEMS_AUTH_TOKEN }} - name: Tag Incremental Version if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads/main') run: | git config --local user.email "action@github.com" git config --local user.name "GitHub Action" git tag -a v$(date +'%Y%m%d%H%M%S') -m "Automated tag from GitHub Actions" git push origin --tags