-
Notifications
You must be signed in to change notification settings - Fork 2
151 lines (148 loc) · 6.89 KB
/
pr_validate.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
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
name: PR processing
on:
pull_request:
types:
- opened
- synchronize
jobs:
validate_docs_metadata:
name: validate docs metadata
runs-on: ubuntu-latest
env:
MANIFEST_PATH: '_manifest/validation_manifest.json'
permissions:
contents: 'write'
packages: 'read'
actions: 'write'
statuses: 'write'
steps:
- name: Checkout PR
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: install dependencies
run: pip install -r _metadata_validation/requirements.txt
- name: Get changed files
id: changed_files
run: |
export PR_NUMBER="${{ github.event.pull_request.number }}"
export REPO="${{ github.repository }}"
FILES_CHANGED=$(python _metadata_validation/get_pr_files.py)
echo "Changed files: $FILES_CHANGED"
echo "CHANGED_FILES=$FILES_CHANGED" >> $GITHUB_ENV
- name: Run validation
id: run_validation
env:
FILES_TO_TRACK: ${{ env.CHANGED_FILES }}
run: |
echo "starting step..."
if [ -n "${{ env.CHANGED_FILES }}" ]; then
echo "changed files not empty"
if [[ ${{ env.CHANGED_FILES }} == *"docs/shipping/"* ]]; then
echo "changed files has files under docs/shipping"
set +e
python _metadata_validation/validate_metadata.py
python_exit_code=$?
set -e
if [ "$python_exit_code" -ne 0 ]; then
echo "The validation script failed with exit code $python_exit_code, sending failure status"
response=$(curl --request POST \
--url https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.event.pull_request.head.sha }} \
--header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
--header 'content-type: application/json' \
--data '{
"context": "PR validation",
"state": "failure",
"description": "Validation failed",
"target_url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
}')
echo "skip_next_step=true" >> "$GITHUB_OUTPUT"
exit $python_exit_code
fi
else
echo "No changes for doc files..."
response=$(curl --request POST \
--url https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.event.pull_request.head.sha }} \
--header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
--header 'content-type: application/json' \
--data '{
"context": "PR validation",
"state": "success",
"description": "No docs changed, does not required validation and manifest",
"target_url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
}')
echo "skip_next_step=true" >> "$GITHUB_OUTPUT"
fi
else
echo "No changes for doc files..."
response=$(curl --request POST \
--url https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.event.pull_request.head.sha }} \
--header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
--header 'content-type: application/json' \
--data '{
"context": "PR validation",
"state": "success",
"description": "No docs changed, does not required validation and manifest",
"target_url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
}')
echo "skip_next_step=true" >> "$GITHUB_OUTPUT"
fi
- name: Create_manifest
id: create_manifest
if: steps.run_validation.outputs.skip_next_step != 'true'
run: |
echo "Creating new manifest..."
python _manifest/manifest_generator.py
echo "Copying file into manifest path"
cp ${{env.MANIFEST_PATH}} static/manifest.json
- uses: stefanzweifel/git-auto-commit-action@v5
id: auto_commit_manifest
if: steps.create_manifest.outputs.skip_next_step != 'true' && steps.create_manifest.outcome == 'success'
with:
file_pattern: './static/manifest.json'
commit_message: 'auto generated manifest'
commit_options: "--no-gpg-sign"
push_options: '--force'
- name: Manifest update success
if: steps.create_manifest.outputs.skip_next_step != 'true' && steps.run_validation.outputs.skip_next_step != 'true'
run: |
if [ ${{ steps.create_manifest.outcome }} == 'success' ]; then
echo "Sending success status on current commit..."
curl --request POST \
--url https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.event.pull_request.head.sha }} \
--header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
--header 'content-type: application/json' \
--data '{
"context": "PR validation",
"state": "success",
"description": "Docs are valid, manifest was generated",
"target_url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
}'
echo "Sending success status on manifest commit..."
curl --request POST \
--url https://api.github.com/repos/${{ github.repository }}/statuses/${{ steps.auto_commit_manifest.outputs.commit_hash }} \
--header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
--header 'content-type: application/json' \
--data '{
"context": "PR validation",
"state": "success",
"description": "Docs are valid, manifest was generated",
"target_url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
}'
else
echo "Sending failure status..."
curl --request POST \
--url https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.event.pull_request.head.sha }} \
--header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
--header 'content-type: application/json' \
--data '{
"context": "PR validation",
"state": "failure",
"description": "Error occurred on manifest generation",
"target_url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
}'
fi