diff --git a/src/codeql/devcontainer-feature.json b/src/codeql/devcontainer-feature.json index 0af2bb8..1d2536e 100644 --- a/src/codeql/devcontainer-feature.json +++ b/src/codeql/devcontainer-feature.json @@ -7,9 +7,9 @@ "codeql_version": { "type": "string", "proposals": [ - "2.19.1" + "latest" ], - "default": "2.19.1", + "default": "latest", "description": "Select the version of the CodeQL CLI to install" } }, diff --git a/src/codeql/install.sh b/src/codeql/install.sh index 3c281e2..a6d9209 100644 --- a/src/codeql/install.sh +++ b/src/codeql/install.sh @@ -2,7 +2,7 @@ set -e CODEQL_HOME=/usr/local/codeql-home - +CODEQL_TAG="" echo "Activating feature 'CodeQL'" echo "The provided CodeQL version is: $CODEQL_VERSION" echo "The CodeQL home directory is: $CODEQL_HOME" @@ -19,59 +19,52 @@ echo "The effective dev container remoteUser's home directory is '$_REMOTE_USER_ echo "The effective dev container containerUser is '$_CONTAINER_USER'" echo "The effective dev container containerUser's home directory is '$_CONTAINER_USER_HOME'" + check_version() { - if [ -z "$1" ]; then - echo "Version is not provided" - exit 1 - fi + echo "Checking version" - if ! [[ "$1" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then - echo "Version is not valid. Please provide a valid version" - exit 1 + # Set the codeql version to the latest if it is not provided + if [ "$CODEQL_VERSION" = "latest" ]; then + CODEQL_TAG=$(curl -s https://api.github.com/repos/github/codeql-action/releases/latest | jq -r '.tag_name') + echo "Setting the CodeQL version to the latest: $CODEQL_TAG" + else + CODEQL_TAG="codeql-bundle-v$CODEQL_VERSION" + echo "Using provided version: $CODEQL_TAG" fi } -install_packages(){ +install_packages() { + echo "Installing required packages" + apt-get update && \ apt-get upgrade -y && \ apt-get install -y --no-install-recommends \ - software-properties-common \ curl \ - git \ - git-lfs \ - build-essential \ - unzip \ - apt-transport-https \ - python3.10 \ - python3-venv \ - python3-pip \ - python3-setuptools \ - python3-dev \ - python-is-python3 \ - gnupg \ - g++ \ - make \ - gcc \ - apt-utils - - # Clean up - apt-get clean && apt-get autoremove + jq \ + ca-certificates + + update-ca-certificates + + echo "Installed packages:" + curl --version + jq --version } -install_codeql(){ +install_codeql() { + echo "Installing CodeQL" mkdir ${CODEQL_HOME} # Install CodeQL cd /tmp - echo "Downloading CodeQL bundle v${CODEQL_VERSION}" - curl -OL https://github.com/github/codeql-action/releases/download/codeql-bundle-v${CODEQL_VERSION}/codeql-bundle-linux64.tar.gz + echo "Downloading CodeQL bundle v${CODEQL_TAG}" + curl -OL https://github.com/github/codeql-action/releases/download/${CODEQL_TAG}/codeql-bundle-linux64.tar.gz tar -xvf /tmp/codeql-bundle-linux64.tar.gz --directory ${CODEQL_HOME} rm /tmp/codeql-bundle-linux64.tar.gz } -check_version +install_packages -#install_packages +check_version install_codeql \ No newline at end of file diff --git a/test/codeql/codeql_version.sh b/test/codeql/codeql_version.sh index d316de8..ccf0a29 100644 --- a/test/codeql/codeql_version.sh +++ b/test/codeql/codeql_version.sh @@ -10,7 +10,6 @@ source dev-container-features-test-lib # Feature-specific tests # The 'check' command comes from the dev-container-features-test-lib. -check "execute command" bash -c "color | grep 'CodeQL installed at /usr/local/codeql-home and version is 2.19.1" check "Validate CodeQL Version installed" codeql --version | grep "$CODEQL_VERSION" # Report result diff --git a/test/codeql/scenarios.json b/test/codeql/scenarios.json index 37a536a..37fbdde 100644 --- a/test/codeql/scenarios.json +++ b/test/codeql/scenarios.json @@ -1,5 +1,5 @@ { - "check_codeql_version": { + "codeql_version": { "image": "mcr.microsoft.com/devcontainers/base:ubuntu", "features": { "codeql": {