Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 148 additions & 0 deletions .github/workflows/validate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,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}"