Cherry-pick a release #43
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: Cherry-pick a release | |
on: | |
workflow_call: | |
inputs: | |
amp-version: | |
description: AMP version (13 digits) | |
required: true | |
type: string | |
shas: | |
description: commit sha(s) to cherry-pick with (i.e. abcdef1 abcdef2) | |
required: true | |
type: string | |
secrets: | |
access-token: | |
description: 'Personal access token for the bot that will create the pull requests' | |
required: true | |
workflow_dispatch: | |
inputs: | |
amp-version: | |
description: AMP version (13 digits) | |
required: true | |
type: string | |
shas: | |
description: commit sha(s) to cherry-pick with (i.e. abcdef1 abcdef2) | |
required: true | |
type: string | |
jobs: | |
cherry-pick: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout ampproject/amphtml | |
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 | |
with: | |
repository: ampproject/amphtml | |
fetch-depth: 0 | |
token: ${{ secrets.ACCESS_TOKEN }} | |
- name: Generate cherry-pick branch name | |
id: get-branch | |
run: | | |
# get amp version to be cherry-picked | |
AMP_VERSION=${{ github.event.inputs.amp-version }} | |
# get number of commits to cherry-pick | |
read -r -a SHAS_ARRAY <<< "${{ github.event.inputs.shas }}" | |
SHAS_COUNT=${#SHAS_ARRAY[@]} | |
# get number of current cherry-picks by taking the last 3 digits | |
CURRENT_CP_COUNT=${AMP_VERSION:10:13} | |
# add commits to cherry-pick to current cherry-picks, and then pad with 00 | |
# i.e. if there are 10 cherry-picks total, NEW_CP_COUNT would be 0010 | |
NEW_CP_COUNT=00$(expr $CURRENT_CP_COUNT + $SHAS_COUNT) | |
# set the cherry-picked amp version to be the first 10 digits of the current amp version, | |
# then the last 3 digits of the total cherry-picks | |
# i.e. if there are 10 cherry-picks total, the last 3 digits would be 010 | |
CHERRY_PICK_BRANCH=amp-release-${AMP_VERSION:0:10}${NEW_CP_COUNT: -3} | |
echo "branch=${CHERRY_PICK_BRANCH}" >> $GITHUB_OUTPUT | |
- name: Set git config | |
run: | | |
NAME=$(git --no-pager log --format=format:'%an' -n 1) | |
EMAIL="$(git --no-pager log --format=format:'%ae' -n 1)" | |
git config --global user.name $NAME | |
git config --global user.email $EMAIL | |
- name: Cherry-pick ${{ github.event.inputs.amp-version }} with ${{ github.event.inputs.shas }} | |
run: | | |
git checkout -b ${{ steps.get-branch.outputs.branch }} ${{ github.event.inputs.amp-version }} | |
git cherry-pick -x ${{ github.event.inputs.shas }} | |
git push --set-upstream https://github.com/ampproject/amphtml.git ${{ steps.get-branch.outputs.branch }} | |
create-issue-on-error: | |
if: failure() | |
needs: cherry-pick | |
permissions: | |
contents: read | |
issues: write | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 | |
- name: Create issue on error | |
uses: JasonEtco/create-an-issue@v2 | |
with: | |
filename: .github/create_issue_on_error.md | |
env: | |
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }} | |
WORKFLOW_NAME: ${{ github.workflow }} | |
MENTION: '@ampproject/release-on-duty' | |
REPO_SLUG: ${{ github.repository }} | |
RUN_ID: ${{ github.run_id }} |