Push Gem #2
This file contains 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
# This workflow was generated by https://github.com/rubygems/configure_trusted_publisher | |
name: Push Gem | |
on: | |
workflow_dispatch: | |
inputs: | |
version: | |
description: "Version to release (e.g. 1.2.0)" | |
required: true | |
type: string | |
dry-run: | |
description: "Dry Run" | |
required: false | |
type: boolean | |
default: false | |
permissions: | |
contents: read | |
jobs: | |
push: | |
# Limit who can run run this action to core maintainers. | |
if: github.repository == 'block/elasticgraph' && contains('["myronmarston", "BrianSigafoos-SQ"]', github.actor) | |
runs-on: ubuntu-latest | |
environment: | |
name: rubygems.org | |
url: https://rubygems.org/search?query=elasticgraph | |
permissions: | |
contents: write | |
id-token: write | |
pull-requests: write | |
steps: | |
# Set up | |
- name: Harden Runner | |
uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v2.7.1 | |
with: | |
egress-policy: audit | |
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 | |
- name: Set up Ruby | |
uses: ruby/setup-ruby@cacc9f1c0b3f4eb8a16a6bb0ed10897b43b9de49 # v1.176.0 | |
with: | |
working-directory: config/release | |
bundler-cache: true | |
ruby-version: ruby | |
- name: Setup Git Config | |
# https://github.com/orgs/community/discussions/26560#discussioncomment-3531273 | |
run: | | |
git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
git config user.name "github-actions[bot]" | |
- name: Target Release Rakefile | |
run: | | |
rm Rakefile | |
cp config/release/Rakefile . | |
git update-index --skip-worktree Rakefile | |
echo "BUNDLE_GEMFILE=config/release/Gemfile" >> "$GITHUB_ENV" | |
- name: Bump the ElasticGraph version | |
run: bundle exec rake bump_version[${{ inputs.version }}] | |
# Note: we put this after bumping the version because really bumping the version is safe to do in dry-run mode. | |
- name: Enable Dry Run Mode | |
if: ${{ inputs.dry-run }} | |
# As per docs[^1], this is the syntax for setting ENV vars for later steps. | |
# [^1]: https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#setting-an-environment-variable | |
run: echo "GEM_RELEASE_PRETEND=true" >> "$GITHUB_ENV" | |
# Release | |
- name: Release to rubygems.org | |
uses: rubygems/release-gem@612653d273a73bdae1df8453e090060bb4db5f31 # v1 | |
with: | |
await-release: ${{ ! inputs.dry-run }} | |
# Note: this must come after we release the gem because it resets git back to the same SHA we started on | |
# (before bumping the version), but the RubyGems release depends on the version having been bumped. | |
- name: Create pull request for the version bump | |
uses: peter-evans/create-pull-request@v6 | |
with: | |
branch: release-v${{ inputs.version }} | |
title: "Release v${{ inputs.version }}" | |
body: | | |
- [ ] Confirm the [push-gem action](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) succeeded before merging | |
- [ ] Confirm this version bump should be merged into [${{ github.ref_name }}](https://github.com/${{ github.repository }}/tree/${{ github.ref_name }}) or change the base branch | |
- [ ] Review and edit the [GitHub Draft Release](https://github.com/${{ github.repository }}/releases) (can be done after this PR is merged) | |
- name: Create GitHub Release | |
uses: ncipollo/release-action@v1 | |
with: | |
draft: true | |
generateReleaseNotes: true | |
tag: v${{ inputs.version }} |