-
Notifications
You must be signed in to change notification settings - Fork 12
87 lines (86 loc) · 3.77 KB
/
promote.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
name: Promote Dispatch
on:
repository_dispatch:
types: [promote-command]
jobs:
promote-release:
runs-on: ubuntu-latest
env:
URL: ${{ secrets.RELEASE_NOTIFICATON_URL }}
steps:
- name: Set Env Variables
id: env_info
run: |
echo ::set-output name=issuetitle::$(jq -r .client_payload.github.payload.issue.title $GITHUB_EVENT_PATH)
echo ::set-output name=issuenm::$(jq .client_payload.github.payload.issue.number $GITHUB_EVENT_PATH)
echo ::set-output name=labels::$(jq .client_payload.github.payload.issue.labels $GITHUB_EVENT_PATH)
echo ::set-output name=requestor::$(jq .client_payload.github.actor $GITHUB_EVENT_PATH)
- name: Set New Env (Integration)
if: ${{ !contains(steps.env_info.outputs.labels, 'promoted to integration') }}
run: |
echo "NEW_ENV=integration" >> $GITHUB_ENV
- name: Set New Env (Production)
if: ${{ contains(steps.env_info.outputs.labels, 'promoted to integration') }}
run: |
echo "NEW_ENV=production" >> $GITHUB_ENV
- uses: actions/checkout@v3
with:
ref: ${{ steps.env_info.outputs.issuetitle }}
- name: GitHub Pull Request Action
id: create_pr
uses: repo-sync/[email protected]
with:
source_branch: ${{ steps.env_info.outputs.issuetitle }}
destination_branch: ${{ env.NEW_ENV }}
github_token: ${{ secrets.GITHUB_TOKEN }}
pr_title: "Promoting ${{ steps.env_info.outputs.issuetitle }} to ${{ env.NEW_ENV }}"
pr_body: "Promoting release ${{ steps.env_info.outputs.issuetitle }} to the $NEW_ENV environment as requested by @${{ steps.env_info.outputs.requestor }}."
- name: Get PR number
id: pr_num
run: |
echo ::set-output name=prnm::$( echo ${{ steps.create_pr.outputs.pr_url }} | awk -F'/' '{print $NF}')
# - name: Auto-merge
# uses: actions/github-script@v2
# with:
# github-token: ${{ secrets.GITHUB_TOKEN }}
# script: |
# github.pulls.merge({
# owner: context.repo.owner,
# repo: context.repo.repo,
# pull_number: ${{ steps.pr_num.outputs.prnm}},
# merge_method: "squash"
# })
- name: Apply label to issue
uses: actions/github-script@v1
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
github.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{steps.env_info.outputs.issuenm}},
labels: ["promoted to ${{ env.NEW_ENV }}"]
})
- name: Create comment
uses: peter-evans/create-or-update-comment@v1
with:
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
issue-number: "${{ steps.env_info.outputs.issuenm }}"
body: |
Promoted release ${{ steps.env_info.outputs.issuetitle }} to ${{ env.NEW_ENV }}!
- name: Notify chat
run: |
echo "Thread key GITHUB_REPOSITORY-${{ steps.env_info.outputs.issuenm }} "
[ ! -z "$URL" ] && curl "$URL&threadKey=$GITHUB_REPOSITORY-${{ steps.env_info.outputs.issuenm}}" -H "Content-Type: application/json" -d '{ "text" : "Promoted release *${{ steps.env_info.outputs.issuetitle }}* to *${{ env.NEW_ENV }}*" }'
# - name: Delete branch
# if: ${{ env.NEW_ENV == 'production' }}
# uses: dawidd6/action-delete-branch@v3
# with:
# github_token: ${{ github.token }}
# branches: ${{ steps.env_info.outputs.issuetitle }}
# - name: Close Issue
# if: ${{ env.NEW_ENV == 'production' }}
# uses: peter-evans/close-issue@v1
# with:
# issue-number: ${{ steps.env_info.outputs.issuenm }}
# comment: Rollout completed by ${{ steps.env_info.outputs.requestor }} - closing issue.