From f3967cc5d5dd424a5788813a41d0166572d4d1be Mon Sep 17 00:00:00 2001 From: Vaughn Woerpel Date: Thu, 10 Oct 2024 12:24:09 -0400 Subject: [PATCH 1/3] Codeql test --- .github/workflows/codeql.yml | 82 ++++++++++++++++++ .github/workflows/push_pr.yml | 137 ------------------------------- .github/workflows/release.yml | 126 ---------------------------- .github/workflows/repolinter.yml | 31 ------- 4 files changed, 82 insertions(+), 294 deletions(-) create mode 100644 .github/workflows/codeql.yml delete mode 100644 .github/workflows/push_pr.yml delete mode 100644 .github/workflows/release.yml delete mode 100644 .github/workflows/repolinter.yml diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 000000000..cf62ead1c --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,82 @@ +name: "CodeQL Advanced" + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + schedule: + - cron: '0 0 * * 5' + +jobs: + analyze: + name: Analyze (${{ matrix.language }}) + # Runner size impacts CodeQL analysis time. To learn more, please see: + # - https://gh.io/recommended-hardware-resources-for-running-codeql + # - https://gh.io/supported-runners-and-hardware-resources + # - https://gh.io/using-larger-runners (GitHub.com only) + # Consider using larger runners or machines with greater resources for possible analysis time improvements. + runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }} + permissions: + # required for all workflows + security-events: write + + # required to fetch internal or private CodeQL packs + packages: read + + # only required for workflows in private repositories + actions: read + contents: read + + strategy: + fail-fast: false + matrix: + include: + - language: go + build-mode: autobuild + # CodeQL supports the following values keywords for 'language': 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift' + # Use `c-cpp` to analyze code written in C, C++ or both + # Use 'java-kotlin' to analyze code written in Java, Kotlin or both + # Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both + # To learn more about changing the languages that are analyzed or customizing the build mode for your analysis, + # see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning. + # If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how + # your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v3 + with: + languages: ${{ matrix.language }} + build-mode: ${{ matrix.build-mode }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + + # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs + # queries: security-extended,security-and-quality + + # If the analyze step fails for one of the languages you are analyzing with + # "We were unable to automatically build your code", modify the matrix above + # to set the build mode to "manual" for that language. Then modify this step + # to build your code. + # â„šī¸ Command-line programs to run using the OS shell. + # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun + - if: matrix.build-mode == 'manual' + shell: bash + run: | + echo 'If you are using a "manual" build mode for one or more of the' \ + 'languages you are analyzing, replace this with the commands to build' \ + 'your code, for example:' + echo ' make bootstrap' + echo ' make release' + exit 1 + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v3 + with: + category: "/language:${{matrix.language}}" + diff --git a/.github/workflows/push_pr.yml b/.github/workflows/push_pr.yml deleted file mode 100644 index 2a1a25910..000000000 --- a/.github/workflows/push_pr.yml +++ /dev/null @@ -1,137 +0,0 @@ ---- -name: Push/PR pipeline - -on: - push: - branches: - - '**' - tags-ignore: - - '**' - paths-ignore: - - README.md - - 'docs/**' - - 'examples/**' - -env: - REPO_FULL_NAME: ${{ github.event.repository.full_name }} - ORIGINAL_REPO_NAME: "newrelic/nri-flex" - -jobs: - - test-nix: - strategy: - matrix: - os: [ ubuntu-20.04 ] - name: Run unit tests in ${{matrix.os}} - runs-on: ${{matrix.os}} - steps: - - name: checkout code - uses: actions/checkout@v2 - - name: Install go - uses: actions/setup-go@v4 - with: - go-version-file: 'go.mod' - - name: Run unit tests - run: make ci/test - - name: Convert coverage.out to lcov.info - run: make ci/convert-coverage - - name: Coveralls Parallel - uses: coverallsapp/github-action@master - with: - github-token: ${{ secrets.github_token }} - path-to-lcov: lcov.info - flag-name: run-linux - parallel: true - - test-integration-nix: - name: Run integration tests - runs-on: ubuntu-20.04 - steps: - - uses: actions/checkout@v2 - - name: Login to DockerHub - uses: docker/login-action@v1 - with: - username: ${{ secrets.OHAI_DOCKER_HUB_ID }} - password: ${{ secrets.OHAI_DOCKER_HUB_PASSWORD }} - - name: Run integration tests - run: make test-integration - - snyk: - name: Run security checks via snyk - runs-on: ubuntu-20.04 - steps: - - uses: actions/checkout@v2 - - name: Login to DockerHub - uses: docker/login-action@v1 - with: - username: ${{ secrets.OHAI_DOCKER_HUB_ID }} - password: ${{ secrets.OHAI_DOCKER_HUB_PASSWORD }} - - name: Scan code for vulnerabilities - env: - SNYK_TOKEN: ${{ secrets.CAOS_SNYK_TOKEN }} - run: make ci/snyk-test - - test-windows: - strategy: - matrix: - go: [ '1.21' ] - os: [ windows-2022 ] - name: Run unit and integration tests in ${{matrix.os}} with go ${{matrix.go}} - runs-on: ${{matrix.os}} - steps: - - name: checkout - uses: actions/checkout@v2 - - name: install go - uses: actions/setup-go@v4 - with: - go-version-file: 'go.mod' - - name: run unit tests - # we don't have 'make' on windows. - run: | - go test ./cmd/... ./integration-test/... ./internal/... - - name: run integration tests - # we don't have 'make' on windows. - run: | - go test --tags=integration ./cmd/... ./integration-test/... ./internal/... - - test-build: - name: Test binary compilation for all platforms:arch - runs-on: ubuntu-20.04 - steps: - - name: checkout - uses: actions/checkout@v2 - - name: Login to DockerHub - uses: docker/login-action@v1 - with: - username: ${{ secrets.OHAI_DOCKER_HUB_ID }} - password: ${{ secrets.OHAI_DOCKER_HUB_PASSWORD }} - - name: Build all platforms:arch - run: make ci/pre-release - - test-e2e: - name: Run e2e tests - runs-on: ubuntu-20.04 - steps: - - uses: actions/checkout@v2 - - name: Login to DockerHub - uses: docker/login-action@v1 - with: - username: ${{ secrets.OHAI_DOCKER_HUB_ID }} - password: ${{ secrets.OHAI_DOCKER_HUB_PASSWORD }} - - name: Install go - uses: actions/setup-go@v4 - with: - go-version-file: 'go.mod' - - name: Run e2e tests - run: make test-e2e - - finish: - name: Finish - needs: [ test-nix, test-windows ] - runs-on: ubuntu-20.04 - steps: - - name: Coveralls Finished - uses: coverallsapp/github-action@master - with: - github-token: ${{ secrets.github_token }} - parallel-finished: true diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 92d5ea887..000000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,126 +0,0 @@ ---- -name: Release pipeline - -on: - release: - types: - - prereleased - tags: - - 'v*' - -env: - TAG: ${{ github.event.release.tag_name }} - IS_RELEASE: true - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # needed for goreleaser - -jobs: - - test-nix: - strategy: - matrix: - os: [ ubuntu-20.04 ] - name: Run unit tests in ${{matrix.os}} - runs-on: ${{matrix.os}} - steps: - - name: checkout code - uses: actions/checkout@v2 - - name: Install go - uses: actions/setup-go@v4 - with: - go-version-file: 'go.mod' - - name: Run unit tests - run: make ci/test - - name: Convert coverage.out to lcov.info - run: make ci/convert-coverage - - name: Coveralls Parallel - uses: coverallsapp/github-action@master - with: - github-token: ${{ secrets.github_token }} - path-to-lcov: lcov.info - flag-name: run-linux - parallel: true - - test-integration-nix: - name: Run integration tests - runs-on: ubuntu-20.04 - steps: - - uses: actions/checkout@v2 - - name: Login to DockerHub - uses: docker/login-action@v1 - with: - username: ${{ secrets.OHAI_DOCKER_HUB_ID }} - password: ${{ secrets.OHAI_DOCKER_HUB_PASSWORD }} - - name: Run integration tests - run: make test-integration - - snyk: - name: Run security checks via snyk - runs-on: ubuntu-20.04 - steps: - - uses: actions/checkout@v2 - - name: Login to DockerHub - uses: docker/login-action@v1 - with: - username: ${{ secrets.OHAI_DOCKER_HUB_ID }} - password: ${{ secrets.OHAI_DOCKER_HUB_PASSWORD }} - - name: Scan code for vulnerabilities - env: - SNYK_TOKEN: ${{ secrets.CAOS_SNYK_TOKEN }} - run: make ci/snyk-test - - test-windows: - strategy: - matrix: - go: [ '1.21' ] - os: [ windows-2019 ] - name: Run unit and integration tests in ${{matrix.os}} with go ${{matrix.go}} - runs-on: ${{matrix.os}} - steps: - - name: checkout - uses: actions/checkout@v2 - - name: install go - uses: actions/setup-go@v4 - with: - go-version-file: 'go.mod' - - name: run unit tests - # we don't have 'make' on windows. - shell: bash - run: | - go test ./cmd/... ./integration-test/... ./internal/... - - name: run integration tests - # we don't have 'make' on windows. - shell: bash - run: | - go test --tags=integration ./cmd/... ./integration-test/... ./internal/... - - prerelease: - name: Build and release binaries - runs-on: ubuntu-20.04 - needs: [ test-nix, test-windows, snyk, test-integration-nix ] - steps: - - uses: actions/checkout@v2 - - name: Login to DockerHub - uses: docker/login-action@v1 - with: - username: ${{ secrets.OHAI_DOCKER_HUB_ID }} - password: ${{ secrets.OHAI_DOCKER_HUB_PASSWORD }} - - name: Pre release - run: make ci/pre-release - - name: Notify failure via Slack - if: ${{ failure() }} - uses: archive/github-actions-slack@master - with: - slack-bot-user-oauth-access-token: ${{ secrets.COREINT_SLACK_TOKEN }} - slack-channel: ${{ secrets.COREINT_SLACK_CHANNEL }} - slack-text: "❌ `${{ env.REPO_FULL_NAME }}`: prerelease pipeline failed." - - finish: - name: Finish - needs: [ prerelease ] - runs-on: ubuntu-20.04 - steps: - - name: Coveralls Finished - uses: coverallsapp/github-action@master - with: - github-token: ${{ secrets.github_token }} - parallel-finished: true diff --git a/.github/workflows/repolinter.yml b/.github/workflows/repolinter.yml deleted file mode 100644 index acb921f30..000000000 --- a/.github/workflows/repolinter.yml +++ /dev/null @@ -1,31 +0,0 @@ -# NOTE: This file should always be named `repolinter.yml` to allow -# workflow_dispatch to work properly -name: Repolinter Action - -# NOTE: This workflow will ONLY check the default branch! -# Currently there is no elegant way to specify the default -# branch in the event filtering, so branches are instead -# filtered in the "Test Default Branch" step. -on: [push, workflow_dispatch] - -jobs: - repolint: - name: Run Repolinter - runs-on: ubuntu-latest - steps: - - name: Test Default Branch - id: default-branch - uses: actions/github-script@v2 - with: - script: | - const data = await github.repos.get(context.repo) - return data.data && data.data.default_branch === context.ref.split('/').slice(-1)[0] - - name: Checkout Self - if: ${{ steps.default-branch.outputs.result == 'true' }} - uses: actions/checkout@v2 - - name: Run Repolinter - if: ${{ steps.default-branch.outputs.result == 'true' }} - uses: newrelic/repolinter-action@v1 - with: - config_url: https://raw.githubusercontent.com/newrelic/.github/main/repolinter-rulesets/community-plus.yml - output_type: issue From 799c6a6b4b14a10af9add1fe56567ae73c20f422 Mon Sep 17 00:00:00 2001 From: Vaughn Woerpel Date: Thu, 10 Oct 2024 12:29:37 -0400 Subject: [PATCH 2/3] test --- .github/workflows/codeql.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index cf62ead1c..d4a2e8604 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -33,7 +33,7 @@ jobs: matrix: include: - language: go - build-mode: autobuild + build-mode: manual # CodeQL supports the following values keywords for 'language': 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift' # Use `c-cpp` to analyze code written in C, C++ or both # Use 'java-kotlin' to analyze code written in Java, Kotlin or both From 626469566e4f39f25077044d90ec6e06b873c866 Mon Sep 17 00:00:00 2001 From: Vaughn Woerpel Date: Thu, 10 Oct 2024 12:34:26 -0400 Subject: [PATCH 3/3] Test --- .github/workflows/codeql.yml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index d4a2e8604..58ed0735e 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -68,12 +68,8 @@ jobs: - if: matrix.build-mode == 'manual' shell: bash run: | - echo 'If you are using a "manual" build mode for one or more of the' \ - 'languages you are analyzing, replace this with the commands to build' \ - 'your code, for example:' - echo ' make bootstrap' - echo ' make release' - exit 1 + make bin + make build - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v3