-
Notifications
You must be signed in to change notification settings - Fork 0
381 lines (343 loc) · 11.2 KB
/
ci.yml
File metadata and controls
381 lines (343 loc) · 11.2 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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
name: Continuous Integration
on:
pull_request:
push:
branches:
- main
paths-ignore:
- '.github/workflows/**'
- '**/*.md'
- 'test/**'
- 'backup/**'
workflow_dispatch:
permissions:
contents: write
jobs:
unit-tests:
name: Unit Tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup Go
uses: actions/setup-go@v6
with:
go-version: '1.26'
- name: Run Go unit tests with coverage
run: go test ./internal/... -v -cover -coverprofile=coverage.out
- name: Display coverage summary
run: go tool cover -func=coverage.out
build-and-push-docker:
name: Build and Push Docker
needs: unit-tests
runs-on: ubuntu-latest
services:
registry:
image: registry:2
ports:
- 5001:5000
env:
TEST_TAG: localhost:5001/actions/go-git-commit-action:latest
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 10
token: ${{ secrets.PAT_TOKEN }}
- name: Configure Git Safe Directory
run: git config --global --add safe.directory ${{ github.workspace }}
- name: Setup Docker BuildX
uses: docker/setup-buildx-action@v4
with:
install: true
driver-opts: network=host
- name: Build the Container
uses: docker/build-push-action@v7
with:
context: .
push: true
tags: ${{ env.TEST_TAG }}
- name: Create Test File
run: |
echo "$(date +%s)-$RANDOM" > test/test1.txt
- name: Run the Container
env:
USER_EMAIL: actions@github.com
USER_NAME: GitHub Actions
COMMIT_MESSAGE: test1 ${{ github.run_id }}!
BRANCH: test
REPOSITORY_PATH: test
FILE_PATTERN: .
TAG_NAME: test1-${{ github.run_id }}
TAG_MESSAGE: test1 ${{ github.run_id }}
TAG_REFERENCE: v1.0.1
run: |
docker run \
--env INPUT_USER_EMAIL="${{ env.USER_EMAIL }}" \
--env INPUT_USER_NAME="${{ env.USER_NAME }}" \
--env INPUT_COMMIT_MESSAGE="${{ env.COMMIT_MESSAGE }}" \
--env INPUT_BRANCH="${{ env.BRANCH }}" \
--env INPUT_REPOSITORY_PATH="${{ env.REPOSITORY_PATH }}" \
--env INPUT_FILE_PATTERN="${{ env.FILE_PATTERN }}" \
--env INPUT_TAG_NAME="${{ env.TAG_NAME }}" \
--env INPUT_TAG_MESSAGE="${{ env.TAG_MESSAGE }}" \
--env INPUT_TAG_REFERENCE="${{ env.TAG_REFERENCE }}" \
--env GITHUB_TOKEN="${{ secrets.PAT_TOKEN }}" \
--volume ${{ github.workspace }}:/app \
--rm ${{ env.TEST_TAG }}
- name: Confirm Tag Reference
run: |
git show -1 v1.0.1
git show -1 test1-${{ github.run_id }}
- name: Delete Tag
env:
USER_EMAIL: actions@github.com
USER_NAME: GitHub Actions
BRANCH: main
TAG_NAME: test1-${{ github.run_id }}
TAG_MESSAGE: test1 ${{ github.run_id }}
run: |
docker run \
--env INPUT_USER_EMAIL="${{ env.USER_EMAIL }}" \
--env INPUT_USER_NAME="${{ env.USER_NAME }}" \
--env INPUT_BRANCH="${{ env.BRANCH }}" \
--env INPUT_TAG_NAME="${{ env.TAG_NAME }}" \
--env INPUT_DELETE_TAG="true" \
--env GITHUB_TOKEN="${{ secrets.PAT_TOKEN }}" \
--volume ${{ github.workspace }}:/app \
--rm ${{ env.TEST_TAG }}
test-action-auto-branch-false:
name: Test Auto Branch False
runs-on: ubuntu-latest
needs: build-and-push-docker
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 10
- name: Test Auto Branch Local Action (auto_branch false)
uses: ./
with:
user_email: actions@github.com
user_name: GitHub Actions
branch: test
create_pr: true
auto_branch: false
pr_title: test-pr-title
pr_base: main
pr_branch: test
pr_labels: "test,automated,auto-branch-false-test"
repository_path: test
file_pattern: .
github_token: ${{ secrets.PAT_TOKEN }}
pr_closed: true
test-action-auto-branch-true:
name: Test Auto Branch True
runs-on: ubuntu-latest
needs: [build-and-push-docker, test-action-auto-branch-false]
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 10
token: ${{ secrets.PAT_TOKEN }}
- name: Create Test File
run: |
echo "$(date +%s)-$RANDOM" > test/test2.txt
- name: Test Auto Branch Local Action (auto_branch true)
uses: ./
with:
user_email: actions@github.com
user_name: GitHub Actions
branch: test
create_pr: true
auto_branch: true
pr_base: main
pr_labels: "test,automated,auto-branch-true-test"
repository_path: test
file_pattern: .
delete_source_branch: true
github_token: ${{ secrets.PAT_TOKEN }}
pr_closed: true
test-skip-if-empty:
name: Test Skip If Empty
runs-on: ubuntu-latest
needs: [test-action-auto-branch-true]
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 10
token: ${{ secrets.PAT_TOKEN }}
- name: Test Skip If Empty (should skip - no changes)
id: skip-test
uses: ./
with:
user_email: actions@github.com
user_name: GitHub Actions
branch: test
create_pr: true
auto_branch: false
pr_base: main
pr_branch: test
repository_path: test
file_pattern: .
skip_if_empty: true
pr_title: "Test Skip If Empty - No Changes (should skip)"
pr_labels: "test,automated,skip-if-empty-test"
github_token: ${{ secrets.PAT_TOKEN }}
pr_closed: true
- name: Verify Skip Output
run: |
echo "skipped=${{ steps.skip-test.outputs.skipped }}"
echo "changed_files=${{ steps.skip-test.outputs.changed_files }}"
if [ "${{ steps.skip-test.outputs.skipped }}" != "true" ]; then
echo "FAIL: expected skipped=true"
exit 1
fi
echo "PASS: skip output verified"
# Verify skip does not happen when changes exist
- name: Create Test File
run: |
echo "$(date +%s)-$RANDOM" > test/skip-test.txt
- name: Test Skip If Empty (should not skip - with changes)
id: no-skip-test
uses: ./
with:
user_email: actions@github.com
user_name: GitHub Actions
branch: test
create_pr: true
auto_branch: true
pr_base: main
pr_labels: "test,automated,skip-if-empty-test"
repository_path: test
delete_source_branch: true
file_pattern: .
skip_if_empty: true
pr_title: "Test Skip If Empty - With Changes (should not skip)"
github_token: ${{ secrets.PAT_TOKEN }}
pr_closed: true
- name: Verify No-Skip Output
run: |
echo "skipped=${{ steps.no-skip-test.outputs.skipped }}"
echo "changed_files=${{ steps.no-skip-test.outputs.changed_files }}"
echo "pr_number=${{ steps.no-skip-test.outputs.pr_number }}"
echo "pr_url=${{ steps.no-skip-test.outputs.pr_url }}"
if [ "${{ steps.no-skip-test.outputs.skipped }}" = "true" ]; then
echo "FAIL: expected skipped!=true"
exit 1
fi
echo "PASS: no-skip output verified"
test-pr-auto-close-pr-body:
name: Test PR Auto Close
runs-on: ubuntu-latest
needs: [test-skip-if-empty]
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 10
token: ${{ secrets.PAT_TOKEN }}
- name: Configure Git Safe Directory
run: git config --global --add safe.directory ${{ github.workspace }}
- name: Test PR Auto Close
uses: ./
with:
user_email: actions@github.com
user_name: GitHub Actions
branch: test
pr_branch: test
create_pr: true
pr_base: main
repository_path: test
file_pattern: .
pr_closed: true
pr_labels: "test,automated,auto-close-pr-body-test"
pr_title: "Test Auto Close PR"
pr_body: |
## Test Auto Close PR
This PR will be automatically closed after creation.
github_token: ${{ secrets.PAT_TOKEN }}
test-pr-dry-run:
name: Test PR Dry Run
runs-on: ubuntu-latest
needs: [test-pr-auto-close-pr-body]
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 10
token: ${{ secrets.PAT_TOKEN }}
- name: Test PR Dry Run (auto_branch false)
uses: ./
with:
user_email: actions@github.com
user_name: GitHub Actions
branch: main
create_pr: true
auto_branch: false
pr_title: "Test PR Dry Run"
pr_base: test
pr_branch: main
pr_labels: "test,automated,dry-run-test"
repository_path: "test"
file_pattern: "pr-dry-run-test.txt"
github_token: ${{ secrets.PAT_TOKEN }}
pr_dry_run: true
- name: Test PR Dry Run with Draft
uses: ./
with:
user_email: actions@github.com
user_name: GitHub Actions
branch: main
create_pr: true
auto_branch: false
pr_title: "Test PR Dry Run (Draft)"
pr_base: test
pr_branch: main
pr_labels: "test,automated,draft-pr-test"
repository_path: "test"
file_pattern: "pr-dry-run-test.txt"
github_token: ${{ secrets.PAT_TOKEN }}
pr_draft: true
pr_dry_run: true
- name: Test PR Dry Run with Reviewers and Assignees
uses: ./
with:
user_email: actions@github.com
user_name: GitHub Actions
branch: main
create_pr: true
auto_branch: false
pr_title: "Test PR Dry Run (Reviewers/Assignees)"
pr_base: test
pr_branch: main
pr_labels: "test,automated,reviewers-test"
pr_reviewers: "somaz94"
pr_assignees: "somaz94"
repository_path: "test"
file_pattern: "pr-dry-run-test.txt"
github_token: ${{ secrets.PAT_TOKEN }}
pr_dry_run: true
ci-result:
name: CI Result
if: always()
needs:
- unit-tests
- build-and-push-docker
- test-action-auto-branch-false
- test-action-auto-branch-true
- test-skip-if-empty
- test-pr-auto-close-pr-body
- test-pr-dry-run
runs-on: ubuntu-latest
steps:
- name: Check all jobs
run: |
if [ "${{ contains(needs.*.result, 'failure') }}" = "true" ] || \
[ "${{ contains(needs.*.result, 'cancelled') }}" = "true" ]; then
echo "[FAIL]Some jobs failed or were cancelled"
exit 1
fi
echo "[PASS]All CI jobs passed"