From 236992d55da83684e77ab3ec3937ccf679bc988e Mon Sep 17 00:00:00 2001 From: venkatadhatri <80774439+venkatadhatri@users.noreply.github.com> Date: Thu, 14 Nov 2024 10:42:36 -0500 Subject: [PATCH 1/4] Create codeql.yml --- .github/workflows/codeql.yml | 57 ++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 .github/workflows/codeql.yml diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000..57bb803 --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,57 @@ +# Define the name of the workflow +name: "CodeQL-Advanced" + +# Define when the workflow should be triggered (on push to a specific branch and pull requests to the master branch) +on: + push: + branches: + - main + pull_request: + branches: + - main +# Define the jobs that will be executed as part of the workflow +jobs: + analyze: + name: Analyze + runs-on: + group: ncats-awsci-runners + + # Define the matrix strategy for parallel runs with different languages + strategy: + fail-fast: false + matrix: + language: [ 'javascript-typescript' ] + + steps: + # Step 1: Checkout repository + - name: Checkout repository + uses: actions/checkout@v4 + + # Step 2: Initialize CodeQL for scanning + - name: Initialize CodeQL + uses: github/codeql-action/init@v3 + with: + languages: ${{ matrix.language }} + + # Step 3: Autobuild the code. + - name: Autobuild + uses: github/codeql-action/autobuild@v3 + + # Step 4: Analyzes the code using CodeQL, with the analysis category based on the matrix language. + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v3 + with: + category: "/language:${{matrix.language}}" + + # Step 5: Generate Security Report + - name: Generate Security Report + uses: rsdmike/github-security-report-action@v3.0.4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + + # Step 6: Uploads artifacts (PDF reports) generated during the workflow to download. + - name: Upload Artifacts + uses: actions/upload-artifact@v4 + with: + name: codeql-reports + path: ./*.pdf From 7e73e293ead450d63edde17c3d46bea7eda6e3dc Mon Sep 17 00:00:00 2001 From: venkatadhatri <80774439+venkatadhatri@users.noreply.github.com> Date: Thu, 14 Nov 2024 10:44:28 -0500 Subject: [PATCH 2/4] Create snyk.yml --- .github/workflows/snyk.yml | 86 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 .github/workflows/snyk.yml diff --git a/.github/workflows/snyk.yml b/.github/workflows/snyk.yml new file mode 100644 index 0000000..63fa11d --- /dev/null +++ b/.github/workflows/snyk.yml @@ -0,0 +1,86 @@ +# Define the name of the workflow +name: snyk-zap + +# Define when the workflow should be triggered (on push to a specific branch and pull requests to the master branch) +on: + push: + branches: + - master + pull_request: + branches: + - master + workflow_dispatch: + +# Define the jobs that will be executed as part of the workflow +jobs: + # Job to build and push the ZAP Docker image to Docker Hub + Snyk-Docker-Image: + runs-on: + group: ncats-awsci-runners + permissions: + actions: read + contents: read + security-events: write + issues: write + + outputs: + build_version: ${{ steps.get_build_version.outputs.build_version }} + + steps: + # Step 1: Checkout repository + - name: Checkout code + uses: actions/checkout@v4 + + # Step 2: Generate Build Version Number + - name: Generate Build Version Number + id: GET_BUILD_VERSION + run: | + # Get the last recorded date from the environment variable + LAST_DATE=$(date -d "$LAST_BUILD_DATE" +'%Y-%m-%d' 2>/dev/null || echo "") + + # Get the current date + CURRENT_DATE=$(date +'%Y-%m-%d') + echo "Last recorded date: $LAST_DATE" + echo "Current date: $CURRENT_DATE" + + # Check if it's a new day + if [ "$LAST_DATE" != "$CURRENT_DATE" ]; then + # Reset BUILDS_TODAY to 0 for the new day + BUILDS_TODAY=0 + echo "Resetting BUILDS_TODAY to 0 for the new day" + else + # Calculate the number of builds today + BUILDS_TODAY=$(seq -f v$GITHUB_RUN_NUMBER.%g $(($GITHUB_RUN_NUMBER - 1)) | wc -l) + echo "Incrementing BUILDS_TODAY" + fi + + # Store the current date for the next run + echo "LAST_BUILD_DATE=$CURRENT_DATE" >> $GITHUB_ENV + + # Generate the build version with the number of builds today + BUILD_VERSION_GENERATED=$(date +v%Y.%m%d.$BUILDS_TODAY) + echo "Generated Build Version: $BUILD_VERSION_GENERATED" + echo "BUILD_VERSION=$BUILD_VERSION_GENERATED" >> $GITHUB_ENV + echo "BUILD=true" >> $GITHUB_ENV + echo "::set-output name=build_version::$BUILD_VERSION_GENERATED" + + # # Step 3: Login to Dockerhub + # - name: Login to Dockerhub + # run: docker login -u "${{ secrets.DKRHUB_NCATSSVCDVOPS_USERNAME }}" -p "${{ secrets.DKRHUB_NCATSSVCDVOPS_TOKEN_WRITE }}" + + # Step 4: Build a Docker image + - name: Build a Docker image + run: docker build --no-cache -f ./Dockerfile --build-arg NPM_TOKEN=${{ secrets.NPM_INSTALL_TOKEN }} --build-arg BUILD_VERSION=$BUILD_VERSION -t ncats/smartgraph_frontend:$BUILD_VERSION . + + # Step 5: Run Snyk to check Docker image for vulnerabilities + - name: Run Snyk to check Docker image for vulnerabilities + continue-on-error: true + uses: snyk/actions/docker@master + id: docker-image-scan + env: + SNYK_TOKEN: ${{ secrets.SNYK_CLI }} + ACTIONS_STEP_DEBUG: true + with: + command: monitor + image: ncats/smartgraph_frontend:$BUILD_VERSION + args: --file=Dockerfile From fa24736a2d5d31d53117b99eaed34751baddd851 Mon Sep 17 00:00:00 2001 From: venkatadhatri <80774439+venkatadhatri@users.noreply.github.com> Date: Thu, 14 Nov 2024 10:45:01 -0500 Subject: [PATCH 3/4] Update codeql.yml --- .github/workflows/codeql.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 57bb803..3058212 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -5,10 +5,10 @@ name: "CodeQL-Advanced" on: push: branches: - - main + - master pull_request: branches: - - main + - master # Define the jobs that will be executed as part of the workflow jobs: analyze: From 18eba8221f7b772560754d255ac89ccff5ccb16c Mon Sep 17 00:00:00 2001 From: venkatadhatri <80774439+venkatadhatri@users.noreply.github.com> Date: Thu, 14 Nov 2024 12:04:10 -0500 Subject: [PATCH 4/4] Update snyk.yml --- .github/workflows/snyk.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/snyk.yml b/.github/workflows/snyk.yml index 63fa11d..23da014 100644 --- a/.github/workflows/snyk.yml +++ b/.github/workflows/snyk.yml @@ -5,10 +5,10 @@ name: snyk-zap on: push: branches: - - master + - development pull_request: branches: - - master + - development workflow_dispatch: # Define the jobs that will be executed as part of the workflow