Publish #23
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
name: Publish | |
on: | |
workflow_dispatch: | |
inputs: | |
version_type: | |
type: choice | |
description: Version type | |
default: minor | |
options: | |
- major | |
- minor | |
- patch | |
rubygems_api_key: | |
description: API Key | |
required: true | |
rubygems_otp: | |
description: OTP Code | |
required: true | |
jobs: | |
publish: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Hide the inputs values to keep them private in the logs when running this workflow | |
uses: levibostian/action-hide-sensitive-inputs@v1 | |
- uses: actions/checkout@v4 | |
- name: Setup git repo | |
run: | | |
git config user.name $GITHUB_ACTOR | |
git config user.email gh-actions-${GITHUB_ACTOR}@github.com | |
git remote add gh-origin https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git | |
- name: Set up Ruby | |
uses: ruby/setup-ruby@v1 | |
with: | |
ruby-version: 3.3.1 | |
- name: Upgrade RubyGems version | |
run: gem update --system | |
- name: Install gems | |
run: | | |
gem install bundler | |
bundle install --jobs 4 --retry 3 | |
- name: Bump Version | |
id: bump_version | |
run: | | |
NEW_VERSION=$(rake "bump_version_number[${{ inputs.version_type }}]") | |
echo "NEW_VERSION=$NEW_VERSION" | |
echo "new_version=$(echo $NEW_VERSION)" >> $GITHUB_OUTPUT | |
- name: Configure authentication to RubyGems | |
run: | | |
mkdir -p $HOME/.gem | |
touch $HOME/.gem/credentials | |
chmod 0600 $HOME/.gem/credentials | |
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials | |
env: | |
GEM_HOST_API_KEY: "${{ inputs.rubygems_api_key }}" | |
- name: Publish to RubyGems | |
run: rake publish | |
env: | |
GEM_HOST_OTP_CODE: ${{ inputs.rubygems_otp }} | |
- name: Create a Release | |
id: create-release | |
uses: softprops/action-gh-release@v1 | |
with: | |
tag_name: ${{ steps.bump_version.outputs.new_version }} | |
generate_release_notes: true | |
- name: Comment on PRs with link to release they are included in | |
uses: actions/github-script@v6 | |
env: | |
RELEASE_ID: ${{ steps.create-release.outputs.id }} | |
with: | |
script: | | |
const releaseId = process.env.RELEASE_ID; | |
console.log(`Fetching release_id: ${releaseId} ...`); | |
const getReleaseResponse = await github.rest.repos.getRelease({ | |
release_id: process.env.RELEASE_ID, | |
owner: context.repo.owner, | |
repo: context.repo.repo | |
}); | |
const release = getReleaseResponse.data; | |
const prNumbersInRelease = new Set(Array.from(release.body.matchAll(/\/pull\/(\d+)/g)).map(p=>p[1])); | |
for(let prNumber of prNumbersInRelease) { | |
console.log(`Adding comment on PR #${prNumber} ...`); | |
await github.rest.issues.createComment({ | |
issue_number: prNumber, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: `The changes in this PR were just released in [${release.name}](https://github.com/${context.repo.owner}/${context.repo.repo}/releases/tag/${release.tag_name}) 🎉.` | |
}) | |
} | |