-
Notifications
You must be signed in to change notification settings - Fork 0
110 lines (92 loc) · 5.14 KB
/
createpr.yml
File metadata and controls
110 lines (92 loc) · 5.14 KB
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
name: CreatePR
on:
workflow_call:
env:
BRANCHCONDITION: ${{ (github.ref != 'refs/heads/master') &&
(github.ref != 'refs/heads/develop') &&
(github.ref != 'refs/heads/developv2') &&
(github.ref != 'refs/heads/pdfxfa-master') &&
(github.ref != 'refs/heads/pdfxfa-develop') &&
(! startsWith(github.ref, 'refs/heads/rebased/')) &&
(! startsWith(github.ref, 'refs/heads/no-rebased/')) &&
(! startsWith(github.ref, 'refs/heads/archive/')) &&
(! startsWith(github.ref, 'refs/heads/android/')) &&
(! startsWith(github.ref, 'refs/heads/7.1/')) &&
(! startsWith(github.ref, 'refs/heads/7.2/')) &&
(! startsWith(github.ref, 'refs/heads/7.3/')) &&
(! startsWith(github.ref, 'refs/heads/8.0/')) &&
(! startsWith(github.ref, 'refs/heads/autoport-')) &&
(! startsWith(github.ref, 'refs/heads/autoport/')) &&
(! startsWith(github.ref, 'refs/heads/release_branch')) &&
(! startsWith(github.ref, 'refs/heads/after_release')) &&
(! startsWith(github.ref, 'refs/heads/master-rc')) &&
(! startsWith(github.ref, 'refs/heads/test-release')) &&
(! startsWith(github.ref, 'refs/heads/test-after-release')) &&
(! startsWith(github.ref, 'refs/heads/internal-master-rc')) }}
jobs:
create_pr:
runs-on: ubuntu-latest
continue-on-error: true
outputs:
email: ${{ steps.get-email.outputs.email }}
prid: ${{ steps.open-pull-request.outputs.prid }}
failure: ${{ steps.failure_handling.outputs.failure }}
branchcondition: ${{ steps.branch-condition.outputs.branchcondition }}
steps:
- name: Branch condition
id: branch-condition
run: |
echo "github.ref: ${{ github.ref }}"
echo "BRANCHCONDITION=$BRANCHCONDITION"
echo "branchcondition=$BRANCHCONDITION" >> $GITHUB_OUTPUT
- name: Get email
id: get-email
if: ${{ (steps.branch-condition.outputs.branchcondition == 'true') }}
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
EMAIL=$(curl --request GET --url "https://api.github.com/users/${{ github.event.sender.login }}" --header "Accept: application/vnd.github+json" --header "X-GitHub-Api-Version: 2022-11-28" --header "Authorization: Bearer $GITHUB_TOKEN" --silent | jq '.email')
echo "email=$EMAIL" >> $GITHUB_OUTPUT
- name: Open pull request
id: open-pull-request
if: ${{ (steps.branch-condition.outputs.branchcondition == 'true') }}
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
PRID=$(curl --request POST --url "https://api.github.com/repos/${{ github.repository }}/pulls" \
--header "Accept: application/vnd.github+json" \
--header "X-GitHub-Api-Version: 2022-11-28" \
--header "Authorization: Bearer $GITHUB_TOKEN" \
--data "{\"title\": \"Pull Request to create/update rebased branch for '${{ github.ref }}'\", \"body\": \"Programmatically created Pull Request to automatically keep merge branch to develop up-to-date\", \"head\": \"${{ github.ref }}\", \"base\": \"develop\"}" \
--silent | jq '.number')
curl --request POST --url "https://api.github.com/repos/${{ github.repository }}/issues/${PRID}/assignees" \
--header "Accept: application/vnd.github+json" \
--header "X-GitHub-Api-Version: 2022-11-28" \
--header "Authorization: Bearer $GITHUB_TOKEN" \
--data "{\"assignees\":[\"${{ github.event.sender.login }}\"]}" \
--silent
echo "prid=$PRID" >> $GITHUB_OUTPUT
- name: Failure handling
if: failure()
id: failure_handling
run: |
FAILURE=${{ true }}
echo "failure=$FAILURE" >> $GITHUB_OUTPUT
notification_success:
needs: [create_pr]
if: (needs.create_pr.outputs.branchcondition == 'true') && (! needs.create_pr.outputs.failure)
uses: ./.github/workflows/sendslackmsgtopusher.yml
secrets: inherit
with:
emailslackuser: ${{ needs.create_pr.outputs.email }}
shortmsg: "Pull request created for '${{ github.ref }}'!"
blocks: "[{\"type\": \"section\", \"text\": {\"type\": \"mrkdwn\", \"text\": \"Pull request created for '${{ github.ref }}': https://github.com/${{ github.repository }}/pull/${{ needs.create_pr.outputs.prid }}\"}}]"
notification_failure:
needs: [create_pr]
if: (needs.create_pr.outputs.branchcondition == 'true') && (needs.create_pr.outputs.failure)
uses: ./.github/workflows/sendslackmsgtopusher.yml
secrets: inherit
with:
emailslackuser: ${{ needs.create_pr.outputs.email }}
shortmsg: "No pull request created for '${{ github.ref }}'!"
blocks: "[{\"type\": \"section\", \"text\": {\"type\": \"mrkdwn\", \"text\": \":alert-beam: No pull request created in '${{ github.server_url }}/${{ github.repository }}':\"}}, {\"type\": \"section\", \"text\": {\"type\": \"mrkdwn\", \"text\": \"Check if '${{ github.ref }}' has changes compared to 'develop' & push again\"}}]"