Repository navigation
112 lines (100 loc) · 3.84 KB
/
Copy pathautomerge-check.yml
File metadata and controls
112 lines (100 loc) · 3.84 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
name: Automerge Check
on:
pull_request_target:
branches:
- master
types: [opened, synchronize, reopened]
jobs:
detect:
uses: ./.github/workflows/detect-non-template-changes.yml
permissions:
contents: read
pull-requests: read
automerge-check:
needs: detect
runs-on: ubuntu-26.04
permissions:
pull-requests: write
contents: write
steps:
- name: Setup refs
id: setup-refs
run: |
echo "base_sha=${{ github.event.pull_request.base.sha }}" >> "$GITHUB_OUTPUT"
echo "head_sha=${{ github.event.pull_request.head.sha }}" >> "$GITHUB_OUTPUT"
- name: Check out code
uses: actions/checkout@v7
with:
fetch-depth: 2
ref: ${{ steps.setup-refs.outputs.head_sha }}
allow-unsafe-pr-checkout: true
- name: Get changed JSON files
id: changed-json-files
uses: tj-actions/changed-files@9426d40962ed5378910ee2e21d5f8c6fcbf2dd96 # v47.0.6
with:
files: '*.json'
files_ignore: '.github/**'
# PRs changing non-template files always go to manual review.
- name: Decide whether to run the linter
id: decide
env:
NON_TEMPLATE_CHANGED: ${{ needs.detect.outputs.non_template_changed }}
ANY_JSON_CHANGED: ${{ steps.changed-json-files.outputs.any_changed }}
run: |
if [ "$NON_TEMPLATE_CHANGED" = "true" ]; then
echo "Non-template files changed, skipping automerge check"
echo "run_linter=false" >> "$GITHUB_OUTPUT"
elif [ "$ANY_JSON_CHANGED" != "true" ]; then
echo "No JSON files changed, skipping automerge check"
echo "run_linter=false" >> "$GITHUB_OUTPUT"
else
echo "run_linter=true" >> "$GITHUB_OUTPUT"
fi
- name: Set up Go
if: steps.decide.outputs.run_linter == 'true'
uses: actions/setup-go@v7
with:
go-version: '^1.22'
- name: Install dc-template-linter
if: steps.decide.outputs.run_linter == 'true'
run: |
go install github.com/Domain-Connect/dc-template-linter@latest
- name: Run linter with merge-or-fail on changed files
id: linter-check
if: steps.decide.outputs.run_linter == 'true'
continue-on-error: true
env:
ALL_CHANGED_FILES: ${{ steps.changed-json-files.outputs.all_changed_files }}
run: |
linter_failed=0
for file in ${ALL_CHANGED_FILES}; do
echo "Checking $file"
if ! $(go env GOPATH)/bin/dc-template-linter --merge-or-fail "$file" > /dev/null 2>&1; then
echo "Linter failed for $file"
linter_failed=1
break
fi
done
if [ $linter_failed -eq 1 ]; then
echo "linter_passed=false" >> "$GITHUB_OUTPUT"
else
echo "linter_passed=true" >> "$GITHUB_OUTPUT"
fi
- name: Add automerge-possible label on success
if: steps.linter-check.outputs.linter_passed == 'true'
env:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
REPO: ${{ github.repository }}
run: |
echo "Linter passed, adding automerge-possible label"
gh pr edit "$PR_NUMBER" --repo "$REPO" --add-label "automerge-possible"
- name: Remove automerge-possible label on failure or skip
if: steps.linter-check.outputs.linter_passed != 'true'
env:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
REPO: ${{ github.repository }}
run: |
echo "Linter failed or skipped, removing automerge-possible label if present"
gh pr edit "$PR_NUMBER" --repo "$REPO" --remove-label "automerge-possible" 2>/dev/null || true