1+ name : Validate
2+
3+ on :
4+ pull_request :
5+ types : [synchronize, opened, reopened, labeled]
6+
7+ permissions :
8+ pull-requests : write
9+
10+ # concurrency:
11+ # group: ${{ github.workflow }}-${{ github.ref }}
12+ # cancel-in-progress: true
13+
14+ jobs :
15+ validate :
16+ name : ' Validate Changed Packages - Github Hosted'
17+ if : >
18+ github.event.action == 'labeled' &&
19+ contains(github.event.pull_request.labels.*.name, 'run-full-validation') &&
20+ !contains(github.event.pull_request.labels.*.name, 'long-run')
21+ runs-on : ubuntu-latest
22+
23+ steps :
24+ - name : Checkout code
25+ uses : actions/checkout@v4
26+ with :
27+ fetch-depth : 0
28+
29+ - name : Run Validation Script
30+ run : |
31+ echo "Running validation because 'full validation' label was added"
32+ # Add your validation logic here (e.g., linting, testing)
33+
34+ sleep 30
35+ exit 0
36+
37+ - name : ' Remove label'
38+ run : |
39+ curl -X DELETE -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
40+ -H "Accept: application/vnd.github.v3+json" \
41+ "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels/run-full-validation"
42+
43+ validate-self-hosted :
44+ name : ' Validate Changed Packages- Self-Hosted'
45+ if : >
46+ github.event.action == 'labeled' &&
47+ contains(github.event.pull_request.labels.*.name, 'run-full-validation') &&
48+ contains(github.event.pull_request.labels.*.name, 'long-run')
49+ runs-on : ubuntu-latest
50+
51+ steps :
52+ - name : Checkout code
53+ uses : actions/checkout@v4
54+ with :
55+ fetch-depth : 0
56+
57+ - name : Run Validation Script
58+ run : |
59+ echo "Running validation because 'full validation' label was added"
60+ # Add your validation logic here (e.g., linting, testing)
61+
62+ sleep 30
63+ exit 0
64+
65+ - name : ' Remove label'
66+ run : |
67+ curl -X DELETE -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
68+ -H "Accept: application/vnd.github.v3+json" \
69+ "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels/run-full-validation"
70+
71+ # - name: 'Remove label'
72+ # if: always()
73+ # run: |
74+ # PR_NUMBER=${{ github.event.pull_request.number }}
75+ # REPO=${{ github.repository }}
76+ # LABEL="full validation"
77+
78+ # # URL-encodes the label by replacing special characters with their percent-encoded equivalents.
79+ # 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')
80+
81+ # HTTP_RESPONSE=$(curl -s -o response.txt -w "%{http_code}" -X DELETE \
82+ # -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
83+ # -H "Accept: application/vnd.github.v3+json" \
84+ # "https://api.github.com/repos/$REPO/issues/$PR_NUMBER/labels/${ENCODED_FULL_VALIDATION_LABEL}")
85+
86+ # # Check if the HTTP response code is not 2xx and fail the step
87+ # if [[ $HTTP_RESPONSE -lt 200 || $HTTP_RESPONSE -ge 300 ]]; then
88+ # echo "Failed to remove label. HTTP Status: $HTTP_RESPONSE"
89+ # exit 1
90+ # fi
91+
92+ static-check :
93+ name : ' See if Static Analysis should run'
94+ if : github.event.action != 'labeled'
95+ runs-on : ubuntu-latest
96+
97+ outputs :
98+ all-changed-files : ${{ steps.changed-files.outputs.all_changed_and_modified_files }}
99+
100+ steps :
101+ - uses : actions/checkout@v4
102+ with :
103+ fetch-depth : 0
104+
105+ - name : Get all changed files for this PR
106+ id : changed-files
107+ run : |
108+ # Simulating output for debugging purposes
109+ echo "all_changed_and_modified_files=file1.txt,file2.txt,file3.txt"
110+ echo "::set-output name=all_changed_and_modified_files::file1.txt,file2.txt,file3.txt"
111+
112+ - name : List changed files, skipping this job if there are no files to analyze
113+ run : |
114+ if [ "${{ steps.changed-files.outputs.all_changed_and_modified_files }}" == "" ]; then
115+ echo 'No files eligible for scanning were changed. Skipping Static Analysis.'
116+ exit 0
117+ else
118+ echo ${{ steps.changed-files.outputs.all_changed_and_modified_files }}
119+ fi
120+
121+ static :
122+ name : ' Run Static Analysis'
123+ runs-on : ubuntu-latest
124+ needs : static-check
125+ if : needs.static-check.outputs.all-changed-files != ''
126+
127+ steps :
128+ - name : Check the outputs to determine whether to fail
129+ run : echo "Running static analyzer"
130+
131+ # remove-label:
132+ # needs: validate
133+ # if: always() # Ensures this runs even if validation fails
134+ # runs-on: ubuntu-latest
135+
136+ # steps:
137+ # - name: Remove 'needs-validation' label
138+ # run: |
139+ # PR_NUMBER=${{ github.event.pull_request.number }}
140+ # REPO=${{ github.repository }}
141+ # LABEL="full validation"
142+ # 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')
143+
144+ # echo $ENCODED_LABEL
145+ # echo "https://api.github.com/repos/$REPO/issues/$PR_NUMBER/labels/$ENCODED_LABEL"
146+ # curl -X DELETE -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
147+ # -H "Accept: application/vnd.github.v3+json" \
148+ # "https://api.github.com/repos/$REPO/issues/$PR_NUMBER/labels/${ENCODED_LABEL}"
0 commit comments