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