Skip to content

Release

Release #64

Workflow file for this run

# This workflow was generated by https://github.com/rubygems/configure_trusted_publisher
name: Release
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:
release:
name: Release Gems
# Limit who can run run this action to admins.
if: github.repository == 'block/elasticgraph' && contains('["myronmarston", "bsorbo"]', github.actor)
runs-on: ubuntu-latest
environment:
name: rubygems.org
url: https://rubygems.org/search?query=elasticgraph
permissions:
actions: write
contents: write
id-token: write
pull-requests: write
steps:
# Set up
- name: Harden Runner
uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0
with:
egress-policy: audit
- name: Checkout Git Repo
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
- name: Set up Ruby
uses: ruby/setup-ruby@4c24fa5ec04b2e79eb40571b1cee2a0d2b705771 # v1.278.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: Archive Docs (for non-prerelease versions)
run: |
if [[ ! "${{ inputs.version }}" =~ [a-zA-Z] ]]; then
bundle exec rake "site:archive_docs[${{ inputs.version }}]"
git add config/site/archived_docs/v${{ inputs.version }}.tar.gz
git commit -m "Archive docs for v${{ inputs.version }}"
fi
- name: Bump the ElasticGraph version to release version
run: |
bundle exec rake bump_version[${{ inputs.version }}]
if [[ ! "${{ inputs.version }}" =~ [a-zA-Z] ]]; then
# For non-prerelease versions, squash the doc archive commit with the version bump
git reset --soft HEAD~2 && git commit -C ORIG_HEAD
fi
# 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@1c162a739e8b4cb21a676e97b087e8268d8fc40b # v1.1.2
with:
await-release: ${{ ! inputs.dry-run }}
- name: Bump the ElasticGraph version to next pre-release version
run: |
unset GEM_RELEASE_PRETEND
bundle exec rake bump_version_to_next_prerelease
# 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@98357b18bf14b5342f975ff684046ec3b2a07725 # v8.0.0
with:
sign-commits: false
branch: release-v${{ inputs.version }}
title: "Release v${{ inputs.version }}"
body: |
> [!NOTE]
> This PR bumps the ElasticGraph version twice in two separate commits. The released version does not show
> in the overall PR diff but is in the first commit. These two commits should not be squashed or rebased so
> that the tagged commit lands as-is in the base branch.
- [ ] Confirm the [release 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)
# PRs created using GITHUB_TOKEN don't trigger `pull_request` workflows (GitHub prevents
# this to avoid infinite loops). We explicitly trigger CI here so that the release PR
# gets the required `All CI Checks Passed` status check for branch protection.
- name: Trigger CI on release branch
run: gh workflow run ci.yaml --ref release-v${{ inputs.version }}
env:
GH_TOKEN: ${{ github.token }}
- name: Create GitHub Release
uses: ncipollo/release-action@b7eabc95ff50cbeeedec83973935c8f306dfcd0b # v1.20.0
with:
draft: true
generateReleaseNotes: true
tag: v${{ inputs.version }}