From 995207439b2bcc297253ad27556c4f460dbc69d7 Mon Sep 17 00:00:00 2001 From: Whisperity Date: Mon, 29 Nov 2021 17:42:43 +0100 Subject: [PATCH] feat: Grab CodeChecker release from PyPI by default --- .github/workflows/test.yml | 49 ++++++++++++++++----------- README.md | 11 +++--- action.yml | 69 +++++++++++++------------------------- src/apt-dependencies.sh | 9 ----- src/build-codechecker.sh | 37 ++++++++++++++++++++ src/get-llvm.sh | 8 +++-- src/pip-codechecker.sh | 20 +++++++++++ 7 files changed, 121 insertions(+), 82 deletions(-) delete mode 100755 src/apt-dependencies.sh create mode 100755 src/build-codechecker.sh create mode 100755 src/pip-codechecker.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9cf7c7f..713e023 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,30 +12,39 @@ on: - '**.md' jobs: - # Fetch tests do not produce results, but test the functionality of the - # "grab LLVM" and "grab and build CodeChecker" features. - fetch_ubuntu-2004_latest-llvm: - name: "Fetch: Ubuntu Linux 20.04 (latest LLVM)" - runs-on: ubuntu-20.04 + fetch-tests: + strategy: + fail-fast: false + matrix: + include: + - os: ubuntu-18.04 + install-custom: true + version: v6.16.0 + llvm-version: '12' + - os: ubuntu-20.04 + install-custom: false + version: 6.17.0 + llvm-version: '13' + - os: ubuntu-20.04 + install-custom: true + version: master + llvm-version: 'latest' + - os: ubuntu-20.04 + install-custom: false + version: master + llvm-version: 'latest' + name: "Fetch: ${{ matrix.os }}, LLVM ${{ matrix.llvm-version }}, ${{ matrix.install-custom && 'repository' || 'pip' }} ${{ matrix.version }}" + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2 - uses: ./ + id: codechecker with: - version: "master" - llvm-version: "latest" - logfile: "test/empty/compile_commands.json" - fetch_ubuntu-1804_12-llvm: - name: "Fetch: Ubuntu Linux 18.04 (LLVM 12.y)" - runs-on: ubuntu-18.04 - steps: - - uses: actions/checkout@v2 - - uses: ./ - with: - version: "master" - llvm-version: 12 + install-custom: ${{ matrix.install-custom }} + version: ${{ matrix.version }} + llvm-version: ${{ matrix.llvm-version }} logfile: "test/empty/compile_commands.json" - # Test simple build and analysis configuration. simple-analysis-tests: strategy: fail-fast: false @@ -169,7 +178,7 @@ jobs: id: codechecker continue-on-error: true with: - version: "v${{ env.CODECHECKER_VERSION }}" + version: "${{ env.CODECHECKER_VERSION }}" logfile: 'test/simple/compile_commands.json' store: true store-url: 'http://0.0.0.0:8001/Default' @@ -179,7 +188,7 @@ jobs: id: test continue-on-error: true run: docker logs codechecker-server | grep "stored results" - - name: "Teardown CodeChecker server" + - name: "Tear down CodeChecker server" run: | set -x diff --git a/README.md b/README.md index c0a7092..0e2d814 100644 --- a/README.md +++ b/README.md @@ -105,11 +105,12 @@ runs: ### Versions to install -| Variable | Default | Description | -|----------------|------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `repository` | [`Ericsson/CodeChecker`](http://github.com/Ericsson/CodeChecker) | The CodeChecker repository to check out and build | -| `version` | `master` | The branch, tag, or commit SHA in the `repository` to use. | -| `llvm-version` | `latest` | The major version of LLVM to install and use. LLVM is installed from [PPA](http://apt.llvm.org/). If `latest`, automatically gather the latest version. If `ignore`, don't install anything. (Not recommended) | +| Variable | Default | Description | +|------------------|------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `install-custom` | `false` | If set to `true`, opens the ability to locally clone and install CodeChecker from the specified `repository` and `version`. Otherwise, `version` is taken as a release version, and the [CodeChecker suite from PyPI](http://pypi.org/project/codechecker) is downloaded. | +| `repository` | [`Ericsson/CodeChecker`](http://github.com/Ericsson/CodeChecker) | The CodeChecker repository to check out and build, if `install-custom` is `true`. | +| `version` | `master` | If `install-custom` is `false`, the release version (e.g. `6.18.0`) to download from PyPI, or `master` to fetch the latest release. Otherwise, the branch (defaulting to `master`), tag, or commit SHA in the `repository` to check out. | +| `llvm-version` | `latest` | The major version of LLVM to install and use. LLVM is installed from [PPA](http://apt.llvm.org/). If `latest`, automatically gather the latest version. If `ignore`, don't install anything. (Not recommended) | ### Build log configuration diff --git a/action.yml b/action.yml index 56f29c6..5e19e7c 100644 --- a/action.yml +++ b/action.yml @@ -6,12 +6,16 @@ branding: color: 'blue' inputs: + install-custom: + description: 'Whether to download, check out, and build a CodeChecker package manually in the CI.' + required: true + default: 'false' repository: description: 'The CodeChecker repository to check out and build from.' required: true default: 'Ericsson/CodeChecker' version: - description: 'The version of the CodeChecker suite to obtain and execute. Might be a Git commit SHA, a branch name, or a tag.' + description: 'The version of the CodeChecker suite to obtain and execute. Might be a Git commit SHA, a branch name, or a tag if building a custom package, or a release version if downloading from PyPI. If "master" and downloading from PyPI, fetch the latest release.' required: true default: 'master' llvm-version: @@ -32,24 +36,24 @@ inputs: analyze-output: description: 'The output directory where the raw analysis output should be stored. If left the default empty, the path will be generated automatically.' - default: '' required: false + default: '' ctu: description: 'Whether to enable Cross Translation Unit (CTU) analysis in the Clang Static Analyzer.' - default: 'false' required: true + default: 'false' fail-build-if-reports: description: 'Whether to fail the build if static analysis warnings are emitted.' - default: 'false' required: true + default: 'false' store: - description: 'Whether to enable storing the results to a CodeChecker server. If enabled, other flags, such as `store-url` must also be set.' - default: 'false' + description: 'Whether to enable storing the results to a CodeChecker server. If enabled, other flags, such as "store-url" must also be set.' required: true + default: 'false' store-url: - description: 'The CodeChecker product URL (usually in the format of http://example.com/ProductName) where the store should connect to. Mandatory if `store` is true.' + description: 'The CodeChecker product URL (usually in the format of http://example.com/ProductName) where the store should connect to. Mandatory if "store" is true.' required: false store-username: description: 'If the server requires authentication, the username to authenticate with.' @@ -59,8 +63,8 @@ inputs: required: false store-run-name: description: 'An identifying name of the analysis run. A run usually correlates to a set of configuration, e.g. analysis mode, branch, etc. If left default, the name is automatically generated from the current repository and branch name.' - default: '__DEFAULT__' required: true + default: '__DEFAULT__' outputs: logfile: @@ -90,61 +94,36 @@ runs: steps: - name: "Check out repository ${{ inputs.repository }}" uses: actions/checkout@v2 + if: ${{ inputs.install-custom == 'true' }} with: - repository: ${{ inputs.repository }} path: CodeChecker + repository: ${{ inputs.repository }} ref: ${{ inputs.version }} - - name: "Install dependencies of CodeChecker" - shell: bash - run: | - sudo apt-get -qy update - ${{ github.action_path }}/src/apt-dependencies.sh - - - name: "Install LLVM version" + - name: "Install LLVM (${{ inputs.llvm-version }})" id: llvm if: ${{ inputs.llvm-version != 'ignore' }} env: - CONFIGURED_LLVM_VERSION: ${{ inputs.llvm-version }} + IN_LLVM_VERSION: ${{ inputs.llvm-version }} shell: bash - run: | - ${{ github.action_path }}/src/get-llvm.sh - echo "::set-output name=REAL_VERSION::$(clang --version | head -n 1 | cut -d' ' -f4-)" + run: ${{ github.action_path }}/src/get-llvm.sh - name: "Build and Package CodeChecker" id: codechecker env: CODECHECKER_WILL_USE_WEB_API: ${{ inputs.store == 'true' }} + + IN_INSTALL_CUSTOM: ${{ inputs.install-custom }} + IN_VERSION: ${{ inputs.version }} shell: bash run: | - set -ex - if [[ "$CODECHECKER_WILL_USE_WEB_API" == "false" ]]; then - # If the job is only running analysis, do not spend time with building the API stuff! - echo "Building only 'analyzer' module..." - pushd CodeChecker/analyzer + set -x + if [[ "$IN_INSTALL_CUSTOM" == "true" ]]; then + ${{ github.action_path }}/src/build-codechecker.sh else - echo "Building full CodeChecker package..." - pushd CodeChecker + ${{ github.action_path }}/src/pip-codechecker.sh fi - make venv - source venv/bin/activate - BUILD_UI_DIST=NO make standalone_package - deactivate - - ./build/CodeChecker/bin/CodeChecker analyzer-version - if [[ "$CODECHECKER_WILL_USE_WEB_API" == "true" ]]; then - ./build/CodeChecker/bin/CodeChecker web-version - else - echo "CodeChecker 'web' package not built." - fi - - echo "::set-output name=PATH::$(readlink -f ./build/CodeChecker/bin)" - echo "::set-output name=VERSION::$(./build/CodeChecker/bin/CodeChecker analyzer-version | grep 'Base package' | cut -d'|' -f 2 | tr -d ' ')" - echo "::set-output name=GITSEVEN::$(./build/CodeChecker/bin/CodeChecker analyzer-version | grep 'Git commit' | cut -d'|' -f 2 | cut -c 2-8)" - - popd - - name: "Prepare JSON Compilation Database" id: log env: diff --git a/src/apt-dependencies.sh b/src/apt-dependencies.sh deleted file mode 100755 index 171b43e..0000000 --- a/src/apt-dependencies.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -set -x - -sudo apt-get -y --no-install-recommends install \ - build-essential \ - curl \ - gcc-multilib \ - python3-dev \ - python3-venv diff --git a/src/build-codechecker.sh b/src/build-codechecker.sh new file mode 100755 index 0000000..a1f2c77 --- /dev/null +++ b/src/build-codechecker.sh @@ -0,0 +1,37 @@ +#!/bin/bash +set -ex + +sudo apt-get -y update +sudo apt-get -y --no-install-recommends install \ + build-essential \ + curl \ + gcc-multilib \ + python3-dev \ + python3-venv + +if [[ "$CODECHECKER_WILL_USE_WEB_API" == "false" ]]; then + # If the job is only running analysis, do not spend time with building the API stuff! + echo "Building only 'analyzer' module..." + pushd CodeChecker/analyzer +else + echo "Building full CodeChecker package..." + pushd CodeChecker +fi + +make venv +source venv/bin/activate +BUILD_UI_DIST=NO make standalone_package +deactivate + +./build/CodeChecker/bin/CodeChecker analyzer-version +if [[ "$CODECHECKER_WILL_USE_WEB_API" == "true" ]]; then + ./build/CodeChecker/bin/CodeChecker web-version +else + echo "CodeChecker 'web' package not built." +fi + +echo "::set-output name=PATH::$(readlink -f ./build/CodeChecker/bin)" +echo "::set-output name=VERSION::$(./build/CodeChecker/bin/CodeChecker analyzer-version | grep 'Base package' | cut -d'|' -f 2 | tr -d ' ')" +echo "::set-output name=GITSEVEN::$(./build/CodeChecker/bin/CodeChecker analyzer-version | grep 'Git commit' | cut -d'|' -f 2 | cut -c 2-8)" + +popd diff --git a/src/get-llvm.sh b/src/get-llvm.sh index e207937..e1a6795 100755 --- a/src/get-llvm.sh +++ b/src/get-llvm.sh @@ -4,13 +4,13 @@ set -ex export DISTRO_FANCYNAME="$(lsb_release -c | awk '{ print $2 }')" curl -sL http://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - -if [[ "$CONFIGURED_LLVM_VERSION" == "latest" ]]; then +if [[ "$IN_LLVM_VERSION" == "latest" ]]; then sudo add-apt-repository -y "deb http://apt.llvm.org/$DISTRO_FANCYNAME/ llvm-toolchain-$DISTRO_FANCYNAME main" # Get the largest Clang package number available. export LLVM_VER="$(apt-cache search --full 'clang-[[:digit:]]*$' | grep '^Package: clang' | cut -d ' ' -f 2 | sort -V | tail -n 1 | sed 's/clang-//')" else - sudo add-apt-repository -y "deb http://apt.llvm.org/$DISTRO_FANCYNAME/ llvm-toolchain-$DISTRO_FANCYNAME-$CONFIGURED_LLVM_VERSION main" - export LLVM_VER="$CONFIGURED_LLVM_VERSION" + sudo add-apt-repository -y "deb http://apt.llvm.org/$DISTRO_FANCYNAME/ llvm-toolchain-$DISTRO_FANCYNAME-$IN_LLVM_VERSION main" + export LLVM_VER="$IN_LLVM_VERSION" fi sudo apt-get -y --no-install-recommends install \ @@ -21,3 +21,5 @@ sudo update-alternatives --install \ --slave \ /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-$LLVM_VER update-alternatives --query clang + +echo "::set-output name=REAL_VERSION::$(clang --version | head -n 1 | cut -d' ' -f4-)" diff --git a/src/pip-codechecker.sh b/src/pip-codechecker.sh new file mode 100755 index 0000000..b2769e2 --- /dev/null +++ b/src/pip-codechecker.sh @@ -0,0 +1,20 @@ +#!/bin/bash +set -x + +if [[ "$IN_VERSION" == "master" ]]; then + # The default branch name "master" is offered as a convenient shortcut for + # fetching the latest release. + pip3 install codechecker +else + pip3 install codechecker=="$IN_VERSION" +fi + +pip3 show codechecker +which CodeChecker + +CodeChecker analyzer-version +CodeChecker web-version + +echo "::set-output name=PATH::$(dirname $(which CodeChecker))" +echo "::set-output name=VERSION::$(CodeChecker analyzer-version | grep 'Base package' | cut -d'|' -f 2 | tr -d ' ')" +echo "::set-output name=GITSEVEN::$(CodeChecker analyzer-version | grep 'Git commit' | cut -d'|' -f 2 | cut -c 2-8)"