|
| 1 | +# For most projects, this workflow file will not need changing; you simply need |
| 2 | +# to commit it to your repository. |
| 3 | +# |
| 4 | +# You may wish to alter this file to override the set of languages analyzed, |
| 5 | +# or to provide custom queries or build logic. |
| 6 | +# |
| 7 | +# ******** NOTE ******** |
| 8 | +# We have attempted to detect the languages in your repository. Please check |
| 9 | +# the `language` matrix defined below to confirm you have the correct set of |
| 10 | +# supported CodeQL languages. |
| 11 | +# |
| 12 | +name: "GHA-06: CodeQL Java" |
| 13 | + |
| 14 | +on: |
| 15 | + push: |
| 16 | + branches: [ "master" ] |
| 17 | + pull_request: |
| 18 | + # The branches below must be a subset of the branches above |
| 19 | + branches: [ "master" ] |
| 20 | + schedule: |
| 21 | + - cron: '32 12 * * 0' |
| 22 | + workflow_dispatch: |
| 23 | + # Allow manually running the action, e.g. if disabled after some quietness in the source |
| 24 | + |
| 25 | +jobs: |
| 26 | + analyze: |
| 27 | + name: Analyze |
| 28 | + runs-on: ${{ matrix.os }} |
| 29 | + permissions: |
| 30 | + actions: read |
| 31 | + contents: read |
| 32 | + security-events: write |
| 33 | + |
| 34 | + strategy: |
| 35 | + fail-fast: false |
| 36 | + matrix: |
| 37 | + # https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs |
| 38 | + language: [ 'java' ] |
| 39 | + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] |
| 40 | + # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support |
| 41 | + compilerpkg: [ 'openjdk-21-jdk' ] |
| 42 | + # TOTHINK: various JDK versions? |
| 43 | + os: [ 'ubuntu-latest' ] |
| 44 | + # TOTHINK: windows-latest, macos-latest? |
| 45 | + build-mode: [ 'autobuild' ] |
| 46 | + # manual ? |
| 47 | + # https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages |
| 48 | + # Abusing "manual" here to try building with ccache (and |
| 49 | + # have codeql not intercept that build but parse C/C++ |
| 50 | + # files on its own), and "manual" to custom-build without; |
| 51 | + # the "autobuild" mode is handled by codeql itself but |
| 52 | + # would probably ignore our CC/CXX setting |
| 53 | + # NOTE: We do not add ccache to PATH when actually compiling NUT code |
| 54 | + # (we only speed up "configure" stages), so compilation always happens |
| 55 | + # and is parsed by current CodeQL detectors of the day as they evolve! |
| 56 | + |
| 57 | + steps: |
| 58 | + - name: Checkout repository |
| 59 | + uses: actions/checkout@v3 |
| 60 | + |
| 61 | + # Using hints from https://askubuntu.com/questions/272248/processing-triggers-for-man-db |
| 62 | + - if: matrix.language == 'java' && matrix.os == 'ubuntu-latest' |
| 63 | + name: NUT CI Prerequisite packages (Ubuntu) |
| 64 | + run: | |
| 65 | + echo "set man-db/auto-update false" | sudo debconf-communicate |
| 66 | + sudo dpkg-reconfigure man-db |
| 67 | + sudo apt update |
| 68 | + sudo apt install ${{ matrix.compilerpkg }} maven |
| 69 | + date > .timestamp-init |
| 70 | +
|
| 71 | + - name: Prepare maven cache |
| 72 | + # Based on https://docs.github.com/en/actions/reference/workflows-and-actions/dependency-caching#example-using-the-cache-action example |
| 73 | + id: cache-m2cache |
| 74 | + uses: actions/cache@v4 |
| 75 | + env: |
| 76 | + cache-name: cache-m2cache- |
| 77 | + with: |
| 78 | + path: | |
| 79 | + ~/.m2 |
| 80 | + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/.timestamp-init') }} |
| 81 | + restore-keys: | |
| 82 | + ${{ runner.os }}-build-${{ env.cache-name }}- |
| 83 | + ${{ runner.os }}-build- |
| 84 | + ${{ runner.os }}- |
| 85 | +
|
| 86 | + # Initializes the CodeQL tools for scanning. |
| 87 | + - name: Initialize CodeQL |
| 88 | + uses: github/codeql-action/init@v3 |
| 89 | + with: |
| 90 | + languages: ${{ matrix.language }} |
| 91 | + build-mode: ${{ matrix.build-mode }} |
| 92 | + # If you wish to specify custom queries, you can do so here or in a config file. |
| 93 | + # By default, queries listed here will override any specified in a config file. |
| 94 | + # Prefix the (whole) list here with "+" to use these queries and those in the config file. |
| 95 | + # 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 |
| 96 | + queries: +security-extended,security-and-quality |
| 97 | + config-file: ./.github/codeql/codeql-config.yml |
| 98 | + |
| 99 | + # Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java). |
| 100 | + # If this step fails, then you should remove it and run the build manually (see below) |
| 101 | + # https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages |
| 102 | + - if: matrix.build-mode == 'autobuild' |
| 103 | + name: Autobuild |
| 104 | + uses: github/codeql-action/autobuild@v3 |
| 105 | + |
| 106 | + # ℹ️ Command-line programs to run using the OS shell. |
| 107 | + # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun |
| 108 | + |
| 109 | + - if: matrix.build-mode != 'autobuild' && matrix.language == 'java' |
| 110 | + name: Maven build and test |
| 111 | + run: mvn package |
| 112 | + |
| 113 | + - name: Perform CodeQL Analysis |
| 114 | + uses: github/codeql-action/analyze@v3 |
| 115 | + with: |
| 116 | + category: "/language:${{matrix.language}}" |
0 commit comments