-
Notifications
You must be signed in to change notification settings - Fork 1
188 lines (165 loc) · 5.93 KB
/
pull-request.yml
File metadata and controls
188 lines (165 loc) · 5.93 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
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
name: "PR: Create"
on:
push:
branches-ignore:
- master
- main
- develop
- "release/**"
- "hotfix/**"
permissions:
contents: read
pull-requests: write
concurrency:
group: ${{github.workflow}}-${{github.ref}}
cancel-in-progress: true
env:
HEAD_REF: ${{github.head_ref}}
BASE_REF: ${{github.base_ref}}
REPO: ${{github.repository}}
REPO_OWNER: ${{github.repository_owner}}
jobs:
info:
runs-on: [self-hosted, linux, build]
steps:
- name: "Initialise Workspace"
if: runner.environment == 'self-hosted'
shell: bash
run: sudo chown -R "$USER:$USER" "$GITHUB_WORKSPACE"
- name: "Set Active Environment"
id: active-env
shell: bash
run: |
{
echo "ACTIVE_RUNNER_NAME=${{runner.name}}"
echo "ACTIVE_HOSTNAME=$HOSTNAME"
echo "ACTIVE_USER=$USER"
} >> "$GITHUB_OUTPUT"
- name: "Info"
uses: actions/github-script@v8.0.0
with:
script: |
core.info('Branch: ${{env.HEAD_REF}}');
core.info('Base Branch: ${{env.BASE_REF}}');
core.info('Repo: ${{env.REPO}}');
core.info('Owner: ${{env.REPO_OWNER}}');
pull-request:
runs-on: [self-hosted, linux, build]
env:
CREATE_DRAFT: true
REPO_STATUS: private
steps:
- name: "Initialise Workspace"
if: runner.environment == 'self-hosted'
shell: bash
run: sudo chown -R "$USER:$USER" "$GITHUB_WORKSPACE"
- name: "Set Active Environment"
id: active-env
shell: bash
run: |
{
echo "ACTIVE_RUNNER_NAME=${{runner.name}}"
echo "ACTIVE_HOSTNAME=$HOSTNAME"
echo "ACTIVE_USER=$USER"
} >> "$GITHUB_OUTPUT"
- name: "Checkout source"
uses: actions/checkout@v6.0.2
with:
clean: true
fetch-depth: 1
fetch-tags: true
- name: "Find PR For branch"
uses: juliangruber/find-pull-request-action@v1.11.0
id: findPr
with:
branch: ${{github.ref_name}}
- name: "Existing PR Information"
if: steps.findPr.outputs.number != ''
uses: actions/github-script@v8.0.0
with:
script: |
core.info('Pull request already exists with id: ${{steps.findPr.outputs.number}}');
core.info('URL: https://github.com/${{env.REPO}}/pull/${{steps.findPr.outputs.number}}');
- name: "Read PR Template"
if: steps.findPr.outputs.number == ''
id: pr-template
uses: juliangruber/read-file-action@v1.1.8
with:
path: ./.github/PULL_REQUEST_TEMPLATE.md
- name: "Get last commit info"
if: steps.findPr.outputs.number == ''
id: commit-info
shell: bash
run: |
title="$(git log -1 --pretty=%s)"
echo "commit-title=$title" >> "$GITHUB_OUTPUT"
- name: "Check Required Secrets"
if: env.REPO_STATUS == '' &&steps.findPr.outputs.number == ''
shell: bash
run: |
if [ -z "${{secrets.SOURCE_PUSH_TOKEN}}" ]; then
echo "::error::SOURCE_PUSH_TOKEN is required but not set"
exit 1
fi
- name: "Check Repo Visibility"
if: env.REPO_STATUS == '' &&steps.findPr.outputs.number == ''
uses: credfeto/action-repo-visibility@v1.2.0
id: visibility
with:
repository: ${{env.REPO}}
token: ${{secrets.SOURCE_PUSH_TOKEN}}
- name: "Override DRAFT Flag"
id: draft-flag
if: |-
steps.findPr.outputs.number == ''
&& env.REPO_OWNER != 'funfair-tech'
&& env.REPO_STATUS == 'private'
shell: bash
run: echo "create-draft=false" >> "$GITHUB_OUTPUT"
- name: "Status"
uses: actions/github-script@v8.0.0
with:
script: |
core.info('Repo: ${{env.REPO}}');
core.info('Owner: ${{env.REPO_OWNER}}');
core.info('Repo Status: ${{env.REPO_STATUS}}');
core.info('PR OK: ${{steps.findPr.outputs.number == ''}}');
core.info('Owner OK: ${{env.REPO_OWNER != 'funfair-tech'}}');
core.info('Status OK: ${{env.REPO_STATUS == 'private'}}');
- name: "Create Pull Request"
if: steps.findPr.outputs.number == ''
id: open-pr
uses: repo-sync/pull-request@v2.12
with:
source_branch: "" # If blank, default: triggered branch
destination_branch: "main" # If blank, default: master
pr_assignee: ${{github.actor}} # Comma-separated list (no spaces)
pr_label: "auto-pr" # Comma-separated list (no spaces)
pr_draft: ${{steps.draft-flag.outputs.create-draft || env.CREATE_DRAFT}} # Creates pull request as draft
pr_title: ${{steps.commit-info.outputs.commit-title}}
pr_body: ${{steps.pr-template.outputs.content}}
github_token: ${{github.token}}
- name: "New PR Details"
if: steps.findPr.outputs.number == ''
uses: actions/github-script@v8.0.0
with:
script: |
core.info('URL: ${{steps.open-pr.outputs.pr_url}}');
core.info('PR: ${{steps.open-pr.outputs.pr_number}}');
core.info('CF: ${{steps.open-pr.outputs.has_changed_files}}');
- name: "Check Required Secrets"
if: steps.findPr.outputs.number == ''
shell: bash
run: |
if [ -z "${{secrets.SOURCE_PUSH_TOKEN}}" ]; then
echo "::error::SOURCE_PUSH_TOKEN is required but not set"
exit 1
fi
- name: "Sync Labels"
if: steps.findPr.outputs.number == ''
uses: actions/labeler@v6
with:
repo-token: ${{secrets.SOURCE_PUSH_TOKEN}}
configuration-path: .github/labeler.yml
sync-labels: true
pr-number: ${{steps.open-pr.outputs.pr_number}}