forked from GoogleCloudPlatform/magic-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
71 lines (67 loc) · 2.75 KB
/
pre-build-validation.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
name: Pre-Build Validation
permissions:
actions: read
contents: read
statuses: write
env:
status_suffix: "-pre-build-validation"
on:
workflow_dispatch:
inputs:
owner:
description: 'The owner of the fork'
required: false
default: 'modular-magician'
repo:
description: 'The Base Repository to pull from'
required: false
default: 'magic-modules'
sha:
description: "The commit SHA in magic-modules repository to execute against and where the status result will be posted"
required: true
jobs:
pre-build-validation:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
with:
repository: ${{ github.event.inputs.owner }}/${{ github.event.inputs.repo }}
ref: ${{ github.event.inputs.sha }}
path: repo
fetch-depth: 0
- name: Check for mmv1 product file changes
id: pull_request
run: |
cd repo
git config user.name "modular-magician"
git config user.email "[email protected]"
git merge --no-ff origin/main
yamlfiles=$(git diff --name-only origin/main -- mmv1/products)
if [ ! -z "$yamlfiles" ]; then
echo "yamlfiles=repo/${yamlfiles//$'\n'/ repo/}" >> $GITHUB_OUTPUT
fi
- name: Get Job URL
if: ${{ !failure() && steps.pull_request.outputs.yamlfiles != '' }}
id: get_job
run: |
response=$(curl --get -Ss -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -H "Accept: application/vnd.github.v3+json" "https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/attempts/${{ github.run_attempt }}/jobs")
html_url=$(echo "$response" | jq -r --arg job_name "${{ github.job }}" '.jobs | map(select(.name == $job_name)) | .[0].html_url')
echo "url=${html_url}" >> $GITHUB_OUTPUT
- name: Install yamllint
if: ${{ !failure() && steps.pull_request.outputs.yamlfiles != '' }}
run: pip install yamllint
- name: Lint YAML files
if: ${{ !failure() && steps.pull_request.outputs.yamlfiles != '' }}
run: yamllint -c repo/.yamllint ${{steps.pull_request.outputs.yamlfiles}}
- name: Post Result Status to Pull Request
if: ${{ !cancelled() && steps.pull_request.outputs.yamlfiles != '' }}
run: |
curl -X POST -H "Authorization: token ${{secrets.GITHUB_TOKEN}}" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/GoogleCloudPlatform/magic-modules/statuses/${{github.event.inputs.sha}}" \
-d '{
"context": "${{ github.event.inputs.repo }}${{ env.status_suffix }}",
"target_url": "${{ steps.get_job.outputs.url }}",
"state": "${{ job.status }}"
}'