diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..41867f1 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,32 @@ +name: CI + +on: + push: + pull_request: + +permissions: + contents: read + +jobs: + test: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + ruby-version: ['3.2', '3.3'] + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby-version }} + bundler-cache: true + + - name: Run tests + run: bundle exec rake test + + - name: Build gem + run: bundle exec rake build diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..ddb89cd --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,58 @@ +name: Release + +on: + release: + types: [published] + workflow_dispatch: + +permissions: + contents: read + +jobs: + verify: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.2' + bundler-cache: true + + - name: Run tests + run: bundle exec rake test + + - name: Ensure version is bumped + run: | + CURRENT_VERSION="$(ruby -Ilib -e "require 'cloudstack_client/version'; puts CloudstackClient::VERSION")" + LATEST_JSON="$(curl -fsSL https://rubygems.org/api/v1/versions/cloudstack_client/latest.json || true)" + if [ -n "$LATEST_JSON" ]; then + LATEST_VERSION="$(printf '%s' "$LATEST_JSON" | ruby -rjson -e "puts JSON.parse(STDIN.read)['version']")" + ruby -e "require 'rubygems/version'; current = Gem::Version.new('$CURRENT_VERSION'); latest = Gem::Version.new('$LATEST_VERSION'); abort(\"Version must be bumped before building (current=#{current}, latest=#{latest})\") unless current > latest" + fi + + - name: Build gem + run: bundle exec rake build + + publish: + runs-on: ubuntu-latest + needs: verify + environment: rubygems + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.2' + bundler-cache: true + + - name: Publish gem to RubyGems + uses: rubygems/release-gem@v1 + with: + api-key: ${{ secrets.RUBYGEMS_AUTH_TOKEN }} diff --git a/Gemfile.lock b/Gemfile.lock index c5b00a2..e1478d5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - cloudstack_client (1.5.11) + cloudstack_client (1.5.12) GEM remote: https://rubygems.org/ diff --git a/README.md b/README.md index 48b6149..d76fc81 100644 --- a/README.md +++ b/README.md @@ -164,6 +164,19 @@ $ cloudstack_client list_apis > data/4.15.json $ gzip data/4.15.json ``` +### GitHub Actions + +This repository includes GitHub Actions workflows for: + +- Running tests and gem build on every push and pull request (`CI`) +- Publishing the gem to RubyGems when a GitHub Release is published (`Release`) + +To enable publishing, add this repository secret: + +- `RUBYGEMS_AUTH_TOKEN`: your RubyGems API key with push permissions + +The release workflow checks that `CloudstackClient::VERSION` is greater than the latest version on RubyGems before building, then uses the `rubygems` environment to publish. + ## References - [Apache CloudStack API documentation](http://cloudstack.apache.org/api/apidocs-4.15/)