From 039b70ee9a947671cc5b8681ce17fa9b81dcc680 Mon Sep 17 00:00:00 2001 From: npotluri-rh <114231130+npotluri-rh@users.noreply.github.com> Date: Fri, 2 May 2025 13:47:42 -0500 Subject: [PATCH 1/6] sealights steps on pr workflow added --- .github/workflows/pr.yaml | 73 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index 7f58d025e..3e7881824 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -13,6 +13,15 @@ jobs: name: PR Validate runs-on: ubuntu-latest steps: + - name: Determine workflow run event context + run: echo "on-event=${{ github.event_name }}" >> $GITHUB_ENV + + - name: Handle invalid context for pull requests + if: ${{ env.on-event == 'pull_request' && (!github.event.pull_request.head.sha || !github.event.pull_request.number) }} + run: | + echo "Invalid context for this workflow run. Exiting." + exit 1 + - name: Checkout uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 with: @@ -49,6 +58,9 @@ jobs: with: go-version-file: 'go.mod' + - name: Store build timestamp + run: echo "BUILD_TIME=$(date +'%Y-%m-%dT%H:%M:%S')" >> $GITHUB_ENV + # gosec needs a "build" stage so connect it to the lint step which we always do - name: build run: make lint @@ -68,15 +80,65 @@ jobs: make manifests generate fmt vet install make run & + - name: Download SeaLights Go agent and CLI tool + run: | + echo "[Sealights] Downloading Sealights Golang & CLI Agents..." + case $(lscpu | awk '/Architecture:/{print $2}') in + x86_64) SL_ARCH="linux-amd64";; + arm) SL_ARCH="linux-arm64";; + esac + wget -nv -O sealights-go-agent.tar.gz https://agents.sealights.co/slgoagent/latest/slgoagent-$SL_ARCH.tar.gz + wget -nv -O sealights-slcli.tar.gz https://agents.sealights.co/slcli/latest/slcli-$SL_ARCH.tar.gz + tar -xzf ./sealights-go-agent.tar.gz && tar -xzf ./sealights-slcli.tar.gz + rm -f ./sealights-go-agent.tar.gz ./sealights-slcli.tar.gz + ./slgoagent -v 2> /dev/null | grep version && ./slcli -v 2> /dev/null | grep version + + - name: Write SeaLights token into file + run: echo "${SEALIGHTS_AGENT_TOKEN}" > sltoken.txt + env: + SEALIGHTS_AGENT_TOKEN: '${{secrets.SEALIGHTS_AGENT_TOKEN}}' ## Make sure to add token to repo secrets + + - name: Initiating the SeaLights agent + run: | + echo "[Sealights] Initiating the SeaLights agent to Golang and handing it the token" + ./slcli config init --lang go --token ./sltoken.txt + + - name: Configuring SeaLights - on pull_request event + if: env.on-event == 'pull_request' + run: | + echo "[Sealights] Configuring SeaLights to scan the pull request branch" + echo "Latest commit sha: ${LATEST_COMMIT_SHA}" + echo "PR Number: ${PULL_REQUEST_NUMBER}" + ./slcli config create-pr-bsid --app rhdh-operator --target-branch "main" --pull-request-number ${PULL_REQUEST_NUMBER} --latest-commit ${LATEST_COMMIT_SHA} --repository-url https://github.com/redhat-developer/rhdh-operator.git + env: + PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number || github.event.issue.number }} + LATEST_COMMIT_SHA: ${{github.event.pull_request.head.sha}} + + - name: Configuring SeaLights - on push event + if: env.on-event == 'push' + run: | + echo "[Sealights] Configuring SeaLights to scan the main branch after pull request was closed" + ./slcli config create-bsid --app rhdh-operator --branch "main" --build "$BUILD_TIME :$LATEST_COMMIT_SHA" + env: + LATEST_COMMIT_SHA: ${{ github.sha }} + + - name: Run the SeaLights scan for integration_tests + run: | + echo "[Sealights] Running the SeaLights integration tests scan" + ./slcli scan --bsid buildSessionId.txt --path-to-scanner ./slgoagent --workspacepath "./" --scm git --scmBaseUrl https://github.com/redhat-developer/rhdh-operator --scmProvider github + env: + SEALIGHTS_TEST_STAGE: "ALL Tests" + SEALIGHTS_TEST_SELECTION: false + - name: Test # run this stage only if there are changes that match the includes and not the excludes - if: steps.changed-files.outputs.any_changed == 'true' + #if: steps.changed-files.outputs.any_changed == 'true' ## enable after initial scan results captured run: make test - name: Generic Integration test # run this stage only if there are changes that match the includes and not the excludes # perform it on backstage.io for speed - if: steps.changed-files.outputs.any_changed == 'true' + #if: steps.changed-files.outputs.any_changed == 'true' ## enable after initial scan results captured run: make integration-test PROFILE=backstage.io USE_EXISTING_CLUSTER=true USE_EXISTING_CONTROLLER=true - name: RHDH specific Integration test @@ -84,6 +146,11 @@ jobs: if: steps.changed-files.outputs.any_changed == 'true' run: make integration-test ARGS='--focus "create default rhdh"' USE_EXISTING_CLUSTER=true USE_EXISTING_CONTROLLER=true + - name: clean all SeaLights secret stuff + run: | + echo "[Sealights] Cleaning up after SeaLights run" + rm sltoken.txt + - name: Run Gosec Security Scanner run: make gosec @@ -91,4 +158,4 @@ jobs: uses: github/codeql-action/upload-sarif@28deaeda66b76a05916b6923827895f2b14ab387 # v3 with: # Path to SARIF file relative to the root of the repository - sarif_file: gosec.sarif + sarif_file: gosec.sarif \ No newline at end of file From 353584f47e85f7a5083fbb15b5bdc02eeb4bae01 Mon Sep 17 00:00:00 2001 From: npotluri-rh <114231130+npotluri-rh@users.noreply.github.com> Date: Thu, 8 May 2025 13:12:54 -0500 Subject: [PATCH 2/6] updated suggested changes from comments --- .github/workflows/pr.yaml | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index b9ae4e348..7534daa10 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -1,12 +1,8 @@ name: PR Test operator on: - pull_request: - branches: - - main - - rhdh-1.[0-9]+ - - 1.[0-9]+.x - - release-1.[0-9]+ + pull_request_target: + types: [opened, synchronize, reopened, labeled, unlabeled] jobs: pr-validate: @@ -19,7 +15,7 @@ jobs: - name: Handle invalid context for pull requests if: ${{ env.on-event == 'pull_request' && (!github.event.pull_request.head.sha || !github.event.pull_request.number) }} run: | - echo "Invalid context for this workflow run. Exiting." + echo "[ERROR] Pull Request has no github.event.pull_request.head.sha or github.event.pull_request.number: must exit." exit 1 - name: Checkout @@ -122,12 +118,12 @@ jobs: env: LATEST_COMMIT_SHA: ${{ github.sha }} - - name: Run the SeaLights scan for integration_tests + - name: Run SeaLights scan for unit and integration tests run: | echo "[Sealights] Running the SeaLights integration tests scan" ./slcli scan --bsid buildSessionId.txt --path-to-scanner ./slgoagent --workspacepath "./" --scm git --scmBaseUrl https://github.com/redhat-developer/rhdh-operator --scmProvider github env: - SEALIGHTS_TEST_STAGE: "ALL Tests" + SEALIGHTS_TEST_STAGE: "Unit and Integration" SEALIGHTS_TEST_SELECTION: false - name: Test @@ -146,7 +142,7 @@ jobs: if: steps.changed-files.outputs.any_changed == 'true' run: make integration-test ARGS='--focus "create default rhdh"' USE_EXISTING_CLUSTER=true USE_EXISTING_CONTROLLER=true - - name: clean all SeaLights secret stuff + - name: Remove SeaLights secrets run: | echo "[Sealights] Cleaning up after SeaLights run" rm sltoken.txt From 6484d99b5a21bfa63a342ade2d572261f569b536 Mon Sep 17 00:00:00 2001 From: npotluri-rh <114231130+npotluri-rh@users.noreply.github.com> Date: Tue, 13 May 2025 15:10:42 -0500 Subject: [PATCH 3/6] updates for commented suggessions --- .github/workflows/pr.yaml | 86 +++++++++++++++++++++------------------ 1 file changed, 46 insertions(+), 40 deletions(-) diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index a8f56667e..099850406 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -2,22 +2,31 @@ name: PR Test operator on: pull_request_target: - types: [opened, synchronize, reopened, labeled, unlabeled] + types: [opened, synchronize, reopened, ready_for_review] + branches: + - main + - rhdh-1.[0-9]+ + - 1.[0-9]+.x + - release-1.[0-9]+ jobs: - pr-validate: - name: PR Validate + authorize: + # The 'external' environment is configured with the odo-maintainers team as required reviewers. + # All the subsequent jobs in this workflow 'need' this job, which will require manual approval for PRs coming from external forks. + # see list of approvers in OWNERS file + environment: + ${{ (github.event.pull_request.head.repo.full_name == github.repository || + contains(fromJSON('["gazarenkov","nickboldt","rm3l","openshift-cherrypick-robot"]'), github.actor)) && 'internal' || 'external' }} runs-on: ubuntu-latest steps: - - name: Determine workflow run event context - run: echo "on-event=${{ github.event_name }}" >> $GITHUB_ENV - - - name: Handle invalid context for pull requests - if: ${{ env.on-event == 'pull_request' && (!github.event.pull_request.head.sha || !github.event.pull_request.number) }} + - name: approved run: | - echo "[ERROR] Pull Request has no github.event.pull_request.head.sha or github.event.pull_request.number: must exit." - exit 1 - + echo "✓" + + pr-validate: + name: PR Validate + runs-on: ubuntu-latest + steps: - name: Checkout uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 with: @@ -76,33 +85,36 @@ jobs: make manifests generate fmt vet install make run & - - name: Download SeaLights Go agent and CLI tool - run: | - echo "[Sealights] Downloading Sealights Golang & CLI Agents..." - case $(lscpu | awk '/Architecture:/{print $2}') in - x86_64) SL_ARCH="linux-amd64";; - arm) SL_ARCH="linux-arm64";; - esac - wget -nv -O sealights-go-agent.tar.gz https://agents.sealights.co/slgoagent/latest/slgoagent-$SL_ARCH.tar.gz - wget -nv -O sealights-slcli.tar.gz https://agents.sealights.co/slcli/latest/slcli-$SL_ARCH.tar.gz - tar -xzf ./sealights-go-agent.tar.gz && tar -xzf ./sealights-slcli.tar.gz - rm -f ./sealights-go-agent.tar.gz ./sealights-slcli.tar.gz - ./slgoagent -v 2> /dev/null | grep version && ./slcli -v 2> /dev/null | grep version - - name: Write SeaLights token into file + if: steps.changed-files.outputs.any_changed == 'true' && ${{ matrix.branch == 'main' }} run: echo "${SEALIGHTS_AGENT_TOKEN}" > sltoken.txt env: SEALIGHTS_AGENT_TOKEN: '${{secrets.SEALIGHTS_AGENT_TOKEN}}' ## Make sure to add token to repo secrets + - name: Download SeaLights Go agent and CLI tool + if: steps.changed-files.outputs.any_changed == 'true' && ${{ matrix.branch == 'main' }} + run: | + echo "[SeaLights] Downloading SeaLights Golang & CLI Agents..." + # Architectures available: darwin-amd64, darwin-arm64, linux-amd64, linux-arm64 + SL_OS_ARCH=linux-amd64 + SL_GO_AGENT_VERSION=v1.1.193 + SL_CLI_AGENT_VERSION=v1.0.49 + wget -nv -O sealights-go-agent.tar.gz https://agents.sealights.co/slgoagent/${SL_GO_AGENT_VERSION}/slgoagent-${SL_OS_ARCH}.tar.gz + wget -nv -O sealights-slcli.tar.gz https://agents.sealights.co/slcli/${SL_CLI_AGENT_VERSION}/slcli-${SL_OS_ARCH}.tar.gz + tar -xzf ./sealights-go-agent.tar.gz && tar -xzf ./sealights-slcli.tar.gz + rm -f ./sealights-go-agent.tar.gz ./sealights-slcli.tar.gz + ./slgoagent -v 2> /dev/null | grep version && ./slcli -v 2> /dev/null | grep version + - name: Initiating the SeaLights agent + if: steps.changed-files.outputs.any_changed == 'true' && ${{ matrix.branch == 'main' }} run: | - echo "[Sealights] Initiating the SeaLights agent to Golang and handing it the token" + echo "[SeaLights] Initiating the SeaLights agent to Golang and handing it the token" ./slcli config init --lang go --token ./sltoken.txt - - name: Configuring SeaLights - on pull_request event - if: env.on-event == 'pull_request' + - name: Configuring SeaLights + if: steps.changed-files.outputs.any_changed == 'true' && ${{ matrix.branch == 'main' }} run: | - echo "[Sealights] Configuring SeaLights to scan the pull request branch" + echo "[SeaLights] Configuring SeaLights to scan the pull request branch" echo "Latest commit sha: ${LATEST_COMMIT_SHA}" echo "PR Number: ${PULL_REQUEST_NUMBER}" ./slcli config create-pr-bsid --app rhdh-operator --target-branch "main" --pull-request-number ${PULL_REQUEST_NUMBER} --latest-commit ${LATEST_COMMIT_SHA} --repository-url https://github.com/redhat-developer/rhdh-operator.git @@ -110,17 +122,10 @@ jobs: PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number || github.event.issue.number }} LATEST_COMMIT_SHA: ${{github.event.pull_request.head.sha}} - - name: Configuring SeaLights - on push event - if: env.on-event == 'push' - run: | - echo "[Sealights] Configuring SeaLights to scan the main branch after pull request was closed" - ./slcli config create-bsid --app rhdh-operator --branch "main" --build "$BUILD_TIME :$LATEST_COMMIT_SHA" - env: - LATEST_COMMIT_SHA: ${{ github.sha }} - - name: Run SeaLights scan for unit and integration tests + if: steps.changed-files.outputs.any_changed == 'true' && ${{ matrix.branch == 'main' }} run: | - echo "[Sealights] Running the SeaLights integration tests scan" + echo "[SeaLights] Running the SeaLights integration tests scan" ./slcli scan --bsid buildSessionId.txt --path-to-scanner ./slgoagent --workspacepath "./" --scm git --scmBaseUrl https://github.com/redhat-developer/rhdh-operator --scmProvider github env: SEALIGHTS_TEST_STAGE: "Unit and Integration" @@ -128,13 +133,13 @@ jobs: - name: Test # run this stage only if there are changes that match the includes and not the excludes - #if: steps.changed-files.outputs.any_changed == 'true' ## enable after initial scan results captured + if: steps.changed-files.outputs.any_changed == 'true' run: make test - name: Generic Integration test # run this stage only if there are changes that match the includes and not the excludes # perform it on backstage.io for speed - #if: steps.changed-files.outputs.any_changed == 'true' ## enable after initial scan results captured + if: steps.changed-files.outputs.any_changed == 'true' run: make integration-test PROFILE=backstage.io USE_EXISTING_CLUSTER=true USE_EXISTING_CONTROLLER=true - name: RHDH specific Integration test @@ -143,8 +148,9 @@ jobs: run: make integration-test ARGS='--focus "create default rhdh"' USE_EXISTING_CLUSTER=true USE_EXISTING_CONTROLLER=true - name: Remove SeaLights secrets + if: steps.changed-files.outputs.any_changed == 'true' && ${{ matrix.branch == 'main' }} run: | - echo "[Sealights] Cleaning up after SeaLights run" + echo "[SeaLights] Cleaning up after SeaLights run" rm sltoken.txt - name: Run Gosec Security Scanner From fd3e59d07b960a22c2d77c768f8e06ca94a243ad Mon Sep 17 00:00:00 2001 From: npotluri-rh <114231130+npotluri-rh@users.noreply.github.com> Date: Thu, 15 May 2025 06:51:29 -0500 Subject: [PATCH 4/6] fixes from review --- .github/workflows/pr.yaml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index 099850406..3d609ad04 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -26,6 +26,7 @@ jobs: pr-validate: name: PR Validate runs-on: ubuntu-latest + needs: authorize steps: - name: Checkout uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 @@ -86,13 +87,13 @@ jobs: make run & - name: Write SeaLights token into file - if: steps.changed-files.outputs.any_changed == 'true' && ${{ matrix.branch == 'main' }} + if: steps.changed-files.outputs.any_changed == 'true' run: echo "${SEALIGHTS_AGENT_TOKEN}" > sltoken.txt env: SEALIGHTS_AGENT_TOKEN: '${{secrets.SEALIGHTS_AGENT_TOKEN}}' ## Make sure to add token to repo secrets - name: Download SeaLights Go agent and CLI tool - if: steps.changed-files.outputs.any_changed == 'true' && ${{ matrix.branch == 'main' }} + if: steps.changed-files.outputs.any_changed == 'true' run: | echo "[SeaLights] Downloading SeaLights Golang & CLI Agents..." # Architectures available: darwin-amd64, darwin-arm64, linux-amd64, linux-arm64 @@ -106,13 +107,13 @@ jobs: ./slgoagent -v 2> /dev/null | grep version && ./slcli -v 2> /dev/null | grep version - name: Initiating the SeaLights agent - if: steps.changed-files.outputs.any_changed == 'true' && ${{ matrix.branch == 'main' }} + if: steps.changed-files.outputs.any_changed == 'true' run: | echo "[SeaLights] Initiating the SeaLights agent to Golang and handing it the token" ./slcli config init --lang go --token ./sltoken.txt - name: Configuring SeaLights - if: steps.changed-files.outputs.any_changed == 'true' && ${{ matrix.branch == 'main' }} + if: steps.changed-files.outputs.any_changed == 'true' run: | echo "[SeaLights] Configuring SeaLights to scan the pull request branch" echo "Latest commit sha: ${LATEST_COMMIT_SHA}" @@ -123,7 +124,7 @@ jobs: LATEST_COMMIT_SHA: ${{github.event.pull_request.head.sha}} - name: Run SeaLights scan for unit and integration tests - if: steps.changed-files.outputs.any_changed == 'true' && ${{ matrix.branch == 'main' }} + if: steps.changed-files.outputs.any_changed == 'true' run: | echo "[SeaLights] Running the SeaLights integration tests scan" ./slcli scan --bsid buildSessionId.txt --path-to-scanner ./slgoagent --workspacepath "./" --scm git --scmBaseUrl https://github.com/redhat-developer/rhdh-operator --scmProvider github @@ -148,7 +149,7 @@ jobs: run: make integration-test ARGS='--focus "create default rhdh"' USE_EXISTING_CLUSTER=true USE_EXISTING_CONTROLLER=true - name: Remove SeaLights secrets - if: steps.changed-files.outputs.any_changed == 'true' && ${{ matrix.branch == 'main' }} + if: always() && steps.changed-files.outputs.any_changed == 'true' run: | echo "[SeaLights] Cleaning up after SeaLights run" rm sltoken.txt From d8319e4344111fec6c25c50818d8a0449d914046 Mon Sep 17 00:00:00 2001 From: npotluri-rh <114231130+npotluri-rh@users.noreply.github.com> Date: Thu, 15 May 2025 10:49:35 -0500 Subject: [PATCH 5/6] branch name fetched --- .github/workflows/pr.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index 3d609ad04..f7a9cc4df 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -118,10 +118,13 @@ jobs: echo "[SeaLights] Configuring SeaLights to scan the pull request branch" echo "Latest commit sha: ${LATEST_COMMIT_SHA}" echo "PR Number: ${PULL_REQUEST_NUMBER}" - ./slcli config create-pr-bsid --app rhdh-operator --target-branch "main" --pull-request-number ${PULL_REQUEST_NUMBER} --latest-commit ${LATEST_COMMIT_SHA} --repository-url https://github.com/redhat-developer/rhdh-operator.git + echo "Target Branch: ${TARGET_BRANCH}" + ./slcli config create-pr-bsid --app rhdh-operator --target-branch ${TARGET_BRANCH} --pull-request-number ${PULL_REQUEST_NUMBER} --latest-commit ${LATEST_COMMIT_SHA} --repository-url https://github.com/redhat-developer/rhdh-operator.git env: PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number || github.event.issue.number }} LATEST_COMMIT_SHA: ${{github.event.pull_request.head.sha}} + ${{ github.ref_name }} + TARGET_BRANCH: ${{ github.base_ref }} - name: Run SeaLights scan for unit and integration tests if: steps.changed-files.outputs.any_changed == 'true' From ded34604bf5105542e578faa9e76d0b77e0a13b9 Mon Sep 17 00:00:00 2001 From: npotluri-rh <114231130+npotluri-rh@users.noreply.github.com> Date: Thu, 15 May 2025 14:59:09 -0500 Subject: [PATCH 6/6] rm -f for token file --- .github/workflows/pr.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index f7a9cc4df..f453ea90f 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -155,7 +155,7 @@ jobs: if: always() && steps.changed-files.outputs.any_changed == 'true' run: | echo "[SeaLights] Cleaning up after SeaLights run" - rm sltoken.txt + rm -f sltoken.txt - name: Run Gosec Security Scanner run: make gosec