-
Notifications
You must be signed in to change notification settings - Fork 22
116 lines (99 loc) · 3.55 KB
/
PR-Validator.yaml
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
name: PR Validator
on:
pull_request:
paths:
- "oci/*/*.y*ml"
jobs:
get-submitted-files:
runs-on: ubuntu-22.04
name: Get submitted files
outputs:
changed-files-matrix: ${{ steps.changed-files-matrix.outputs.matrix }}
image-name: ${{ steps.changed-files-dir-names.outputs.all_changed_files }}
steps:
- uses: actions/checkout@v4
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v35
with:
json: true
files: |
oci/*/*.y*ml
- name: Get image name
id: changed-files-dir-names
uses: tj-actions/changed-files@v35
with:
dir_names: "true"
files: |
oci/*/*.y*ml
- name: Only 1 image can be changed per PR
run: |
set -eux
dir_names="${{ steps.changed-files-dir-names.outputs.all_changed_files }}"
echo "Can only modify 1 image per PR"
(( $(echo "${dir_names}" | wc -w) == 1 ))
- name: Save matrix layout for file validation
id: changed-files-matrix
run: |
echo 'Changed files are: ${{ steps.changed-files.outputs.all_changed_files }}'
echo "matrix={\"filename\":${{ steps.changed-files.outputs.all_changed_files }}}" >> "$GITHUB_OUTPUT"
check-missing-files:
runs-on: ubuntu-22.04
name: Check for missing files
needs: [get-submitted-files]
# temporarily continue on error, until the Notification and Doc update jobs are set
continue-on-error: true
steps:
- uses: actions/checkout@v4
- name: Check if documentation.yaml exists
uses: andstor/file-existence-action@v2
with:
files: "${{ needs.get-submitted-files.outputs.image-name }}/documentation.yaml"
fail: true
- name: Check if contacts.yaml exists
uses: andstor/file-existence-action@v2
with:
files: "${{ needs.get-submitted-files.outputs.image-name }}/contacts.yaml"
fail: true
validate-submitted-files:
runs-on: ubuntu-22.04
name: Validate files
needs: [get-submitted-files]
strategy:
fail-fast: true
matrix: ${{ fromJSON(needs.get-submitted-files.outputs.changed-files-matrix) }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Validate YAML format
run: |
set -eux
pip install yamllint
yamllint -c .yamllint.yaml ${{ matrix.filename }}
- name: Validate documentation trigger file
if: ${{ contains(matrix.filename, 'documentation.yaml') }}
run: |
pip install -r src/docs/requirements.txt
python3 -c '
import src.docs.generate_oci_doc_yaml as OCIDoc
OCIDoc.OCIDocumentationData.read_documentation_yaml("${{ matrix.filename }}")
'
update-pr:
runs-on: ubuntu-22.04
name: Add comment to PR
needs: [get-submitted-files, check-missing-files, validate-submitted-files]
if: ${{ always() && contains(needs.*.result, 'failure') }}
permissions:
pull-requests: write
steps:
- uses: actions/checkout@v4
- name: Comment PR
uses: thollander/actions-comment-pull-request@v2
with:
message: |
One or more files in this PR are not valid! :grimacing:
_Run ID: **${{ github.run_id }}** ; Attempt: **${{ github.run_attempt }}**_
See [logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}).
reactions: eyes