Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Publish to RubyGems

on:
workflow_call:
inputs:
version:
required: true
type: string

jobs:
publish:
if: >-
github.repository == 'htmlcsstoimage/ruby-client' &&
github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
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@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
with:
ref: ${{ github.sha }}
fetch-depth: 0
- uses: ruby/setup-ruby@78c62f2208e480ce3d5ae4dfd9b9e181acf48b63 # 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@8a0cd651e5b2365bd640854a3fa5dfc70e4875f3 # v3
with:
tag_name: ${{ env.TAG }}
generate_release_notes: true
38 changes: 35 additions & 3 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,48 @@ on:

jobs:
test:

runs-on: ubuntu-latest
permissions:
contents: read
outputs:
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
run: bundle install
- name: Run tests
run: bundle exec rake
- name: Check for a version bump
id: version
if: >-
github.repository == 'htmlcsstoimage/ruby-client' &&
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 }}
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<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` 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.

Expand Down
4 changes: 3 additions & 1 deletion docs/file.README.html
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,9 @@ <h2 id="Available_parameters">Available parameters</h2>
<code>block_consent_banners</code>.</p>
<h2 id="Development">Development</h2>
<p>After checking out the repo, run <code>bin/setup</code> to install dependencies. Then, run <code>rake spec</code> to run the tests. You can also run <code>bin/console</code> for an interactive prompt that will allow you to experiment.</p>
<p>To install this gem onto your local machine, run <code>bundle exec rake install</code>. To release a new version, update the version number in <code>version.rb</code>, and then run <code>bundle exec rake release</code>, which will create a git tag for the version, push git commits and tags, and push the <code>.gem</code> file to <a href="https://rubygems.org">rubygems.org</a>.</p>
<p>To install the gem locally, run <code>bundle exec rake install</code>.</p>
<p>To release, bump <code>lib/htmlcsstoimage/version.rb</code>, run <code>bundle install</code> to update <code>Gemfile.lock</code>, and merge both changes into <code>main</code>. After the tests pass, GitHub Actions tags the tested commit as <code>v&lt;version&gt;</code>, publishes the gem to RubyGems.org, and creates a GitHub Release. If a step fails, rerun the original workflow for that commit.</p>
<p>The RubyGems trusted publisher for <code>htmlcsstoimage-api</code> uses the GitHub repository <code>htmlcsstoimage/ruby-client</code> and workflow filename <code>publish.yml</code>. Leave Environment, Workflow Repository Owner, and Workflow Repository Name blank. <a href="https://guides.rubygems.org/trusted-publishing/">RubyGems trusted publishing guide</a>.</p>
<p>To generate the Yard docs, run <code>yard doc -o docs</code> and commit the changes.</p>
<h2 id="Support">Support</h2>
<p>For help with the API, you can also contact <code>support@htmlcsstoimage.com</code>.</p>
Expand Down
4 changes: 3 additions & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,9 @@ <h2 id="Available_parameters">Available parameters</h2>
<code>block_consent_banners</code>.</p>
<h2 id="Development">Development</h2>
<p>After checking out the repo, run <code>bin/setup</code> to install dependencies. Then, run <code>rake spec</code> to run the tests. You can also run <code>bin/console</code> for an interactive prompt that will allow you to experiment.</p>
<p>To install this gem onto your local machine, run <code>bundle exec rake install</code>. To release a new version, update the version number in <code>version.rb</code>, and then run <code>bundle exec rake release</code>, which will create a git tag for the version, push git commits and tags, and push the <code>.gem</code> file to <a href="https://rubygems.org">rubygems.org</a>.</p>
<p>To install the gem locally, run <code>bundle exec rake install</code>.</p>
<p>To release, bump <code>lib/htmlcsstoimage/version.rb</code>, run <code>bundle install</code> to update <code>Gemfile.lock</code>, and merge both changes into <code>main</code>. After the tests pass, GitHub Actions tags the tested commit as <code>v&lt;version&gt;</code>, publishes the gem to RubyGems.org, and creates a GitHub Release. If a step fails, rerun the original workflow for that commit.</p>
<p>The RubyGems trusted publisher for <code>htmlcsstoimage-api</code> uses the GitHub repository <code>htmlcsstoimage/ruby-client</code> and workflow filename <code>publish.yml</code>. Leave Environment, Workflow Repository Owner, and Workflow Repository Name blank. <a href="https://guides.rubygems.org/trusted-publishing/">RubyGems trusted publishing guide</a>.</p>
<p>To generate the Yard docs, run <code>yard doc -o docs</code> and commit the changes.</p>
<h2 id="Support">Support</h2>
<p>For help with the API, you can also contact <code>support@htmlcsstoimage.com</code>.</p>
Expand Down
Loading