diff --git a/.github/workflows/nightly.yaml b/.github/workflows/nightly.yaml deleted file mode 100644 index 4d2c538..0000000 --- a/.github/workflows/nightly.yaml +++ /dev/null @@ -1,41 +0,0 @@ -name: Nightly Build -on: - workflow_dispatch: - # schedule: - # - cron: "0 0 * * *" - -jobs: - full-validation: - runs-on: ubuntu-latest - environment: DEV - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Run tests (controlled via environment variable) - run: | - echo "Running nightly tests..." - echo "TEST_RESULT_OVERRIDE: ${{ vars.TEST_RESULT_OVERRIDE }}" - - if [ -n "${{ vars.TEST_RESULT_OVERRIDE }}" ]; then - if [ "${{ vars.TEST_RESULT_OVERRIDE }}" == "pass" ]; then - echo "Tests passed by override (via environment)!" - exit 0 - elif [ "${{ vars.TEST_RESULT_OVERRIDE }}" == "fail" ]; then - echo "Tests failed by override (via environment)!" - exit 1 - fi - else - echo "Random test result mode..." - if [ $((RANDOM % 2)) -eq 0 ]; then - echo "Tests passed!" - exit 0 - else - echo "Tests failed!" - exit 1 - fi - fi - - - name: Mark workflow as successful - if: success() - run: echo "Tests passed successfully!" \ No newline at end of file diff --git a/.github/workflows/validate.yaml b/.github/workflows/validate.yaml index 843446c..584d2c2 100644 --- a/.github/workflows/validate.yaml +++ b/.github/workflows/validate.yaml @@ -1,152 +1,66 @@ -name: 'PR Review Comment' on: - issue_comment: - types: [created, edited] + pull_request: + types: [labeled] + +permissions: + pull-requests: write + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: - sfp-validate-pool: + validate: + name: 'Validate Changed Packages' + if: contains(github.event.pull_request.labels.*.name, 'full validation') runs-on: ubuntu-latest - permissions: - pull-requests: write - if: > - github.event.issue.pull_request && - ( - contains(github.event.comment.body, '/quick-validation') || - contains(github.event.comment.body, '/full-validation') - ) - steps: - - name: Fetch Branch Name - id: fetch-branch-name - uses: xt0rted/pull-request-comment-branch@v2 - - name: Check out code from ${{ steps.fetch-branch-name.outputs.head_ref }} - uses: actions/checkout@v3 + steps: + - name: Checkout code + uses: actions/checkout@v4 with: - ref: ${{ steps.fetch-branch-name.outputs.head_ref }} + fetch-depth: 0 - - name: Process PR Comment - id: process-comment + - name: Run Validation Script run: | - COMMENT_ID="${{ github.event.comment.id }}" - COMMENT_BODY="${{ github.event.comment.body }}" - echo "COMMENT_ID: $COMMENT_ID" - echo "COMMENT_BODY: $COMMENT_BODY" - echo "::set-output name=comment-id::$COMMENT_ID" - if [[ "$COMMENT_BODY" == *"/quick-validation"* ]]; then - echo "::set-output name=validation-type::quick" - elif [[ "$COMMENT_BODY" == *"/full-validation"* ]]; then - echo "::set-output name=validation-type::full" - fi + echo "Running validation because 'full validation' label was added" + # Add your validation logic here (e.g., linting, testing) - # - name: Checkout - # uses: actions/checkout@v3 + sleep 10 + exit 0 - - name: Run Validation - id: validate + - name: Remove label + if: always() run: | - if [[ "${{ steps.process-comment.outputs.validation-type }}" == "quick" ]]; then - echo "Running Quick Validation..." - sleep 5 # Simulate quick validation - echo "Quick Validation Successful" > result.txt - elif [[ "${{ steps.process-comment.outputs.validation-type }}" == "full" ]]; then - echo "Running Full Validation..." - sleep 60 # Simulate full validation - echo "Full Validation Successful" > result.txt - fi - continue-on-error: true - - - name: Post Validation Status to PR - uses: mshick/add-pr-comment@v2 - with: - message: | - Validation run completed: **${{ steps.process-comment.outputs.validation-type }}** - Status: ${{ steps.validate.outcome == 'success' && '✅ Success' || '❌ Failed' }} - [View the workflow run here](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) - - - - - - - - - - - + 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_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 "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}" - - - - -# name: Validate and Run Commands Based on PR Labels - -# on: -# pull_request: -# types: [opened, synchronize, labeled, unlabeled] - -# jobs: -# validate-and-execute: +# remove-label: +# needs: validate +# if: always() # Ensures this runs even if validation fails # runs-on: ubuntu-latest # steps: -# - name: Checkout code -# uses: actions/checkout@v3 - -# # - name: Get PR Labels -# # id: get-labels -# # uses: actions/github-script@v6 -# # with: -# # script: | -# # const labels = context.payload.pull_request.labels.map(label => label.name); -# # return labels; -# # result-encoding: string - -# # - name: Determine Validation Type -# # id: determine-validation-mode -# # run: | -# # labels="${{ steps.get-labels.outputs.result }}" - -# # validation_mode="thorough" -# # if echo "$labels" | grep -q "quick validation"; then -# # validation_mode="individual" -# # fi - -# # echo "validation_mode=$validation_mode" | tee -a $GITHUB_OUTPUT - -# # # Validate source and trigger test, skipping if there are no deployable changes -# # - name: 'If deployable changes were made, push source to a scratch org' -# # run: | -# # labels="${{ steps.get-labels.outputs.result }}" - -# # validation_mode="thorough" -# # if echo "$labels" | grep -q "quick validation"; then -# # validation_mode="individual" -# # fi -# # echo $validation_mode - -# - name: Get SFP Pool Validation Mode from the PR labels -# id: sfp-validation-mode -# uses: actions/github-script@v7 -# with: -# script: | - -# const labels = context.payload.pull_request.labels.map(label => label.name); -# const hasQuickValidation = labels.includes('quick validation'); -# const hasFullValidation = labels.includes('full validation'); - -# let validationMode = 'thorough'; - -# if (hasQuickValidation && !hasFullValidation) { -# validationMode = 'individual'; -# } - -# console.log(`SFP Validation Mode: ${validationMode}`); -# return validationMode; -# result-encoding: string - -# - name: Run Commands Based on the Validation Mode +# - name: Remove 'needs-validation' label # run: | -# echo "Running commands based on the validation mode: ${{ steps.sfp-validation-mode.outputs.result }}" \ No newline at end of file +# 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}" \ No newline at end of file