diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..e11165a --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +name: CI + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + ruby-version: ["3.0", "3.1", "3.2", "3.3"] + + steps: + - uses: actions/checkout@v4 + + - name: Set up Ruby ${{ matrix.ruby-version }} + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby-version }} + + - name: Run tests + run: ruby -Ilib -Itest -e "Dir['test/test_*.rb'].each { |f| require_relative f }" + + - name: Verify gem builds + run: gem build ipdata.gemspec diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..8318d1f --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,84 @@ +name: Publish to RubyGems + +on: + push: + tags: + - "v*" + 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: read + 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" + + - name: Run tests + run: ruby -Ilib -Itest -e "Dir['test/test_*.rb'].each { |f| require_relative f }" + + - name: Build gem + run: gem build ipdata.gemspec + + - name: Push to RubyGems + uses: rubygems/release-gem@v1