From 5e88c1cf956364865470359fa42d1bfdb392fc74 Mon Sep 17 00:00:00 2001 From: Lingjie Li Date: Sun, 4 Feb 2024 13:25:45 +0800 Subject: [PATCH] build: tidy & add cleanup for actions --- .github/workflows/static.yml | 45 +++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 60a2eecc..c8b0b212 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -8,11 +8,9 @@ on: pull_request: env: + DEEPLINK_PATH: /mnt/cache/share/deeplinkci/github/${{ github.repository }} ENV_SOURCE: /mnt/cache/share/platform/env/dipu_latest PROXY_SOURCE: /mnt/cache/share/platform/env/proxy - WORKSPACE: /mnt/cache/share/deeplinkci/github/${{ github.repository }}/${{ github.run_number }} - CODE_SOURCE: source - CLANGD_TIDY_SOURCE: clangd-tidy CLANGD_EXEC: /mnt/cache/share/platform/dep/clang-17/bin/clangd concurrency: @@ -20,21 +18,34 @@ concurrency: cancel-in-progress: true jobs: - checkout-code: - name: checkout code + static-checks-on-sco: + name: static checks on sco runs-on: tps-sco-ci steps: - - name: prepare workspace + - name: setting up environment run: | set -euxo pipefail - mkdir -p ${WORKSPACE} && cd ${WORKSPACE} && pwd + set_env() { + echo "$1=$2" >> "${GITHUB_ENV}" + eval "$1=\"\$2\"" + } + set_env WORKSPACE "${DEEPLINK_PATH}/${{ github.run_number }}" + set_env CODE_SOURCE "${WORKSPACE}/source" + set_env CLANGD_TIDY_SOURCE "${WORKSPACE}/clangd-tidy" + set_env CLANGD_TIDY_LOG "${WORKSPACE}/clang-tidy.log" + - name: clean obsolete workspaces & prepare workspace + run: | + set -euxo pipefail + ls -la ${DEEPLINK_PATH} + rm -rf ${WORKSPACE} + find ${DEEPLINK_PATH} -maxdepth 1 -mmin +480 -type d -exec bash -c 'echo clean "$0" && rm -rf "$0"' {} \; + mkdir -p ${WORKSPACE} - name: checkout code run: | set -euo pipefail source ${PROXY_SOURCE} set -x - cd ${WORKSPACE} && pwd - [[ ! -d ${CODE_SOURCE} ]] || rm -rf ${CODE_SOURCE} + rm -rf ${CODE_SOURCE} if [ -n "${{ github.event.pull_request.head.repo.full_name }}" ] && [[ ! "${{ github.event.pull_request.head.repo.full_name }}" == "${{ github.repository }}" ]]; then git clone ${{ github.event.pull_request.head.repo.clone_url }} ${CODE_SOURCE} cd ${CODE_SOURCE} && git checkout ${{ github.event.pull_request.head.sha }} @@ -54,19 +65,17 @@ jobs: set -euo pipefail source ${PROXY_SOURCE} set -x - cd ${WORKSPACE}/${CODE_SOURCE} && pwd git -c advice.detachedHead=false clone --depth 1 -b v0.1.3 https://github.com/lljbash/clangd-tidy.git ${CLANGD_TIDY_SOURCE} - - build-and-tidy: - name: build and tidy - runs-on: tps-sco-ci - needs: [checkout-code] - steps: - name: build run: | set -euxo pipefail - srun --job-name=${GITHUB_JOB} bash -c "source ${ENV_SOURCE} && cd ${WORKSPACE}/${CODE_SOURCE} && pwd && pip install -e . -v -t install" + srun --job-name=${GITHUB_JOB} bash -c "source ${ENV_SOURCE} && set -euxo pipefail && cd ${CODE_SOURCE} && pip install -e . -v -t install" - name: clang-tidy run: | set -euxo pipefail - srun --job-name=${GITHUB_JOB} bash -c "source ${ENV_SOURCE} && cd ${WORKSPACE}/${CODE_SOURCE} && pwd && git ls-files csrc | xargs ${CLANGD_TIDY_SOURCE}/clangd-tidy --clangd-executable=${CLANGD_EXEC} --github --git-root=${WORKSPACE}/${CODE_SOURCE} -j4 -o clang-tidy.log" || (cat ${WORKSPACE}/${CODE_SOURCE}/clang-tidy.log && false) + srun --job-name=${GITHUB_JOB} bash -c "source ${ENV_SOURCE} && set -euxo pipefail && cd ${CODE_SOURCE} && pwd && git ls-files csrc | xargs ${CLANGD_TIDY_SOURCE}/clangd-tidy --clangd-executable=${CLANGD_EXEC} --github --git-root=${CODE_SOURCE} -j4 -o ${CLANGD_TIDY_LOG}" || (cat ${CLANGD_TIDY_LOG} && false) + - name: cleanup + if: always() + run: | + set -euxo pipefail + rm -rf ${CODE_SOURCE}/build/.cache