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'
16+ if : github.event.action == 'labeled' && contains(github.event.pull_request.labels.*.name, 'run-full-validation')
17+ runs-on : ubuntu-latest
18+
19+ steps :
20+ - name : Checkout code
21+ uses : actions/checkout@v4
22+ with :
23+ fetch-depth : 0
24+
25+ - name : Run Validation Script
26+ run : |
27+ echo "Running validation because 'full validation' label was added"
28+ # Add your validation logic here (e.g., linting, testing)
29+
30+ sleep 30
31+ exit 0
32+
33+ - name : Remove Label using GitHub CLI
34+ run : gh pr edit ${{ github.event.pull_request.number }} --remove-label run-full-validation"
35+ env :
36+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
37+
38+ # - name: 'Remove label'
39+ # if: always()
40+ # run: |
41+ # PR_NUMBER=${{ github.event.pull_request.number }}
42+ # REPO=${{ github.repository }}
43+ # LABEL="full validation"
44+
45+ # # URL-encodes the label by replacing special characters with their percent-encoded equivalents.
46+ # 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')
47+
48+ # HTTP_RESPONSE=$(curl -s -o response.txt -w "%{http_code}" -X DELETE \
49+ # -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
50+ # -H "Accept: application/vnd.github.v3+json" \
51+ # "https://api.github.com/repos/$REPO/issues/$PR_NUMBER/labels/${ENCODED_FULL_VALIDATION_LABEL}")
52+
53+ # # Check if the HTTP response code is not 2xx and fail the step
54+ # if [[ $HTTP_RESPONSE -lt 200 || $HTTP_RESPONSE -ge 300 ]]; then
55+ # echo "Failed to remove label. HTTP Status: $HTTP_RESPONSE"
56+ # exit 1
57+ # fi
58+
59+ static-check :
60+ name : ' See if Static Analysis should run'
61+ runs-on : ubuntu-latest
62+
63+ outputs :
64+ all-changed-files : ${{ steps.changed-files.outputs.all_changed_and_modified_files }}
65+
66+ steps :
67+ - uses : actions/checkout@v4
68+ with :
69+ fetch-depth : 0
70+
71+ - name : Get all changed files for this PR
72+ id : changed-files
73+ run : |
74+ # Simulating output for debugging purposes
75+ echo "all_changed_and_modified_files=file1.txt,file2.txt,file3.txt"
76+ echo "::set-output name=all_changed_and_modified_files::file1.txt,file2.txt,file3.txt"
77+
78+ - name : List changed files, skipping this job if there are no files to analyze
79+ run : |
80+ if [ "${{ steps.changed-files.outputs.all_changed_and_modified_files }}" == "" ]; then
81+ echo 'No files eligible for scanning were changed. Skipping Static Analysis.'
82+ exit 0
83+ else
84+ echo ${{ steps.changed-files.outputs.all_changed_and_modified_files }}
85+ fi
86+
87+ static :
88+ name : ' Run Static Analysis'
89+ runs-on : ubuntu-latest
90+ needs : static-check
91+ if : needs.static-check.outputs.all-changed-files != ''
92+
93+ steps :
94+ - name : Check the outputs to determine whether to fail
95+ run : echo "Running static analyzer"
96+
97+ # remove-label:
98+ # needs: validate
99+ # if: always() # Ensures this runs even if validation fails
100+ # runs-on: ubuntu-latest
101+
102+ # steps:
103+ # - name: Remove 'needs-validation' label
104+ # run: |
105+ # PR_NUMBER=${{ github.event.pull_request.number }}
106+ # REPO=${{ github.repository }}
107+ # LABEL="full validation"
108+ # 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')
109+
110+ # echo $ENCODED_LABEL
111+ # echo "https://api.github.com/repos/$REPO/issues/$PR_NUMBER/labels/$ENCODED_LABEL"
112+ # curl -X DELETE -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
113+ # -H "Accept: application/vnd.github.v3+json" \
114+ # "https://api.github.com/repos/$REPO/issues/$PR_NUMBER/labels/${ENCODED_LABEL}"
0 commit comments