Repository navigation
Publish to RubyGems #5
This file contains hidden or 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: Publish to RubyGems | |
| on: | |
| push: | |
| tags: | |
| - "v*" | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| inputs: | |
| bump: | |
| description: "Version bump type" | |
| required: true | |
| type: choice | |
| options: | |
| - patch | |
| - minor | |
| - major | |
| jobs: | |
| bump: | |
| if: github.event_name == 'workflow_dispatch' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Ruby | |
| uses: ruby/setup-ruby@v1 | |
| with: | |
| ruby-version: "3.3" | |
| - name: Bump version | |
| id: bump | |
| run: | | |
| current=$(ruby -r ./lib/ipdata/version -e "puts IPData::VERSION") | |
| IFS='.' read -r major minor patch <<< "$current" | |
| case "${{ inputs.bump }}" in | |
| major) major=$((major + 1)); minor=0; patch=0 ;; | |
| minor) minor=$((minor + 1)); patch=0 ;; | |
| patch) patch=$((patch + 1)) ;; | |
| esac | |
| new_version="${major}.${minor}.${patch}" | |
| echo "version=${new_version}" >> "$GITHUB_OUTPUT" | |
| sed -i "s/VERSION = \"${current}\"/VERSION = \"${new_version}\"/" lib/ipdata/version.rb | |
| - name: Commit and tag | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add lib/ipdata/version.rb | |
| git commit -m "Bump version to v${{ steps.bump.outputs.version }}" | |
| git tag "v${{ steps.bump.outputs.version }}" | |
| git push origin main --tags | |
| release: | |
| if: always() && (github.event_name == 'push' || needs.bump.result == 'success') | |
| needs: [bump] | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| id-token: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.event_name == 'workflow_dispatch' && 'main' || github.ref }} | |
| - name: Set up Ruby | |
| uses: ruby/setup-ruby@v1 | |
| with: | |
| ruby-version: "3.3" | |
| bundler-cache: true | |
| - name: Run tests | |
| run: bundle exec rake test | |
| - name: Push to RubyGems | |
| uses: rubygems/release-gem@v1 |