From dda589380fb71f27df44eb57ca4ca55c77416c21 Mon Sep 17 00:00:00 2001 From: Whisperity Date: Sat, 27 Nov 2021 12:34:26 +0100 Subject: [PATCH] Wire in downloading and installing LLVM from PPA --- .github/workflows/test.yml | 14 +++++++++++-- README.md | 18 +++++++++++------ action.yml | 41 ++++++++++++++++++++++++++------------ src/apt-dependencies.sh | 9 +++++++++ src/get-llvm.sh | 23 +++++++++++++++++++++ 5 files changed, 84 insertions(+), 21 deletions(-) create mode 100755 src/apt-dependencies.sh create mode 100755 src/get-llvm.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4bb2820..f76e62e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,11 +8,21 @@ on: - 'releases/*' jobs: - ubuntu_2004: - name: "Ubuntu Linux 20.04" + ubuntu_2004_latestllvm: + name: "Ubuntu Linux 20.04 (latest LLVM)" runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - uses: ./ with: version: "master" + llvm-version: "latest" + ubuntu_1804_12llvm: + name: "Ubuntu Linux 18.04 (LLVM 12.y)" + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + - uses: ./ + with: + version: "master" + llvm-version: 12 diff --git a/README.md b/README.md index bd4708f..4cc735b 100644 --- a/README.md +++ b/README.md @@ -6,14 +6,20 @@ Objective-C) using the [Clang](http://clang.llvm.org/) infrastructure and ## Overview -:warning: **This action has been written with commands that target Ubuntu-based distributions!** +⚠️ **CAUTION! This action has been written with commands that target Ubuntu-based distributions!** + +This single action composite script encompasses the following steps: + + 1. Obtain a package of the LLVM Clang suite's analysers, and CodeChecker. + ## Action configuration -### Installing versions -| 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. | +### 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) | diff --git a/action.yml b/action.yml index 7546157..b631379 100644 --- a/action.yml +++ b/action.yml @@ -1,6 +1,10 @@ name: 'CodeChecker Static Analysis' author: 'Whisperity' description: 'Execute C/C++ static analysis of LLVM/Clang (Clang Static Analyzer and Clang-Tidy) driven via CodeChecker.' +branding: + icon: 'tool' + color: 'blue' + inputs: repository: description: 'The CodeChecker repository to check out and build from.' @@ -10,6 +14,11 @@ inputs: description: 'The version of the CodeChecker suite to obtain and execute. Might be a Git commit SHA, a branch name, or a tag.' required: true default: 'master' + llvm-version: + description: 'The major version of LLVM to install and use. LLVM is installed from PPA. If "latest", automatically gather the latest version. If "ignore", do not install anything. (Not recommended)' + required: true + default: 'latest' + runs: using: "composite" steps: @@ -20,23 +29,29 @@ runs: path: CodeChecker ref: ${{ inputs.version }} - - name: "Install dependencies of CodeChecker" shell: bash run: | sudo apt-get -qy update - sudo apt-get -y --no-install-recommends install \ - build-essential \ - curl \ - gcc-multilib \ - python3-dev \ - python3-venv - - name: "Build and Package CodeChecker" - id: codechecker_build + ${{ github.action_path }}/src/apt-dependencies.sh + + - name: "Install LLVM version" + id: llvm + if: ${{ inputs.llvm-version != 'ignore' }} env: - CODECHECKER_WILL_USE_WEB_API: false + CONFIGURED_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-)" + + - name: "Build and Package CodeChecker" + id: codechecker + env: + CODECHECKER_WILL_USE_WEB_API: false # TODO: Add support for this later. + 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..." @@ -58,8 +73,8 @@ runs: echo "CodeChecker 'web' package not built." fi - echo "::set-output name=CODECHECKER_PATH::$(readlink -f ./build/CodeChecker/bin)" - echo "::set-output name=CODECHECKER_VERSION::$(./build/CodeChecker/bin/CodeChecker analyzer-version | grep 'Base package' | cut -d'|' -f 2 | tr -d ' ')" - echo "::set-output name=CODECHECKER_GITSEVEN::$(./build/CodeChecker/bin/CodeChecker analyzer-version | grep 'Git commit' | cut -d'|' -f 2 | cut -c 2-8)" + 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/apt-dependencies.sh b/src/apt-dependencies.sh new file mode 100755 index 0000000..f29a2c1 --- /dev/null +++ b/src/apt-dependencies.sh @@ -0,0 +1,9 @@ +#!/bin/bash +set -ex + +sudo apt-get -y --no-install-recommends install \ + build-essential \ + curl \ + gcc-multilib \ + python3-dev \ + python3-venv diff --git a/src/get-llvm.sh b/src/get-llvm.sh new file mode 100755 index 0000000..e207937 --- /dev/null +++ b/src/get-llvm.sh @@ -0,0 +1,23 @@ +#!/bin/bash +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 + 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" +fi + +sudo apt-get -y --no-install-recommends install \ + clang-$LLVM_VER \ + clang-tidy-$LLVM_VER +sudo update-alternatives --install \ + /usr/bin/clang clang /usr/bin/clang-$LLVM_VER 1000 \ + --slave \ + /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-$LLVM_VER +update-alternatives --query clang