From 66a47a0ce7a882ac133f19c52598b6116bb5f531 Mon Sep 17 00:00:00 2001 From: Jiuyang Liu Date: Tue, 30 Jul 2024 20:29:35 +0800 Subject: [PATCH] [ci] add VCS CI --- .github/workflows/vcs.yml | 104 ++++++++++++++++++++++++++++++++++++++ script/ci/src/Main.scala | 4 +- 2 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/vcs.yml diff --git a/.github/workflows/vcs.yml b/.github/workflows/vcs.yml new file mode 100644 index 000000000..09ab3ec9a --- /dev/null +++ b/.github/workflows/vcs.yml @@ -0,0 +1,104 @@ +name: VCS +on: + pull_request: + types: + - opened + - synchronize + - reopened + - ready_for_review + - labeled +env: + USER: runner + +# Cancel the current workflow when new commit pushed +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number }} + cancel-in-progress: true + +jobs: + gen-test-plan: + if: '! github.event.pull_request.draft' + name: "Generate test plan" + runs-on: [self-hosted, linux, nixos] + outputs: + testplan: ${{ steps.get-all-configs.outputs.out }} + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + - id: "get-all-configs" + run: echo "out=$(nix run .#ci-helper generateTestPlan)" > $GITHUB_OUTPUT + + build-emulators: + name: "Build VCS Emulators" + needs: [gen-test-plan] + runs-on: [self-hosted, linux, nixos, BIGRAM] + strategy: + fail-fast: false + matrix: ${{ fromJSON(needs.gen-test-plan.outputs.testplan) }} + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + - name: "Build vcs emulator" + run: | + nix build '.#t1.${{ matrix.config }}.ip.vcs-emu' --impure --no-link --cores 64 + - name: "Build all testcases" + run: | + nix build ".#t1.${{ matrix.config }}.cases.all" --max-jobs auto --no-link --cores 64 + + gen-matrix: + name: "Prepare for running testcases" + needs: [build-emulators] + runs-on: [self-hosted, linux, nixos, BIGRAM] + env: + RUNNERS: 70 + outputs: + ci-tests: ${{ steps.gen-matrix.outputs.matrix }} + steps: + # actions/checkout will use the "event" commit to checkout repository, + # which will lead to an unexpected issue that the "event" commit doesn't belongs to the repository, + # and causing the derivation build output cannot be cache correctly. + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + - id: gen-matrix + name: "Generate test matrix" + run: | + echo -n matrix= >> "$GITHUB_OUTPUT" + nix run ".#ci-helper" -- generateCiMatrix --runnersAmount "$RUNNERS" >> "$GITHUB_OUTPUT" + + run-testcases: + name: "Run VCS" + needs: [gen-matrix] + strategy: + fail-fast: false + matrix: ${{ fromJSON(needs.gen-matrix.outputs.ci-tests) }} + runs-on: [self-hosted, linux, nixos] + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + - name: "Run testcases" + run: | + nix run ".#ci-helper" -- runTests --jobs "${{ matrix.jobs }}" --testType "vcs" + + report: + name: "Report VCS CI result" + # Don't run report when: + # - user cancel ( we don't need report at this case ) + # - PR from outside repository ( we don't have permission to push commit into fork repository ) + if: ${{ !cancelled() && github.event.pull_request.head.repo.full_name == github.repository }} + needs: [run-testcases] + runs-on: [self-hosted, linux, nixos] + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + ref: ${{ github.head_ref }} + - name: "Print step summary" + run: | + nix run ".#ci-helper" -- postCI --failed-tests-file-path ./failed-tests.md --emuType vcs + cat ./failed-tests.md >> $GITHUB_STEP_SUMMARY diff --git a/script/ci/src/Main.scala b/script/ci/src/Main.scala index 23a98e200..b6b4c7c59 100644 --- a/script/ci/src/Main.scala +++ b/script/ci/src/Main.scala @@ -175,13 +175,13 @@ object Main: ) catch case _ => - Logger.error(s"VCS emulation for config $config, case $caseName fail") + Logger.error(s"emulation for config $config, case $caseName fail") println("-" * 50) println(os.proc("nix", "log", testAttr).call().out) println("-" * 50) Logger.fatal("Got error from emulation, exiting CI") - Logger.info("Checking RTL event from VCS") + Logger.info("Checking RTL event from event log") val testSuccess = os.read(testResultPath / "offline-check-status").trim() == "0" if !testSuccess then