-
Notifications
You must be signed in to change notification settings - Fork 22
196 lines (189 loc) · 7.37 KB
/
master-CI.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
name: Continuous integration
on:
push:
branches:
- master
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: dprint/check@v1.5
- uses: actions/setup-node@v1
- run: yarn install
- run: yarn test
create-pr:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: |
git config user.email noreply@github.com
git config user.name "GitHub actions"
git checkout -b feature/test/${{ github.sha }}
echo date > current-date.txt
git add current-date.txt
git commit --message "Some changes"
git push origin feature/test/${{ github.sha }}
- uses: ./
id: create-pr
with:
head: feature/test/${{ github.sha }}
title: Testing commit ${{ github.sha }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Validate that PR exists
run: curl --fail https://api.github.com/repos/${{ github.repository }}/pulls/${{ steps.create-pr.outputs.number }}
- name: Close PR
run: |
curl \
-X PATCH \
-H 'Accept: application/vnd.github.v3+json' \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
https://api.github.com/repos/${{ github.repository }}/pulls/${{ steps.create-pr.outputs.number }} \
-d '{"state":"closed"}'
if: always()
create-draft-pr:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: |
git config user.email noreply@github.com
git config user.name "GitHub actions"
git checkout -b feature/test/${{ github.sha }}-draft
echo date > current-date.txt
git add current-date.txt
git commit --message "Some changes"
git push origin feature/test/${{ github.sha }}-draft
- uses: ./
id: create-draft-pr
with:
head: feature/test/${{ github.sha }}-draft
title: Testing commit ${{ github.sha }}
draft: true
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Validate that PR exists
run: |
curl \
-H 'Accept: application/vnd.github.shadow-cat-preview+json' \
https://api.github.com/repos/${{ github.repository }}/pulls/${{ steps.create-draft-pr.outputs.number }} \
--fail \
- name: Close PR
run: |
curl \
-X PATCH \
-H 'Accept: application/vnd.github.v3+json' \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
https://api.github.com/repos/${{ github.repository }}/pulls/${{ steps.create-draft-pr.outputs.number }} \
-d '{"state":"closed"}'
if: always()
create-pr-with-reviewers:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: |
git config user.email noreply@github.com
git config user.name "GitHub actions"
git checkout -b feature/test/${{ github.sha }}-reviewers
echo date > current-date.txt
git add current-date.txt
git commit --message "Some changes"
git push origin feature/test/${{ github.sha }}-reviewers
- uses: ./
id: create-pr-with-reviewers
with:
head: feature/test/${{ github.sha }}-reviewers
title: Testing commit ${{ github.sha }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
reviewers: ${{ github.actor }}
- name: Validate that PR exists
run: curl --fail https://api.github.com/repos/${{ github.repository }}/pulls/${{ steps.create-pr-with-reviewers.outputs.number }}
- name: Close PR
run: |
curl \
-X PATCH \
-H 'Accept: application/vnd.github.v3+json' \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
https://api.github.com/repos/${{ github.repository }}/pulls/${{ steps.create-pr-with-reviewers.outputs.number }} \
-d '{"state":"closed"}'
if: always()
create-pr-with-labels:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: |
git config user.email noreply@github.com
git config user.name "GitHub actions"
git checkout -b feature/test/${{ github.sha }}-labels
echo date > current-date.txt
git add current-date.txt
git commit --message "Some changes"
git push origin feature/test/${{ github.sha }}-labels
- uses: ./
id: create-pr-with-labels
with:
head: feature/test/${{ github.sha }}-labels
title: Testing commit ${{ github.sha }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
labels: label1,label2
- name: Validate that PR exists
run: curl --fail https://api.github.com/repos/${{ github.repository }}/pulls/${{ steps.create-pr-with-labels.outputs.number }}
- name: Close PR
run: |
curl \
-X PATCH \
-H 'Accept: application/vnd.github.v3+json' \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
https://api.github.com/repos/${{ github.repository }}/pulls/${{ steps.create-pr-with-labels.outputs.number }} \
-d '{"state":"closed"}'
if: always()
do-not-fail-on-existing_pr:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: |
git config user.email noreply@github.com
git config user.name "GitHub actions"
git checkout -b feature/test/${{ github.sha }}-idempotent-case
echo date > current-date.txt
git add current-date.txt
git commit --message "Some changes"
git push origin feature/test/${{ github.sha }}-idempotent-case
- uses: ./
id: create-pr
with:
head: feature/test/${{ github.sha }}-idempotent-case
title: Testing commit ${{ github.sha }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Validate that PR exists
run: curl --fail https://api.github.com/repos/${{ github.repository }}/pulls/${{ steps.create-pr.outputs.number }}
- uses: ./
id: second-create-pr
with:
head: feature/test/${{ github.sha }}-idempotent-case
title: Testing commit ${{ github.sha }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Validate that only first PR is created
run: |
if [ "${{ steps.create-pr.outputs.created }}" != "true" ]
then
echo "First PR is not created: ${{ steps.create-pr.outputs.created }}"
exit 1
fi
if [ "${{ steps.second-create-pr.outputs.created }}" != "false" ]
then
echo "Second PR is created: ${{ steps.second-create-pr.outputs.created }}"
exit 1
fi
- name: Close PR
run: |
curl \
-X PATCH \
-H 'Accept: application/vnd.github.v3+json' \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
https://api.github.com/repos/${{ github.repository }}/pulls/${{ steps.create-pr.outputs.number }} \
-d '{"state":"closed"}'
if: always()