-
Notifications
You must be signed in to change notification settings - Fork 4.7k
119 lines (102 loc) · 5.13 KB
/
automatic-release-to-main-merger.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
name: Automatic main branch merger
on:
# whenever a pull request is merged into a release branch,
# open a pull request to merge changes down to the main branch
pull_request:
branches:
- '[0-9]+.[0-9]+.x'
# Don't merge 2.8.x into main
- '!2.8.x'
# Don't merge 3.0, 3.1 and 3.2 into main
- '!3.0.x'
- '!3.1.x'
- '!3.2.x'
types:
# means that the PR is closed, we still have to check if it was merged
- closed
env:
# keep this in sync with the automatic-pr-approver workflow
LABEL_TYPE: type:release-branch-port
LABEL_STATUS: status:ready-to-merge
jobs:
update_merge_pr:
runs-on: ubuntu-22.04
# only run this workflow if a pull request has been merged
if: github.event.pull_request.merged == true
steps:
- name: Checkout git repository 🕝
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c
- name: Fetch git tags 🎨
# see https://github.com/actions/checkout/issues/206#issuecomment-617937725
run: git fetch --prune --unshallow --tags
- name: Get branch name ✍️
id: get-branch-name
run: |
GITHUB_BRANCH=${GITHUB_REF/refs\/heads\//}
echo "release_branch=${GITHUB_BRANCH}" >> $GITHUB_OUTPUT
echo "new_branch=merge-${GITHUB_BRANCH}-main-${GITHUB_SHA:0:7}" >> $GITHUB_OUTPUT
- name: Get GitHub labels 🏷
id: get-github-labels
run: |
LATEST_RASA_MINOR=$(git tag --list | grep -P '^\d+\.\d+\.\d+$' | tail -n1 | sed -e 's/.\([0-9]\)*$/.0/g')
echo "Latest minor: ${LATEST_RASA_MINOR}"
# bash doesn't support nested variable access
CURRENT_RASA_MINOR=${GITHUB_REF/refs\/heads\//}
CURRENT_RASA_MINOR=${CURRENT_RASA_MINOR/\.x/\.0}
if [[ ${LATEST_RASA_MINOR} == ${CURRENT_RASA_MINOR} ]]
then
echo "labels=${LABEL_TYPE},${LABEL_STATUS}" >> $GITHUB_OUTPUT
else
echo "labels=${LABEL_TYPE}" >> $GITHUB_OUTPUT
fi
- name: Create new branch 🐣
id: create-new-branch
if: always()
uses: peterjgrainger/action-create-branch@64aa569aea81305305c6e92bd236d8c427debff8
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
branch: ${{ steps.get-branch-name.outputs.new_branch }}
- name: Notify Slack if creating a new branch failed 💬
if: ${{ failure() && steps.create-new-branch.conclusion == 'failure' }}
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_INFRASTRUCTURE_SQUAD_MONITORS_WEBHOOK_URL }}
uses: Ilshidur/action-slack@689ad44a9c9092315abd286d0e3a9a74d31ab78a
with:
args: "🚨 There was a problem with creating a new branch containing commits from the ${{ env.RELEASE_BRANCH }} release branch. Check out the Github action: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
- name: Open pull request ☄️
if: ${{ steps.create-new-branch.conclusion == 'success' }}
uses: repo-sync/pull-request@7e79a9f5dc3ad0ce53138f01df2fad14a04831c5
with:
# using this token to make sure it triggers other actions
github_token: ${{ secrets.RASABOT_GITHUB_TOKEN }}
source_branch: ${{ steps.get-branch-name.outputs.new_branch }}
destination_branch: main
pr_title: Merge ${{ steps.get-branch-name.outputs.release_branch }} into main
pr_template: .github/PULL_REQUEST_AUTOMATIC_TEMPLATE.md
pr_label: ${{ steps.get-github-labels.outputs.labels }}
pr_reviewer: ${{ github.event.pull_request.user.login }}
- name: Close outdated release-merge PRs 🧹
id: close-outdated-release-merge-prs
run: |
# fetch all open merge-PRs that have been opened from the current release branch
gh pr list -S "is:open label:${LABEL_TYPE} head:merge-${{ steps.get-branch-name.outputs.release_branch }}-main" > prs.txt
less prs.txt
# delete newly opened PR from the list
awk '!/${{ steps.get-branch-name.outputs.new_branch }}/' prs.txt > temp && mv temp prs.txt
# extract the PR ids
awk '{print $1}' prs.txt > pr_ids.txt
# close all outdated PRs
while read id; do
gh pr close $id -d
done <pr_ids.txt
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: Notify Slack when closing of outdated merge-PRs failed 💬
if: ${{ failure() && steps.close-outdated-release-merge-prs.conclusion == 'failure'}}
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_INFRASTRUCTURE_SQUAD_MONITORS_WEBHOOK_URL }}
uses: Ilshidur/action-slack@689ad44a9c9092315abd286d0e3a9a74d31ab78a
with:
args: "🚨 There was a problem with closing outdated release-merge-PRs of the ${{ env.RELEASE_BRANCH }} release branch. Check out the Github action: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} \
These release-merge-PRs are currently open: https://github.com/${{ github.repository }}/pulls?q=is%3Aopen+label%3A${{ env.LABEL_TYPE }}+head%3Amerge-${{ steps.get-branch-name.outputs.release_branch }}-main"