-
Notifications
You must be signed in to change notification settings - Fork 0
118 lines (106 loc) · 5.31 KB
/
release-on-merge.yaml
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
## This action is run when a commit is made to a `release-*` branch (ideally from patch-* PR)
## - Creates Github Release (with codebase after commit) and Git Tag
## - Creates Changelog for Release
## - Upmerges branch to develop (so any changes that were made in release branch are in develop)
name: "Release-Merge"
on:
push:
branches:
- release-*
jobs:
create-release-tag:
strategy:
max-parallel: 1
runs-on: ubuntu-latest
outputs:
major: ${{ steps.version.outputs.major }}
minor: ${{ steps.version.outputs.minor }}
patch: ${{ steps.version.outputs.patch }}
merged: ${{ steps.check_release.outputs.merged }}
release-commit: ${{ steps.check_release.outputs.release-commit }}
main-commit: ${{ steps.check_release.outputs.main-commit }}
steps:
- uses: actions/checkout@v2.3.4
with:
## This is a Personal Access Token from Admin User that allows us to bypass branch protections on develop
token: ${{ secrets.PAT }}
fetch-depth: 0
# NOTE: Update CHANGELOG_PREFIX_LIST to configure the lines you wan to include in the changelog (body of release PR)
- name: "Get Release Info"
id: version
run: |
git fetch --all --tags;
git checkout ${GITHUB_REF##*/};
cd scripts/release;
unzip git-mkver-linux.zip;
cd ../..;
echo "##[set-output name=major;]$(./scripts/release/git-mkver-linux next --format '{Major}')";
echo "##[set-output name=minor;]$(./scripts/release/git-mkver-linux next --format '{Minor}')";
echo "##[set-output name=patch;]$(./scripts/release/git-mkver-linux next --format '{Patch}')";
CHANGELOG=$(git log --format=%s $(git describe --tags --abbrev=0)..HEAD | grep -i -E "^($CHANGELOG_PREFIX_LIST)" | sed "s/^/ - /")
CHANGELOG="${CHANGELOG//'%'/'%25'}"
CHANGELOG="${CHANGELOG//$'\n'/'%0A'}"
CHANGELOG="${CHANGELOG//$'\r'/'%0D'}"
echo "##[set-output name=changelog;]$(echo $CHANGELOG)";
env:
CHANGELOG_PREFIX_LIST: "feature|feat|fix|bugfix|bug"
# Find info about `release-*` branch:
# 1. has the release branch already been merged to `main` branch
# 2. commit hashes of `main` branch and `release-*` branch
- name: Check Create Release
id: check_release
run: |
echo "##[set-output name=merged;]$(git log main | grep ${GITHUB_REF##*/})";
echo "##[set-output name=main-commit;]$(git log --oneline main | awk '{if (NR == 1) commit=$1 } END { print commit }')";
echo "##[set-output name=release-commit;]$(git log --oneline ${GITHUB_REF##*/} | awk '{if (NR == 1) commit=$1 } END { print commit }')";
# Create Github Release:
# if it has been merged to `main` before (not first cut)
# AND if `release-*` branch commit does not match `main` (not a fast forward)
- name: Create Github Release
id: create_release
uses: actions/create-release@v1
if: steps.version.outputs.patch != 0 && steps.check_release.outputs.release-commit != steps.check_release.outputs.main-commit
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.version.outputs.major }}.${{ steps.version.outputs.minor }}.${{ steps.version.outputs.patch }}
release_name: release-${{ steps.version.outputs.major }}.${{ steps.version.outputs.minor }}.${{ steps.version.outputs.patch }}
body: ${{ steps.version.outputs.changelog }}
upmerge-after-release:
strategy:
max-parallel: 1
runs-on: ubuntu-latest
needs: create-release-tag
steps:
- uses: actions/checkout@v2.3.4
with:
## This is a Personal Access Token from Admin User that allows us to bypass branch protections on develop
token: ${{ secrets.PAT }}
fetch-depth: 0
# Upmerge `release-*` branch to `develop` when:
# it has been merged to `main` before (not first cut)
# AND `release-*` branch is not same commit as `main` (not a fast forward)
- name: Upmerge develop After Release
if: needs.create-release-tag.outputs.patch != 0 && needs.create-release-tag.outputs.release-commit != needs.create-release-tag.outputs.main-commit
run: |
git config --global user.name 'Release Cut';
git config --global user.email 'release@cut.com';
./scripts/release/release-prep-upmerge.sh ${GITHUB_REF##*/}
git commit -m "upmerge after $RELEASE";
git push;
env:
RELEASE: v${{ needs.create-release-tag.outputs.major }}.${{ needs.create-release-tag.outputs.minor }}.${{ needs.create-release-tag.outputs.patch }}
# Upmerge `release-*` branch to `main` when:
# it has been merged to `main` before (not first cut)
# AND `release-*` branch is not same commit as `main` (not a fast forward)
- name: Upmerge main After Release
if: needs.create-release-tag.outputs.patch != 0 && needs.create-release-tag.outputs.release-commit != needs.create-release-tag.outputs.main-commit
run: |
git config --global user.name 'Release Cut';
git config --global user.email 'release@cut.com';
git checkout main;
git pull;
git merge ${GITHUB_REF##*/};
git push;
env:
RELEASE: v${{ needs.create-release-tag.outputs.major }}.${{ needs.create-release-tag.outputs.minor }}.${{ needs.create-release-tag.outputs.patch }}