forked from algorand/go-algorand-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
194 lines (180 loc) · 8.54 KB
/
create-release-pr.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
name: Create Release PR
on:
workflow_dispatch:
inputs:
release_version:
description: 'The release_version used for the release branch name, e.g. release/vx.x.x'
default: 'vx.x.x'
required: true
type: string
pre_release_version:
description: "Pre-Release version, e.g. 'beta.1', will be added behind the release_version as the tag."
required: false
type: string
env:
RELEASE_VERSION: ${{ inputs.release_version }}
PRE_RELEASE_VERSION: ${{ inputs.pre_release_version }}
RELEASE_BRANCH: release/${{ inputs.release_version }}
jobs:
create-release-pr:
runs-on: ubuntu-latest
steps:
- name: Set Release Version and Branch to Check Out
id: set-release
run: |
if [[ $RELEASE_VERSION =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
if [[ $PRE_RELEASE_VERSION =~ ^[a-z.0-9]+$ ]]; then
echo "release-tag: $RELEASE_VERSION-$PRE_RELEASE_VERSION"
echo "release-tag=$RELEASE_VERSION-$PRE_RELEASE_VERSION" >> $GITHUB_OUTPUT
elif [[ -n $PRE_RELEASE_VERSION ]]; then
echo "Input pre_release_version is not empty, but does not match the regex pattern ^[a-z.0-9]+$"
exit 1
else
echo "release-tag: $RELEASE_VERSION"
echo "release-tag=$RELEASE_VERSION" >> $GITHUB_OUTPUT
fi
else
echo "Version input doesn't match the regex pattern ^v[0-9]+\.[0-9]+\.[0-9]+$"
exit 1
fi
- name: Checkout
uses: actions/checkout@v3.5.3
with:
fetch-depth: 0
- name: Create Release Branch if it does not exist
run: |
if ! git show-ref --verify --quiet "refs/remotes/origin/$RELEASE_BRANCH"; then
git checkout -b $RELEASE_BRANCH
git push --set-upstream origin $RELEASE_BRANCH
elif [[ $(git rev-parse --abbrev-ref HEAD) != "$RELEASE_BRANCH" ]]; then
echo "Current Branch: $(git rev-parse --abbrev-ref HEAD)"
echo "Release branch exists, make sure you're using the workflow from the release branch or delete the existing release branch."
exit 1
else
echo "Release branch exists and used as workflow ref."
fi
- name: Get Latest Release
id: get-release
run: |
if [[ -n $PRE_RELEASE_VERSION ]]; then
echo "Get the latest release"
tag=$(curl -L \
--header "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/${{ github.repository }}/releases" | jq -r '.[0].tag_name')
echo "latest-tag=$tag" >> $GITHUB_OUTPUT
else
echo "Get the latest stable release"
tag=$(curl -L \
--header "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/${{ github.repository }}/releases/latest" | jq -r '.tag_name')
echo "latest-tag=$tag" >> $GITHUB_OUTPUT
fi
- name: Build Changelog
id: build-changelog
env:
PREVIOUS_VERSION: ${{ steps.get-release.outputs.latest-tag }}
run: |
CHANGELOG=$(curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ github.token }}"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ github.repository }}/releases/generate-notes \
-d '{"tag_name":"${{ env.RELEASE_VERSION }}","target_commitish":"${{ env.RELEASE_BRANCH }}","previous_tag_name":"${{ env.PREVIOUS_VERSION }}","configuration_file_path":".github/release.yml"}' \
| jq -r '.body')
# The EOF steps are used to save multiline string in github:
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#example-of-a-multiline-string
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "changelog<<$EOF" >> $GITHUB_OUTPUT
echo -e "${CHANGELOG}" >> $GITHUB_OUTPUT
echo "$EOF" >> $GITHUB_OUTPUT
- name: Update Changelog
if: ${{ env.PRE_RELEASE_VERSION == '' }}
env:
CHANGELOG_CONTENT: ${{ steps.build-changelog.outputs.changelog }}
PREVIOUS_VERSION: ${{ steps.get-release.outputs.latest-tag }}
run: |
echo -e "# ${RELEASE_VERSION}\n\n${CHANGELOG_CONTENT}\n" | cat - CHANGELOG.md > temp && mv temp CHANGELOG.md
- name: Commit Changes
uses: EndBug/add-and-commit@v9.1.3
env:
RELEASE_TAG: ${{ steps.set-release.outputs.release-tag }}
with:
message: "bump up version to ${{ env.RELEASE_TAG }}"
- name: Create Pull Request to Master
env:
CHANGELOG_CONTENT: ${{ steps.build-changelog.outputs.changelog }}
PREVIOUS_VERSION: ${{ steps.get-release.outputs.latest-tag }}
GH_TOKEN: ${{ github.token }}
RELEASE_TAG: ${{ steps.set-release.outputs.release-tag }}
run: |
# Note: There's an issue adding teams as reviewers, see https://github.com/cli/cli/issues/6395
PULL_REQUEST_URL=$(gh pr create --base "master" \
--title "FOR REVIEW ONLY: ${{ github.event.repository.name }} $RELEASE_TAG" \
--label "Skip-Release-Notes" \
--label "Team Hyper Flow" \
--body "${CHANGELOG_CONTENT}" | tail -n 1)
if [[ $PULL_REQUEST_URL =~ ^https://github.com/${{ github.repository }}/pull/[0-9]+$ ]]; then
PULL_REQUEST_NUM=$(echo $PULL_REQUEST_URL | sed 's:.*/::')
echo "pull-request-master=$PULL_REQUEST_URL" >> $GITHUB_ENV
echo "pull-request-master-num=$PULL_REQUEST_NUM" >> $GITHUB_ENV
echo "Pull request to Master created: $PULL_REQUEST_URL"
else
echo "There was an issue creating the pull request to master branch."
exit 1
fi
- name: Create Pull Request to Develop
if: ${{ env.PRE_RELEASE_VERSION == '' }}
env:
GH_TOKEN: ${{ github.token }}
RELEASE_TAG: ${{ steps.set-release.outputs.release-tag }}
run: |
# Note: There's an issue adding teams as reviewers, see https://github.com/cli/cli/issues/6395
PULL_REQUEST_URL=$(gh pr create --base "develop" \
--title "FOR REVIEW ONLY: Merge back ${{ github.event.repository.name }} $RELEASE_TAG to develop" \
--label "Skip-Release-Notes" \
--label "Team Hyper Flow" \
--body "Merge back version changes to develop." | tail -n 1)
if [[ $PULL_REQUEST_URL =~ ^https://github.com/${{ github.repository }}/pull/[0-9]+$ ]]; then
echo "Pull request to Develop created: $PULL_REQUEST_URL"
DEVELOP_PR_MESSAGE="\nPull Request to develop: $PULL_REQUEST_URL"
echo "pull-request-develop-message=$DEVELOP_PR_MESSAGE" >> $GITHUB_ENV
else
echo "There was an issue creating the pull request to develop branch."
exit 1
fi
- name: Send Slack Message
id: slack
uses: slackapi/slack-github-action@v1.24.0
env:
RELEASE_TAG: ${{ steps.set-release.outputs.release-tag }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
SDK_DEPLOYMENT_URL: ${{ secrets.SDK_DEPLOYMENT_URL }}
with:
payload: |
{
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "${{ github.event.repository.name }} Release PR for ${{ env.RELEASE_TAG }}"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Approvals needed for*:\nPull Request to master: ${{ env.pull-request-master}}${{ env.pull-request-develop-message }}"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*After approvals*\nDeploy SDK using the <${{ env.SDK_DEPLOYMENT_URL }}|Deployment Pipeline> with the following parameters:\n*SDK*: ${{ github.event.repository.name }}\n*RELEASE_PR_NUM*: ${{ env.pull-request-master-num }}\n*RELEASE_VERSION*: ${{ env.RELEASE_VERSION }}\n*PRE_RELEASE_VERSION*: ${{ env.PRE_RELEASE_VERSION }}"
}
}
]
}