-
Notifications
You must be signed in to change notification settings - Fork 0
200 lines (178 loc) · 7.43 KB
/
promotion-pull-request.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
195
196
197
198
199
200
name: "Create promotion pull request"
on:
workflow_dispatch:
push:
branches:
- test
- dev
- "feature/**"
- "bugfix/**"
jobs:
promote-test-to-main:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/test'
steps:
- uses: actions/checkout@v4
with:
ref: main
- name: Check if PR exists
id: check
env:
GITHUB_TOKEN: ${{ secrets.WORKFLOW_TOKEN }}
run: |
ref=$(echo $GITHUB_REF | sed 's/refs\/heads\///g')
echo "ref=$ref"
prs=$(gh pr list \
--repo "$GITHUB_REPOSITORY" \
--json baseRefName,headRefName \
--jq "map(select(.baseRefName == \"main\" and .headRefName == \"$ref\")) | length")
if ((prs > 0)); then
echo "setting skip true"
echo "skip=true" >> "$GITHUB_OUTPUT"
else
echo "setting skip false"
echo "skip=false" >> "$GITHUB_OUTPUT"
fi
# If we get "fatal: Invalid revision range id1..id2" we pipe the error to stdout and still get higher than 0,
# which means we fall back to creating a PR if there is an issue by design
diffs=$(git diff --name-status ${{ github.event.before }}..${{ github.event.after }} 2>&1 | wc -l)
echo "diffs=$diffs"
if ((diffs > 0)); then
echo "setting has_diff true"
echo "has_diff=true" >> "$GITHUB_OUTPUT"
else
echo "setting has_diff false"
echo "has_diff=false" >> "$GITHUB_OUTPUT"
fi
- name: Reset promotion branch
if: ${{ steps.check.outputs.skip == 'false' && steps.check.outputs.has_diff == 'true' }}
run: |
git fetch origin test:test
git reset --hard test
- name: Create Pull Request
id: create-pr
uses: peter-evans/create-pull-request@v6
if: ${{ steps.check.outputs.skip == 'false' && steps.check.outputs.has_diff == 'true' }}
with:
token: ${{ secrets.WORKFLOW_TOKEN }}
branch: test
title: Merge test changes to main
body: Automatically created pull-request in order to merge changes that were recently pushed to the test branch, back to main
# assignees: hwinther
draft: true
# Not possible if draft: true above
# - name: Set auto merge on pull request
# if: ${{ steps.check.outputs.skip == 'false' && steps.check.outputs.has_diff == 'true' }}
# env:
# GH_TOKEN: ${{ github.token }}
# PR_URL: ${{ steps.create-pr.outputs.pull-request-url }}
# run: gh pr merge --merge --auto $PR_URL
promote-dev-to-test:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/dev'
steps:
- uses: actions/checkout@v4
with:
ref: test
- name: Check if PR exists
id: check
env:
GITHUB_TOKEN: ${{ secrets.WORKFLOW_TOKEN }}
run: |
ref=$(echo $GITHUB_REF | sed 's/refs\/heads\///g')
echo "ref=$ref"
prs=$(gh pr list \
--repo "$GITHUB_REPOSITORY" \
--json baseRefName,headRefName \
--jq "map(select(.baseRefName == \"test\" and .headRefName == \"$ref\")) | length")
if ((prs > 0)); then
echo "setting skip true"
echo "skip=true" >> "$GITHUB_OUTPUT"
else
echo "setting skip false"
echo "skip=false" >> "$GITHUB_OUTPUT"
fi
# If we get "fatal: Invalid revision range id1..id2" we pipe the error to stdout and still get higher than 0,
# which means we fall back to creating a PR if there is an issue by design
diffs=$(git diff --name-status ${{ github.event.before }}..${{ github.event.after }} 2>&1 | wc -l)
echo "diffs=$diffs"
if ((diffs > 0)); then
echo "setting has_diff true"
echo "has_diff=true" >> "$GITHUB_OUTPUT"
else
echo "setting has_diff false"
echo "has_diff=false" >> "$GITHUB_OUTPUT"
fi
- name: Reset promotion branch
if: ${{ steps.check.outputs.skip == 'false' && steps.check.outputs.has_diff == 'true' }}
run: |
git fetch origin dev:dev
git reset --hard dev
- name: Create Pull Request
id: create-pr
uses: peter-evans/create-pull-request@v6
if: ${{ steps.check.outputs.skip == 'false' && steps.check.outputs.has_diff == 'true' }}
with:
token: ${{ secrets.WORKFLOW_TOKEN }}
branch: dev
title: Merge dev changes to test
body: Automatically created pull-request in order to merge changes that were recently pushed to the dev branch, back to test
# assignees: hwinther
draft: true
# Not possible if draft: true above
# - name: Set auto merge on pull request
# if: ${{ steps.check.outputs.skip == 'false' && steps.check.outputs.has_diff == 'true' }}
# env:
# GH_TOKEN: ${{ github.token }}
# PR_URL: ${{ steps.create-pr.outputs.pull-request-url }}
# run: gh pr merge --merge --auto $PR_URL
# promote-feature-branch-to-dev:
# runs-on: ubuntu-latest
# if: ${{ contains(github.ref, 'refs/heads/feature/') || contains(github.ref, 'refs/heads/bugfix/') }}
# steps:
# - uses: actions/checkout@v4
# with:
# ref: dev
# - name: Check if PR exists
# id: check
# env:
# GITHUB_TOKEN: ${{ secrets.WORKFLOW_TOKEN }}
# run: |
# ref=$(echo $GITHUB_REF | sed 's/refs\/heads\///g')
# echo "ref=$ref"
# prs=$(gh pr list \
# --repo "$GITHUB_REPOSITORY" \
# --json baseRefName,headRefName \
# --jq "map(select(.baseRefName == \"dev\" and .headRefName == \"$ref\")) | length")
# if ((prs > 0)); then
# echo "setting skip true"
# echo "skip=true" >> "$GITHUB_OUTPUT"
# else
# echo "setting skip false"
# echo "skip=false" >> "$GITHUB_OUTPUT"
# fi
# # If we get "fatal: Invalid revision range id1..id2" we pipe the error to stdout and still get higher than 0,
# # which means we fall back to creating a PR if there is an issue by design
# diffs=$(git diff --name-status ${{ github.event.before }}..${{ github.event.after }} 2>&1 | wc -l)
# echo "diffs=$diffs"
# if ((diffs > 0)); then
# echo "setting has_diff true"
# echo "has_diff=true" >> "$GITHUB_OUTPUT"
# else
# echo "setting has_diff false"
# echo "has_diff=false" >> "$GITHUB_OUTPUT"
# fi
# - name: Reset promotion branch
# if: ${{ steps.check.outputs.skip == 'false' && steps.check.outputs.has_diff == 'true' }}
# run: |
# git fetch origin ${{ github.ref }}:${{ github.ref }}
# git reset --hard ${{ github.ref }}
# - name: Create Pull Request
# if: ${{ steps.check.outputs.skip == 'false' && steps.check.outputs.has_diff == 'true' }}
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# REF: ${{ github.ref }}
# TITLE: ${{ github.event.head_commit.message }}
# run: |
# PR_URL=$(gh pr create --base dev --head $REF --title '${TITLE}' --body-file .github/PULL_REQUEST_TEMPLATE.md)
# gh pr merge --squash --auto $PR_URL