-
Notifications
You must be signed in to change notification settings - Fork 11
97 lines (84 loc) · 3.35 KB
/
cherry-pick.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # 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@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # 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 }}