From 7f88c5eaae8a43ee6f0a542b631fee7003e6e7db Mon Sep 17 00:00:00 2001 From: jsneedles Date: Wed, 25 Nov 2026 14:42:43 -0500 Subject: [PATCH 1/3] Publish version bumps to RubyGems with trusted publishing --- .github/workflows/publish.yml | 85 +++++++++++++++++++++++++++++++++++ .github/workflows/ruby.yml | 32 ++++++++++++- README.md | 6 ++- docs/file.README.html | 4 +- docs/index.html | 4 +- 5 files changed, 127 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..fdba280 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,85 @@ +name: Publish to RubyGems + +on: + workflow_call: + inputs: + version: + required: true + type: string + +jobs: + publish: + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + runs-on: ubuntu-latest + environment: rubygems + concurrency: rubygems-${{ inputs.version }} + permissions: + contents: write + id-token: write + env: + VERSION: ${{ inputs.version }} + TAG: v${{ inputs.version }} + GEM_NAME: htmlcsstoimage-api + + steps: + - uses: actions/checkout@v6 + with: + ref: ${{ github.sha }} + fetch-depth: 0 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.3' + + - name: Check the tag and RubyGems version + id: check + run: | + set -euo pipefail + git check-ref-format "refs/tags/$TAG" + tagged=false + if git show-ref --verify --quiet "refs/tags/$TAG"; then + if [[ "$(git rev-parse "refs/tags/$TAG^{commit}")" != "$GITHUB_SHA" ]]; then + echo "::error::$TAG already points to a different commit." + exit 1 + fi + tagged=true + fi + status=$(curl --silent --show-error --retry 3 --output "$RUNNER_TEMP/gem.json" \ + --write-out '%{http_code}' "https://rubygems.org/api/v2/rubygems/$GEM_NAME/versions/$VERSION.json") + case "$status" in + 404) echo "push_gem=true" >> "$GITHUB_OUTPUT" ;; + 200) + if [[ "$tagged" != true ]] || ! jq -e '.yanked == false' "$RUNNER_TEMP/gem.json" > /dev/null; then + echo "::error::RubyGems already has $VERSION. Check its status and the matching Git tag." + exit 1 + fi + ;; + *) echo "::error::RubyGems version lookup returned HTTP $status."; exit 1 ;; + esac + echo "tagged=$tagged" >> "$GITHUB_OUTPUT" + + - name: Build the gem + if: steps.check.outputs.push_gem == 'true' + run: | + gem build htmlcsstoimage.gemspec + test -f "$GEM_NAME-$VERSION.gem" + + - name: Create the version tag + if: steps.check.outputs.tagged == 'false' + run: | + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git tag --annotate "$TAG" "$GITHUB_SHA" --message "Release $TAG" + git push origin "refs/tags/$TAG" + + - name: Authenticate with RubyGems + if: steps.check.outputs.push_gem == 'true' + uses: rubygems/configure-rubygems-credentials@c6ca7f4bac0e29c9bde8eeae0a0a986b27efa05f # v2.2.0 + - name: Publish the gem + if: steps.check.outputs.push_gem == 'true' + run: gem push --host https://rubygems.org "$GEM_NAME-$VERSION.gem" + + - name: Create GitHub Release + uses: softprops/action-gh-release@v3 + with: + tag_name: ${{ env.TAG }} + generate_release_notes: true diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index f4bc70b..d179647 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -8,11 +8,16 @@ on: jobs: test: - runs-on: ubuntu-latest + permissions: + contents: read + outputs: + release_version: ${{ steps.version.outputs.version }} steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Set up Ruby uses: ruby/setup-ruby@v1 with: @@ -21,3 +26,28 @@ jobs: run: bundle install - name: Run tests run: bundle exec rake + - name: Check for a version bump + id: version + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + env: + BEFORE_SHA: ${{ github.event.before }} + run: | + set -euo pipefail + version_file=lib/htmlcsstoimage/version.rb + version=$(ruby -r "./$version_file" -e 'print HTMLCSSToImage::VERSION') + if [[ "$BEFORE_SHA" != "0000000000000000000000000000000000000000" ]]; then + git show "$BEFORE_SHA:$version_file" > "$RUNNER_TEMP/previous_version.rb" + previous=$(ruby -r "$RUNNER_TEMP/previous_version.rb" -e 'print HTMLCSSToImage::VERSION') + if [[ "$previous" == "$version" ]]; then exit 0; fi + fi + echo "version=$version" >> "$GITHUB_OUTPUT" + + publish: + needs: test + if: needs.test.outputs.release_version != '' + permissions: + contents: write + id-token: write + uses: ./.github/workflows/publish.yml + with: + version: ${{ needs.test.outputs.release_version }} diff --git a/README.md b/README.md index ecc3676..17e4f77 100644 --- a/README.md +++ b/README.md @@ -368,7 +368,11 @@ and, for URL screenshots, `headers`, `additional_header_origins`, After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. -To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). +To install the gem locally, run `bundle exec rake install`. + +To release, bump `lib/htmlcsstoimage/version.rb`, run `bundle install` to update `Gemfile.lock`, and merge both changes into `main`. After the tests pass, GitHub Actions tags the tested commit as `v`, publishes the gem to RubyGems.org, and creates a GitHub Release. If a step fails, rerun the original workflow for that commit. + +The RubyGems trusted publisher for `htmlcsstoimage-api` uses the GitHub repository `htmlcsstoimage/ruby-client`, workflow filename `publish.yml`, and environment `rubygems`. Leave the two optional workflow repository fields blank. [RubyGems trusted publishing guide](https://guides.rubygems.org/trusted-publishing/). To generate the Yard docs, run `yard doc -o docs` and commit the changes. diff --git a/docs/file.README.html b/docs/file.README.html index 0d28223..77945a4 100644 --- a/docs/file.README.html +++ b/docs/file.README.html @@ -330,7 +330,9 @@

Available parameters

block_consent_banners.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

-

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

+

To install the gem locally, run bundle exec rake install.

+

To release, bump lib/htmlcsstoimage/version.rb, run bundle install to update Gemfile.lock, and merge both changes into main. After the tests pass, GitHub Actions tags the tested commit as v<version>, publishes the gem to RubyGems.org, and creates a GitHub Release. If a step fails, rerun the original workflow for that commit.

+

The RubyGems trusted publisher for htmlcsstoimage-api uses the GitHub repository htmlcsstoimage/ruby-client, workflow filename publish.yml, and environment rubygems. Leave the two optional workflow repository fields blank. RubyGems trusted publishing guide.

To generate the Yard docs, run yard doc -o docs and commit the changes.

Support

For help with the API, you can also contact support@htmlcsstoimage.com.

diff --git a/docs/index.html b/docs/index.html index 400627e..ffac62e 100644 --- a/docs/index.html +++ b/docs/index.html @@ -330,7 +330,9 @@

Available parameters

block_consent_banners.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

-

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

+

To install the gem locally, run bundle exec rake install.

+

To release, bump lib/htmlcsstoimage/version.rb, run bundle install to update Gemfile.lock, and merge both changes into main. After the tests pass, GitHub Actions tags the tested commit as v<version>, publishes the gem to RubyGems.org, and creates a GitHub Release. If a step fails, rerun the original workflow for that commit.

+

The RubyGems trusted publisher for htmlcsstoimage-api uses the GitHub repository htmlcsstoimage/ruby-client, workflow filename publish.yml, and environment rubygems. Leave the two optional workflow repository fields blank. RubyGems trusted publishing guide.

To generate the Yard docs, run yard doc -o docs and commit the changes.

Support

For help with the API, you can also contact support@htmlcsstoimage.com.

From 045b6bfa7c2b58ae8b5296b4a96e5d2c6ed01e60 Mon Sep 17 00:00:00 2001 From: jsneedles Date: Wed, 25 Nov 2026 14:43:35 -0500 Subject: [PATCH 2/3] Match the RubyGems publisher's blank environment --- .github/workflows/publish.yml | 1 - README.md | 2 +- docs/file.README.html | 2 +- docs/index.html | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index fdba280..602fe29 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -11,7 +11,6 @@ jobs: publish: if: github.event_name == 'push' && github.ref == 'refs/heads/main' runs-on: ubuntu-latest - environment: rubygems concurrency: rubygems-${{ inputs.version }} permissions: contents: write diff --git a/README.md b/README.md index 17e4f77..5432cf1 100644 --- a/README.md +++ b/README.md @@ -372,7 +372,7 @@ To install the gem locally, run `bundle exec rake install`. To release, bump `lib/htmlcsstoimage/version.rb`, run `bundle install` to update `Gemfile.lock`, and merge both changes into `main`. After the tests pass, GitHub Actions tags the tested commit as `v`, publishes the gem to RubyGems.org, and creates a GitHub Release. If a step fails, rerun the original workflow for that commit. -The RubyGems trusted publisher for `htmlcsstoimage-api` uses the GitHub repository `htmlcsstoimage/ruby-client`, workflow filename `publish.yml`, and environment `rubygems`. Leave the two optional workflow repository fields blank. [RubyGems trusted publishing guide](https://guides.rubygems.org/trusted-publishing/). +The RubyGems trusted publisher for `htmlcsstoimage-api` uses the GitHub repository `htmlcsstoimage/ruby-client` and workflow filename `publish.yml`. Leave Environment, Workflow Repository Owner, and Workflow Repository Name blank. [RubyGems trusted publishing guide](https://guides.rubygems.org/trusted-publishing/). To generate the Yard docs, run `yard doc -o docs` and commit the changes. diff --git a/docs/file.README.html b/docs/file.README.html index 77945a4..82b58d2 100644 --- a/docs/file.README.html +++ b/docs/file.README.html @@ -332,7 +332,7 @@

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install the gem locally, run bundle exec rake install.

To release, bump lib/htmlcsstoimage/version.rb, run bundle install to update Gemfile.lock, and merge both changes into main. After the tests pass, GitHub Actions tags the tested commit as v<version>, publishes the gem to RubyGems.org, and creates a GitHub Release. If a step fails, rerun the original workflow for that commit.

-

The RubyGems trusted publisher for htmlcsstoimage-api uses the GitHub repository htmlcsstoimage/ruby-client, workflow filename publish.yml, and environment rubygems. Leave the two optional workflow repository fields blank. RubyGems trusted publishing guide.

+

The RubyGems trusted publisher for htmlcsstoimage-api uses the GitHub repository htmlcsstoimage/ruby-client and workflow filename publish.yml. Leave Environment, Workflow Repository Owner, and Workflow Repository Name blank. RubyGems trusted publishing guide.

To generate the Yard docs, run yard doc -o docs and commit the changes.

Support

For help with the API, you can also contact support@htmlcsstoimage.com.

diff --git a/docs/index.html b/docs/index.html index ffac62e..83d8657 100644 --- a/docs/index.html +++ b/docs/index.html @@ -332,7 +332,7 @@

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install the gem locally, run bundle exec rake install.

To release, bump lib/htmlcsstoimage/version.rb, run bundle install to update Gemfile.lock, and merge both changes into main. After the tests pass, GitHub Actions tags the tested commit as v<version>, publishes the gem to RubyGems.org, and creates a GitHub Release. If a step fails, rerun the original workflow for that commit.

-

The RubyGems trusted publisher for htmlcsstoimage-api uses the GitHub repository htmlcsstoimage/ruby-client, workflow filename publish.yml, and environment rubygems. Leave the two optional workflow repository fields blank. RubyGems trusted publishing guide.

+

The RubyGems trusted publisher for htmlcsstoimage-api uses the GitHub repository htmlcsstoimage/ruby-client and workflow filename publish.yml. Leave Environment, Workflow Repository Owner, and Workflow Repository Name blank. RubyGems trusted publishing guide.

To generate the Yard docs, run yard doc -o docs and commit the changes.

Support

For help with the API, you can also contact support@htmlcsstoimage.com.

From 6428a1b4982e6f914f20fa6a09f8be44ba3fcbb1 Mon Sep 17 00:00:00 2001 From: jsneedles Date: Wed, 25 Nov 2026 14:46:20 -0500 Subject: [PATCH 3/3] Restrict RubyGems publishing to the SDK repository and pin actions --- .github/workflows/publish.yml | 10 ++++++---- .github/workflows/ruby.yml | 8 +++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 602fe29..fdf1951 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -9,7 +9,9 @@ on: jobs: publish: - if: github.event_name == 'push' && github.ref == 'refs/heads/main' + if: >- + github.repository == 'htmlcsstoimage/ruby-client' && + github.event_name == 'push' && github.ref == 'refs/heads/main' runs-on: ubuntu-latest concurrency: rubygems-${{ inputs.version }} permissions: @@ -21,11 +23,11 @@ jobs: GEM_NAME: htmlcsstoimage-api steps: - - uses: actions/checkout@v6 + - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 with: ref: ${{ github.sha }} fetch-depth: 0 - - uses: ruby/setup-ruby@v1 + - uses: ruby/setup-ruby@78c62f2208e480ce3d5ae4dfd9b9e181acf48b63 # v1 with: ruby-version: '3.3' @@ -78,7 +80,7 @@ jobs: run: gem push --host https://rubygems.org "$GEM_NAME-$VERSION.gem" - name: Create GitHub Release - uses: softprops/action-gh-release@v3 + uses: softprops/action-gh-release@8a0cd651e5b2365bd640854a3fa5dfc70e4875f3 # v3 with: tag_name: ${{ env.TAG }} generate_release_notes: true diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index d179647..b1ff0c4 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -15,11 +15,11 @@ jobs: release_version: ${{ steps.version.outputs.version }} steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 with: fetch-depth: 0 - name: Set up Ruby - uses: ruby/setup-ruby@v1 + uses: ruby/setup-ruby@78c62f2208e480ce3d5ae4dfd9b9e181acf48b63 # v1 with: ruby-version: '3.3' - name: Install dependencies @@ -28,7 +28,9 @@ jobs: run: bundle exec rake - name: Check for a version bump id: version - if: github.event_name == 'push' && github.ref == 'refs/heads/main' + if: >- + github.repository == 'htmlcsstoimage/ruby-client' && + github.event_name == 'push' && github.ref == 'refs/heads/main' env: BEFORE_SHA: ${{ github.event.before }} run: |