-
Notifications
You must be signed in to change notification settings - Fork 0
148 lines (121 loc) · 5.36 KB
/
validate.yaml
File metadata and controls
148 lines (121 loc) · 5.36 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
name: Validate
on:
pull_request:
types: [synchronize, opened, reopened, labeled]
permissions:
pull-requests: write
# concurrency:
# group: ${{ github.workflow }}-${{ github.ref }}
# cancel-in-progress: true
jobs:
validate:
name: 'Validate Changed Packages - Github Hosted'
if: >
github.event.action == 'labeled' &&
contains(github.event.pull_request.labels.*.name, 'run-full-validation') &&
!contains(github.event.pull_request.labels.*.name, 'long-run')
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Run Validation Script
run: |
echo "Running validation because 'full validation' label was added"
# Add your validation logic here (e.g., linting, testing)
sleep 30
exit 0
- name: 'Remove label'
run: |
curl -X DELETE -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels/run-full-validation"
validate-self-hosted:
name: 'Validate Changed Packages- Self-Hosted'
if: >
github.event.action == 'labeled' &&
contains(github.event.pull_request.labels.*.name, 'run-full-validation') &&
contains(github.event.pull_request.labels.*.name, 'long-run')
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Run Validation Script
run: |
echo "Running validation because 'full validation' label was added"
# Add your validation logic here (e.g., linting, testing)
sleep 30
exit 0
- name: 'Remove label'
run: |
curl -X DELETE -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels/run-full-validation"
# - name: 'Remove label'
# if: always()
# run: |
# PR_NUMBER=${{ github.event.pull_request.number }}
# REPO=${{ github.repository }}
# LABEL="full validation"
# # URL-encodes the label by replacing special characters with their percent-encoded equivalents.
# ENCODED_FULL_VALIDATION_LABEL=$(printf "%s" "${{ env.FULL_VALIDATION_LABEL }}" | sed -e 's/ /%20/g' -e 's/:/%3A/g' -e 's/\//%2F/g' -e 's/?/%3F/g' -e 's/&/%26/g' -e 's/=/%3D/g')
# HTTP_RESPONSE=$(curl -s -o response.txt -w "%{http_code}" -X DELETE \
# -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
# -H "Accept: application/vnd.github.v3+json" \
# "https://api.github.com/repos/$REPO/issues/$PR_NUMBER/labels/${ENCODED_FULL_VALIDATION_LABEL}")
# # Check if the HTTP response code is not 2xx and fail the step
# if [[ $HTTP_RESPONSE -lt 200 || $HTTP_RESPONSE -ge 300 ]]; then
# echo "Failed to remove label. HTTP Status: $HTTP_RESPONSE"
# exit 1
# fi
static-check:
name: 'See if Static Analysis should run'
if: github.event.action != 'labeled'
runs-on: ubuntu-latest
outputs:
all-changed-files: ${{ steps.changed-files.outputs.all_changed_and_modified_files }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get all changed files for this PR
id: changed-files
run: |
# Simulating output for debugging purposes
echo "all_changed_and_modified_files=file1.txt,file2.txt,file3.txt"
echo "::set-output name=all_changed_and_modified_files::file1.txt,file2.txt,file3.txt"
- name: List changed files, skipping this job if there are no files to analyze
run: |
if [ "${{ steps.changed-files.outputs.all_changed_and_modified_files }}" == "" ]; then
echo 'No files eligible for scanning were changed. Skipping Static Analysis.'
exit 0
else
echo ${{ steps.changed-files.outputs.all_changed_and_modified_files }}
fi
static:
name: 'Run Static Analysis'
runs-on: ubuntu-latest
needs: static-check
if: needs.static-check.outputs.all-changed-files != ''
steps:
- name: Check the outputs to determine whether to fail
run: echo "Running static analyzer"
# remove-label:
# needs: validate
# if: always() # Ensures this runs even if validation fails
# runs-on: ubuntu-latest
# steps:
# - name: Remove 'needs-validation' label
# run: |
# PR_NUMBER=${{ github.event.pull_request.number }}
# REPO=${{ github.repository }}
# LABEL="full validation"
# ENCODED_LABEL=$(printf "%s" "$LABEL" | sed -e 's/ /%20/g' -e 's/:/%3A/g' -e 's/\//%2F/g' -e 's/?/%3F/g' -e 's/&/%26/g' -e 's/=/%3D/g')
# echo $ENCODED_LABEL
# echo "https://api.github.com/repos/$REPO/issues/$PR_NUMBER/labels/$ENCODED_LABEL"
# curl -X DELETE -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
# -H "Accept: application/vnd.github.v3+json" \
# "https://api.github.com/repos/$REPO/issues/$PR_NUMBER/labels/${ENCODED_LABEL}"