[CONTP-545] quit leader election if context was cancelled #33658
Workflow file for this run
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: "Go update commenter" | |
on: | |
pull_request: | |
# Only run on PR label events (in particular not on every commit) | |
types: [ labeled ] | |
permissions: | |
# write permissions are needed to create the comment | |
pull-requests: write | |
jobs: | |
old-versions-match: | |
# Only run if the PR is labeled with 'go-update' | |
if: ${{ github.event.label.name == 'go-update' }} | |
runs-on: ubuntu-latest | |
steps: | |
# get the Go version of the target branch | |
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 | |
with: | |
ref: ${{ github.base_ref }} | |
persist-credentials: false | |
- name: Get former Go version | |
id: former_go_version | |
run: | | |
echo version="$(cat .go-version)" >> $GITHUB_OUTPUT | |
# get the Go version of the PR branch | |
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 | |
with: | |
persist-credentials: false | |
- name: Get current Go version | |
id: new_go_version | |
run: | | |
echo version="$(cat .go-version)" >> $GITHUB_OUTPUT | |
# build the comment | |
- name: Build full comment | |
env: | |
GITHUB_SERVER_URL: ${{ github.server_url }} | |
GITHUB_REPOSITORY: ${{ github.repository }} | |
GITHUB_SHA: ${{ github.sha }} | |
FORMER_GO_VERSION: ${{ steps.former_go_version.outputs.version }} | |
NEW_GO_VERSION: ${{ steps.new_go_version.outputs.version }} | |
id: old_versions | |
run: | | |
set -euo pipefail | |
# build the base of the Github URL to the current commit | |
GITHUB_HEAD_URL="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/blob/$GITHUB_SHA" | |
{ | |
echo "matches<<EOF" | |
echo "Here are potential matches of the former version:" | |
echo "" | |
# this step builds a Markdown list of potential matches | |
# the script `detect-old-version.sh` displays each matching line as "file:line_number:line_content" | |
# the sed command transforms this format into a markdown list with Github permalink URL for each file/line | |
# note that the sed command only works properly with GNU sed (MacOS sed doesn't seem to understand \S properly) | |
bash -x ./tools/go-update/detect-old-version.sh "$FORMER_GO_VERSION" "$NEW_GO_VERSION" | \ | |
sed -E 's|^([^:]+):([^:]+):\s*(\S.*)$|- [\1:\2]('"$GITHUB_HEAD_URL"'/\1#L\2): `\3`|' | |
echo "EOF" | |
} >> $GITHUB_OUTPUT | |
# and display it | |
- uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | |
env: | |
# We need to store the output in an environment variable and not use it directly in the createComment, | |
# as it will likely not be a valid JS string (eg. if it contains a quote character) | |
CONTENT: ${{ steps.old_versions.outputs.matches }} | |
with: | |
script: | | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: process.env.CONTENT | |
}) |