-
Notifications
You must be signed in to change notification settings - Fork 1
129 lines (129 loc) · 5.27 KB
/
release-PR-merge-actions.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
120
121
122
123
124
125
126
127
128
129
name: Release branch merge actions
on:
pull_request:
types: [closed]
branches:
- beta
- production
jobs:
shared-variables:
if: github.event.pull_request.merged == true && !contains(github.event.pull_request.labels.*.name, 'no-deploy')
runs-on: ubuntu-20.04
outputs:
tagname: ${{ steps.tagname.outputs.tagname }}
prerelease: ${{ steps.releaseflags.outputs.prerelease }}
latestrelease: ${{ steps.releaseflags.outputs.latestrelease }}
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Generate release tag name (as step output)
id: tagname
shell: bash
run: |
echo "tagname=$(bash ci-scripts/parse-release-branch-name.sh ${{ github.event.pull_request.head.ref }})" >> $GITHUB_OUTPUT
- name: Fail if variable tagname is empty
if: ${{ steps.tagname.outputs.tagname == '' }}
shell: bash
run: |
echo "Github output variable tagname is empty. Failing step." && false
- name: Convert base branch to releaseflags (prerelease and latestrelease)
id: releaseflags
shell: bash
run: |
echo "prerelease=${{github.event.pull_request.base.ref == 'production' && 'false' || 'true'}}" >> $GITHUB_OUTPUT
echo "latestrelease=${{github.event.pull_request.base.ref == 'production' && 'true' || 'false'}}" >> $GITHUB_OUTPUT
- name: Fail if prerelease is empty
if: ${{ steps.releaseflags.outputs.prerelease == '' }}
shell: bash
run: |
echo "Variable prerelease is empty. Failing step." && false
- name: Fail if latestrelease is empty
if: ${{ steps.releaseflags.outputs.latestrelease == '' }}
shell: bash
run: |
echo "Variable prerelease is empty. Failing step." && false
tag-and-release:
runs-on: ubuntu-20.04
needs: [shared-variables]
permissions:
contents: write
env:
tagmessage: ''
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Generate and store release message
shell: bash
run: |
{
echo 'tagmessage<<EOF'
git log --format=%b -n 1
echo EOF
} >> "$GITHUB_ENV"
- name: Git tag
uses: rickstaa/action-create-tag@v1
with:
tag: ${{ needs.shared-variables.outputs.tagname }}
message: ${{ env.tagmessage }}
- name: Create github release
uses: ncipollo/release-action@v1
with:
tag: ${{ needs.shared-variables.outputs.tagname }}
name: 'AGR Curation ${{ needs.shared-variables.outputs.tagname }}'
prerelease: ${{ needs.shared-variables.outputs.prerelease }}
makeLatest: ${{ needs.shared-variables.outputs.latestrelease }}
generateReleaseNotes: true
skipIfReleaseExists: true
token: ${{ secrets.GH_PAT }}
open-mergeback-PR-to-alpha:
runs-on: ubuntu-20.04
needs: [shared-variables, tag-and-release]
permissions:
contents: write
pull-requests: write
env:
mergeback-headbranchname: "gh-actions-mergeback-${{ needs.shared-variables.outputs.tagname }}-alpha"
mergeback-basebranchname: "alpha"
steps:
- name: Check out repository code
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GH_PAT }}
- name: create mergeback branch
run: |
git checkout -b ${{ env.mergeback-headbranchname }} ${{ needs.shared-variables.outputs.tagname }}
- name: fetch base branch
run: |
git fetch origin ${{ env.mergeback-basebranchname }}:${{ env.mergeback-basebranchname }}
- name: merge in base branch changes
id: merge-base
continue-on-error: true
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git merge --no-edit ${{ env.mergeback-basebranchname }}
- name: Abort merge if merging in base branch failed
if: ${{ steps.merge-base.outcome == 'failure' }}
run: |
git merge --abort
- name: push mergeback branch to github
run: |
git push origin ${{ env.mergeback-headbranchname }}
- name: open PR
id: pr-create
env:
GH_TOKEN: ${{ secrets.GH_PAT }}
run: |
echo "gh-pr-url=$(gh pr create -B ${{ env.mergeback-basebranchname }} -H ${{ env.mergeback-headbranchname }} \
-t 'Mergeback release ${{ needs.shared-variables.outputs.tagname }} to ${{ env.mergeback-basebranchname }}'\
-b 'Autogenerated through GH-actions.' -a '${{ github.event.pull_request.user.login }}' -l 'no-deploy')" >> $GITHUB_OUTPUT
- name: Post notification if automatic merge of base failed
if: ${{ steps.merge-base.outcome == 'failure' }}
env:
GH_TOKEN: ${{ secrets.GH_PAT }}
pr-comment: |
GH action detected a potential merge conflict with the base branch (${{ env.mergeback-basebranchname }}).
@${{ github.event.pull_request.user.login }} please resolve the merge conflict and merge the base branch manually.
run: |
gh pr comment ${{ steps.pr-create.outputs.gh-pr-url }} --body "${{ env.pr-comment }}"