-
Notifications
You must be signed in to change notification settings - Fork 320
87 lines (75 loc) · 3.45 KB
/
sync-release.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
name: sync release
on:
pull_request:
types:
- closed
jobs:
sync:
env:
GH_TOKEN: ${{ secrets.PAT }}
if: "${{ github.event.pull_request.merged && startsWith(github.event.pull_request.base.ref, 'release/') && startsWith(github.event.pull_request.title, 'chore: release') && github.event.pull_request.user.login == 'devops-github-rudderstack' }}"
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: parse commit
run: |
MERGE_COMMIT_SHA=$(gh pr view ${{ github.event.pull_request.number }} --json mergeCommit -q .mergeCommit.oid)
echo "MERGE_COMMIT_SHA=$MERGE_COMMIT_SHA" >> "$GITHUB_ENV"
- name: parse release tag
run: |
while [ -n $(git describe --contains $MERGE_COMMIT_SHA && echo "ok" || echo "") ]; do
echo "waiting for release...";
sleep 2
git fetch --tags
done;
RELEASE_TAG=$(git describe --contains $MERGE_COMMIT_SHA)
echo "RELEASE_TAG=$RELEASE_TAG" >> "$GITHUB_ENV"
- name: create branch
run: |
PR_BRANCH="sync-release-${MERGE_COMMIT_SHA}"
echo "PR_BRANCH=$PR_BRANCH" >> "$GITHUB_ENV"
git checkout $MERGE_COMMIT_SHA -b $PR_BRANCH
git push origin $PR_BRANCH
- name: create pull request for major or minor release
if: ${{ endsWith(env.RELEASE_TAG, '.0') }}
run: |
COMMIT_OVERRIDE=$(git rev-list --reverse --pretty="%s" --cherry-pick --right-only ${PR_BRANCH}...origin/master | grep -v "commit" | grep -v "chore: sync #" || echo "")
echo "# Description" >> body
echo "" >> body
echo "Syncing release ${RELEASE_TAG} to main branch" >> body
echo "" >> body
echo "**WARNING: Do NOT rewrite git history and ALWAYS use a \"Merge Commit\" for merging!**" >> body
echo "" >> body
echo "**↓↓ Please review and edit commit overrides before merging ↓↓**" >> body
echo "" >> body
echo "BEGIN_COMMIT_OVERRIDE" >> body
echo "${COMMIT_OVERRIDE}" >> body
echo "END_COMMIT_OVERRIDE" >> body
gh pr create \
--title "chore: sync release ${RELEASE_TAG} to main branch" \
--body "$(cat body)" \
--base master \
--head $PR_BRANCH \
--assignee '${{ github.event.pull_request.merged_by.login }}'
- name: create pull request for patch release
if: ${{ ! endsWith(env.RELEASE_TAG, '.0') }}
run: |
COMMIT_OVERRIDE=$(git rev-list --reverse --pretty="%s" --cherry-pick --right-only origin/master...${PR_BRANCH} | grep -v "commit" | grep -v "chore: release" || echo "")
echo "# Description" >> body
echo "" >> body
echo "Syncing patch release ${RELEASE_TAG} to main branch" >> body
echo "" >> body
echo "**↓↓ Please review and edit commit overrides before merging ↓↓**" >> body
echo "" >> body
echo "BEGIN_COMMIT_OVERRIDE" >> body
echo "${COMMIT_OVERRIDE}" >> body
echo "END_COMMIT_OVERRIDE" >> body
gh pr create \
--title "chore: sync release ${RELEASE_TAG} to main branch" \
--body "$(cat body)" \
--base master \
--head $PR_BRANCH \
--assignee '${{ github.event.pull_request.merged_by.login }}'