From 7c087b0fd7fb9ff7246ded192be92b7a2093f8aa Mon Sep 17 00:00:00 2001 From: oklinov Date: Fri, 18 Jul 2025 15:03:55 +0200 Subject: [PATCH 01/20] feat: testing library --- .github/workflows/platform-tests.yaml | 40 ++++++++++++++ .github/workflows/pr-build-test.yaml | 70 ++++++++++++++---------- .github/workflows/push-build-latest.yaml | 25 ++++----- 3 files changed, 92 insertions(+), 43 deletions(-) create mode 100644 .github/workflows/platform-tests.yaml diff --git a/.github/workflows/platform-tests.yaml b/.github/workflows/platform-tests.yaml new file mode 100644 index 0000000..cdff35e --- /dev/null +++ b/.github/workflows/platform-tests.yaml @@ -0,0 +1,40 @@ +name: Platform tests + +on: + workflow_call: + inputs: + subtest: + type: string + default: "" + required: false + +jobs: + platformTestsCore: + name: Platform tests - Core + if: github.ref == 'refs/heads/master' + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: oNaiPs/secrets-to-env-action@b64e0192bc4bd2ec0682dee8696470d4866577fa + with: + secrets: ${{ toJSON(secrets) }} + + - name: Install dependencies + run: npm install + + - name: Test + run: | + set +e + export RUN_ALL_PLATFORM_TESTS=1 + npx vitest ./test/platform/${{ inputs.subtest }} --run --reporter=default --reporter=json --outputFile=./test-output.json + return_code=$? + npx public-actors-tools report-tests \ + --report-file ./test-output.json \ + --workflow-name "${{ github.workflow }}" \ + --job-url "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" \ + --repository "${{ github.repository }}" + exit $return_code diff --git a/.github/workflows/pr-build-test.yaml b/.github/workflows/pr-build-test.yaml index 6a1db16..14308a5 100644 --- a/.github/workflows/pr-build-test.yaml +++ b/.github/workflows/pr-build-test.yaml @@ -1,42 +1,55 @@ name: Test + on: workflow_call: - # This doesn't do anything, we just have to keep it for backward compatibility - # as passing invalid input crashes the workflow - inputs: - runnerLabel: - description: 'prod or beta' - type: string - default: 'prod' - + concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: platformTest: - # Sadly, dynamic names mess up matching by status check, stupid github - # name: 'PR -> Build devel and test: ${{github.repository}} ${{github.event.head_commit.message}}' - # - # TODO: Improve logic when to run stuff - #if: | - # !contains(github.event.pull_request.message, '[skip ci]') && - # !contains(github.event.head_commit.message, '[skip platform-test]') - + name: Build Devel and Test runs-on: ubuntu-latest steps: - # We fetch all commits in the PR with the base commit as well - - name: 'Calculate PR commits + 1' - run: echo "PR_FETCH_DEPTH=$(( ${{ github.event.pull_request.commits }} + 1 ))" >> "${GITHUB_ENV}" - - uses: actions/checkout@v4 + - name: Checkout Repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: oNaiPs/secrets-to-env-action@b64e0192bc4bd2ec0682dee8696470d4866577fa + with: + secrets: ${{ toJSON(secrets) }} + + - name: Cache base commit + id: base_commit + uses: actions/cache@v4 with: - # By default checkout action creates an extra merge commit with the same code that is useless for us - ref: ${{ github.event.pull_request.head.sha }} - fetch-depth: ${{ env.PR_FETCH_DEPTH }} - - uses: apify-store/github-actions-source@feat/runner-in-action - env: - # A bit hacky way to pass secrets to the action - ALL_TOKENS_JSON: ${{ toJSON(secrets) }} + path: ./base_commit.txt + key: base_commit + + - name: Install dependencies + run: npm install + + - name: Build + id: build + run: | + export base_commit=$(cat base_commit.txt) + actor_builds=$(npx public-actors-tools build --source-branch "origin/${{ github.head_ref }}" --target-branch "origin/${{ github.base_ref }}" $(test $base_commit && echo "--base-commit $base_commit" || echo "")) + echo "actor_builds=$actor_builds" | tee -a $GITHUB_OUTPUT + + - name: Test + run: | + export ACTOR_BUILDS='${{ steps.build.outputs.actor_builds }}' + export RUN_PLATFORM_TESTS=1 + npx vitest ./test/platform --run + + # NOTE: we want to cache the latest commit only if the tests are successfull + - name: Cache latest commit + run: | + export base_commit=$(cat base_commit.txt) + npx public-actors-tools get-latest-commit --source-branch "origin/${{ github.head_ref }}" --target-branch "origin/${{ github.base_ref }}" $(test $base_commit && echo "--base-commit $base_commit" || echo "") > ./base_commit.txt + unitTest: # TODO: only run on changes to code runs-on: ubuntu-latest @@ -55,10 +68,9 @@ jobs: echo "Test folder not found at /test or /code/test. Skipping tests." exit 0 fi - - name: Use Node.js 20 uses: actions/setup-node@v3 - + with: node-version: 20 cache: 'npm' diff --git a/.github/workflows/push-build-latest.yaml b/.github/workflows/push-build-latest.yaml index df1cd43..75722c3 100644 --- a/.github/workflows/push-build-latest.yaml +++ b/.github/workflows/push-build-latest.yaml @@ -2,13 +2,6 @@ name: Build latest and report to slack on: workflow_call: - # This doesn't do anything, we just have to keep it for backward compatibility - # as passing invalid input crashes the workflow - inputs: - runnerLabel: - description: 'prod or beta' - type: string - default: 'prod' jobs: pushBuildLatest: @@ -18,13 +11,17 @@ jobs: !contains(github.event.head_commit.message, '[skip platform-test]') runs-on: ubuntu-latest - + steps: - # We need to fetch at least 2 commits to make a diff for Changelog - uses: actions/checkout@v4 with: - fetch-depth: 2 - - uses: apify-store/github-actions-source@feat/runner-in-action - env: - # A bit hacky way to pass secrets to the action - ALL_TOKENS_JSON: ${{ toJSON(secrets) }} + fetch-depth: 0 + # A simple node script that converts secrets to env vars + # Use specific commit SHA to prevent someone stealing that repo + - uses: oNaiPs/secrets-to-env-action@b64e0192bc4bd2ec0682dee8696470d4866577fa + with: + secrets: ${{ toJSON(secrets) }} + - name: Install dependencies + run: npm install + - name: Build and Test actor build + run: npx public-actors-tools release --push-event-path ${{ github.event_path }} From 416d14a1d8e24c9881abe95b6021f3d6b6783cab Mon Sep 17 00:00:00 2001 From: oklinov Date: Mon, 1 Sep 2025 18:13:19 +0200 Subject: [PATCH 02/20] change package to apify-test-tools --- .github/workflows/platform-tests.yaml | 2 +- .github/workflows/pr-build-test.yaml | 4 ++-- .github/workflows/push-build-latest.yaml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/platform-tests.yaml b/.github/workflows/platform-tests.yaml index cdff35e..d7dd93d 100644 --- a/.github/workflows/platform-tests.yaml +++ b/.github/workflows/platform-tests.yaml @@ -32,7 +32,7 @@ jobs: export RUN_ALL_PLATFORM_TESTS=1 npx vitest ./test/platform/${{ inputs.subtest }} --run --reporter=default --reporter=json --outputFile=./test-output.json return_code=$? - npx public-actors-tools report-tests \ + npx apify-test-tools report-tests \ --report-file ./test-output.json \ --workflow-name "${{ github.workflow }}" \ --job-url "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" \ diff --git a/.github/workflows/pr-build-test.yaml b/.github/workflows/pr-build-test.yaml index 14308a5..163c926 100644 --- a/.github/workflows/pr-build-test.yaml +++ b/.github/workflows/pr-build-test.yaml @@ -35,7 +35,7 @@ jobs: id: build run: | export base_commit=$(cat base_commit.txt) - actor_builds=$(npx public-actors-tools build --source-branch "origin/${{ github.head_ref }}" --target-branch "origin/${{ github.base_ref }}" $(test $base_commit && echo "--base-commit $base_commit" || echo "")) + actor_builds=$(npx apify-test-tools build --source-branch "origin/${{ github.head_ref }}" --target-branch "origin/${{ github.base_ref }}" $(test $base_commit && echo "--base-commit $base_commit" || echo "")) echo "actor_builds=$actor_builds" | tee -a $GITHUB_OUTPUT - name: Test @@ -48,7 +48,7 @@ jobs: - name: Cache latest commit run: | export base_commit=$(cat base_commit.txt) - npx public-actors-tools get-latest-commit --source-branch "origin/${{ github.head_ref }}" --target-branch "origin/${{ github.base_ref }}" $(test $base_commit && echo "--base-commit $base_commit" || echo "") > ./base_commit.txt + npx apify-test-tools get-latest-commit --source-branch "origin/${{ github.head_ref }}" --target-branch "origin/${{ github.base_ref }}" $(test $base_commit && echo "--base-commit $base_commit" || echo "") > ./base_commit.txt unitTest: # TODO: only run on changes to code diff --git a/.github/workflows/push-build-latest.yaml b/.github/workflows/push-build-latest.yaml index 75722c3..bc0f616 100644 --- a/.github/workflows/push-build-latest.yaml +++ b/.github/workflows/push-build-latest.yaml @@ -24,4 +24,4 @@ jobs: - name: Install dependencies run: npm install - name: Build and Test actor build - run: npx public-actors-tools release --push-event-path ${{ github.event_path }} + run: npx apify-test-tools release --push-event-path ${{ github.event_path }} From 8f81b1ccd70c15c3d655728f8145e3fc44842a02 Mon Sep 17 00:00:00 2001 From: Luigi Ruocco Date: Thu, 16 Oct 2025 15:47:35 +0200 Subject: [PATCH 03/20] feat: conditionally perform platform tests (#9) * feat: conditionally perform platform tests * fix: use working-directory * fix: use working-directory on all steps --- .github/workflows/pr-build-test.yaml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.github/workflows/pr-build-test.yaml b/.github/workflows/pr-build-test.yaml index 163c926..b7950cf 100644 --- a/.github/workflows/pr-build-test.yaml +++ b/.github/workflows/pr-build-test.yaml @@ -17,6 +17,18 @@ jobs: with: fetch-depth: 0 + # We want platform tests but some repos that we migrate may not have unit tests or have only standalone-actors + - name: Check if we have tests folder + run: | + if [ -d "code/test/platform" ]; then + echo "TEST_DIR=./code" >> $GITHUB_ENV + elif [ -d "test/platform" ]; then + echo "TEST_DIR=." >> $GITHUB_ENV + else + echo "Test folder not found at /test or /code/test. Skipping tests." + exit 0 + fi + - uses: oNaiPs/secrets-to-env-action@b64e0192bc4bd2ec0682dee8696470d4866577fa with: secrets: ${{ toJSON(secrets) }} @@ -30,6 +42,7 @@ jobs: - name: Install dependencies run: npm install + working-directory: ${{ env.TEST_DIR }} - name: Build id: build @@ -37,12 +50,14 @@ jobs: export base_commit=$(cat base_commit.txt) actor_builds=$(npx apify-test-tools build --source-branch "origin/${{ github.head_ref }}" --target-branch "origin/${{ github.base_ref }}" $(test $base_commit && echo "--base-commit $base_commit" || echo "")) echo "actor_builds=$actor_builds" | tee -a $GITHUB_OUTPUT + working-directory: ${{ env.TEST_DIR }} - name: Test run: | export ACTOR_BUILDS='${{ steps.build.outputs.actor_builds }}' export RUN_PLATFORM_TESTS=1 npx vitest ./test/platform --run + working-directory: ${{ env.TEST_DIR }} # NOTE: we want to cache the latest commit only if the tests are successfull - name: Cache latest commit From 8479cbdf2ab6249c92a6406ad7338f22a43db9f4 Mon Sep 17 00:00:00 2001 From: Luigi Ruocco Date: Thu, 16 Oct 2025 17:01:14 +0200 Subject: [PATCH 04/20] Fix: conditionally skip tests step (#10) * fix: execute tests only if present * feat: conditionally skip unit test * docs: add comment --- .github/workflows/pr-build-test.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/pr-build-test.yaml b/.github/workflows/pr-build-test.yaml index b7950cf..71c3075 100644 --- a/.github/workflows/pr-build-test.yaml +++ b/.github/workflows/pr-build-test.yaml @@ -53,6 +53,8 @@ jobs: working-directory: ${{ env.TEST_DIR }} - name: Test + # Skip step when tests are missing to avoid ci failures + if: env.TEST_DIR != '' run: | export ACTOR_BUILDS='${{ steps.build.outputs.actor_builds }}' export RUN_PLATFORM_TESTS=1 @@ -112,5 +114,7 @@ jobs: working-directory: ${{ env.TEST_DIR }} - name: Test + # Skip step when tests are missing to avoid ci failures + if: env.TEST_DIR != '' run: npm test working-directory: ${{ env.TEST_DIR }} From 98746a88c0dafe7923998a71a9d4f216b5865256 Mon Sep 17 00:00:00 2001 From: oklinov Date: Wed, 29 Oct 2025 10:12:20 +0100 Subject: [PATCH 05/20] imprv: set vitest's maxConcurrency to 20 --- .github/workflows/pr-build-test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-build-test.yaml b/.github/workflows/pr-build-test.yaml index 71c3075..091b551 100644 --- a/.github/workflows/pr-build-test.yaml +++ b/.github/workflows/pr-build-test.yaml @@ -58,7 +58,7 @@ jobs: run: | export ACTOR_BUILDS='${{ steps.build.outputs.actor_builds }}' export RUN_PLATFORM_TESTS=1 - npx vitest ./test/platform --run + npx vitest ./test/platform --run --maxConcurrency 20 working-directory: ${{ env.TEST_DIR }} # NOTE: we want to cache the latest commit only if the tests are successfull From 2157190907992b2d732cf18bb91de40e5113ac9c Mon Sep 17 00:00:00 2001 From: oklinov Date: Wed, 29 Oct 2025 12:06:33 +0100 Subject: [PATCH 06/20] imprv: explicitly enable file parallelism --- .github/workflows/pr-build-test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-build-test.yaml b/.github/workflows/pr-build-test.yaml index 091b551..22436b5 100644 --- a/.github/workflows/pr-build-test.yaml +++ b/.github/workflows/pr-build-test.yaml @@ -58,7 +58,7 @@ jobs: run: | export ACTOR_BUILDS='${{ steps.build.outputs.actor_builds }}' export RUN_PLATFORM_TESTS=1 - npx vitest ./test/platform --run --maxConcurrency 20 + npx vitest ./test/platform --run --maxConcurrency 20 --fileParallelism=true working-directory: ${{ env.TEST_DIR }} # NOTE: we want to cache the latest commit only if the tests are successfull From 1bf54f7acc091738e0b95f43158ed71c6be16af9 Mon Sep 17 00:00:00 2001 From: oklinov Date: Thu, 30 Oct 2025 16:07:23 +0100 Subject: [PATCH 07/20] remove name from platformTest job --- .github/workflows/pr-build-test.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/pr-build-test.yaml b/.github/workflows/pr-build-test.yaml index 22436b5..9b78d98 100644 --- a/.github/workflows/pr-build-test.yaml +++ b/.github/workflows/pr-build-test.yaml @@ -9,7 +9,6 @@ concurrency: jobs: platformTest: - name: Build Devel and Test runs-on: ubuntu-latest steps: - name: Checkout Repository From 22a7f81dc54e7d1a9517462298d5f06172800a55 Mon Sep 17 00:00:00 2001 From: oklinov Date: Tue, 4 Nov 2025 16:46:52 +0100 Subject: [PATCH 08/20] perf: set maxWorkers to 10 to speed up tests --- .github/workflows/pr-build-test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-build-test.yaml b/.github/workflows/pr-build-test.yaml index 9b78d98..c892fa1 100644 --- a/.github/workflows/pr-build-test.yaml +++ b/.github/workflows/pr-build-test.yaml @@ -57,7 +57,7 @@ jobs: run: | export ACTOR_BUILDS='${{ steps.build.outputs.actor_builds }}' export RUN_PLATFORM_TESTS=1 - npx vitest ./test/platform --run --maxConcurrency 20 --fileParallelism=true + npx vitest ./test/platform --run --maxConcurrency 20 --fileParallelism=true --maxWorkers 10 working-directory: ${{ env.TEST_DIR }} # NOTE: we want to cache the latest commit only if the tests are successfull From 9cbc9d783f727a879a6d6bc882a8aa2ae224f9b8 Mon Sep 17 00:00:00 2001 From: Yaroslav Tykhovetskyi Date: Thu, 6 Nov 2025 16:59:52 +0100 Subject: [PATCH 09/20] feat: add prettier and ts-unused-exports checks to the unit test workflow (#8) --- .github/workflows/pr-build-test.yaml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/.github/workflows/pr-build-test.yaml b/.github/workflows/pr-build-test.yaml index c892fa1..19fde4b 100644 --- a/.github/workflows/pr-build-test.yaml +++ b/.github/workflows/pr-build-test.yaml @@ -117,3 +117,21 @@ jobs: if: env.TEST_DIR != '' run: npm test working-directory: ${{ env.TEST_DIR }} + + - name: Prettier Check + run: | + if npx prettier --version > /dev/null 2>&1; then + npx prettier --check .; + else + echo "Prettier is not installed. Skipping Prettier check."; + fi + working-directory: ${{ env.TEST_DIR }} + + - name: Unused Exports Check + run: | + if npx ts-unused-exports --version > /dev/null 2>&1; then + npx ts-unused-exports ./tsconfig.json; + else + echo "ts-unused-exports is not installed. Skipping unused exports check."; + fi + working-directory: ${{ env.TEST_DIR }} From b403518bda6193eb9851771f0d3822e86190de6a Mon Sep 17 00:00:00 2001 From: Yuliya Kazadoi Date: Fri, 7 Nov 2025 11:34:00 +0100 Subject: [PATCH 10/20] fix: add an option to have main instead of master (#12) --- .github/workflows/platform-tests.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/platform-tests.yaml b/.github/workflows/platform-tests.yaml index d7dd93d..b1e3c76 100644 --- a/.github/workflows/platform-tests.yaml +++ b/.github/workflows/platform-tests.yaml @@ -11,7 +11,7 @@ on: jobs: platformTestsCore: name: Platform tests - Core - if: github.ref == 'refs/heads/master' + if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' runs-on: ubuntu-latest steps: - name: Checkout Repository From 4ca223434f78bfcfacd25d58078230b860026df5 Mon Sep 17 00:00:00 2001 From: oklinov Date: Fri, 7 Nov 2025 14:23:04 +0100 Subject: [PATCH 11/20] feat: speed up daily tests --- .github/workflows/platform-tests.yaml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/platform-tests.yaml b/.github/workflows/platform-tests.yaml index b1e3c76..82dcd72 100644 --- a/.github/workflows/platform-tests.yaml +++ b/.github/workflows/platform-tests.yaml @@ -30,7 +30,14 @@ jobs: run: | set +e export RUN_ALL_PLATFORM_TESTS=1 - npx vitest ./test/platform/${{ inputs.subtest }} --run --reporter=default --reporter=json --outputFile=./test-output.json + npx vitest ./test/platform/${{ inputs.subtest }} \ + --run \ + --reporter=default \ + --reporter=json \ + --outputFile=./test-output.json \ + --maxConcurrency 20 \ + --fileParallelism=true \ + --maxWorkers 10 return_code=$? npx apify-test-tools report-tests \ --report-file ./test-output.json \ From a3cad7c655295e129fb3e5b282c6a287a0f3dc4c Mon Sep 17 00:00:00 2001 From: oklinov Date: Fri, 7 Nov 2025 15:05:41 +0100 Subject: [PATCH 12/20] chore: rename scheduled platform tests --- .github/workflows/platform-tests.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/platform-tests.yaml b/.github/workflows/platform-tests.yaml index 82dcd72..099da1f 100644 --- a/.github/workflows/platform-tests.yaml +++ b/.github/workflows/platform-tests.yaml @@ -9,8 +9,8 @@ on: required: false jobs: - platformTestsCore: - name: Platform tests - Core + scheduledPlatformTests: + name: Scheduled Platform tests if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' runs-on: ubuntu-latest steps: From 08d6b0d610695f482caa63e5d6bb87789f6580df Mon Sep 17 00:00:00 2001 From: oklinov Date: Fri, 7 Nov 2025 16:29:41 +0100 Subject: [PATCH 13/20] perf: increase maxWorkers to 100 --- .github/workflows/platform-tests.yaml | 2 +- .github/workflows/pr-build-test.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/platform-tests.yaml b/.github/workflows/platform-tests.yaml index 099da1f..5a0ffc0 100644 --- a/.github/workflows/platform-tests.yaml +++ b/.github/workflows/platform-tests.yaml @@ -37,7 +37,7 @@ jobs: --outputFile=./test-output.json \ --maxConcurrency 20 \ --fileParallelism=true \ - --maxWorkers 10 + --maxWorkers 100 return_code=$? npx apify-test-tools report-tests \ --report-file ./test-output.json \ diff --git a/.github/workflows/pr-build-test.yaml b/.github/workflows/pr-build-test.yaml index 19fde4b..96c0ec0 100644 --- a/.github/workflows/pr-build-test.yaml +++ b/.github/workflows/pr-build-test.yaml @@ -57,7 +57,7 @@ jobs: run: | export ACTOR_BUILDS='${{ steps.build.outputs.actor_builds }}' export RUN_PLATFORM_TESTS=1 - npx vitest ./test/platform --run --maxConcurrency 20 --fileParallelism=true --maxWorkers 10 + npx vitest ./test/platform --run --maxConcurrency 20 --fileParallelism=true --maxWorkers 100 working-directory: ${{ env.TEST_DIR }} # NOTE: we want to cache the latest commit only if the tests are successfull From e59d2c6ffc21557bb185ca4be7ffaeaff8a88dd0 Mon Sep 17 00:00:00 2001 From: oklinov Date: Mon, 10 Nov 2025 16:16:24 +0100 Subject: [PATCH 14/20] fix: add [] to prettier and ts-unused-exports check --- .github/workflows/pr-build-test.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-build-test.yaml b/.github/workflows/pr-build-test.yaml index 96c0ec0..83c0687 100644 --- a/.github/workflows/pr-build-test.yaml +++ b/.github/workflows/pr-build-test.yaml @@ -120,7 +120,7 @@ jobs: - name: Prettier Check run: | - if npx prettier --version > /dev/null 2>&1; then + if [ npx prettier --version > /dev/null 2>&1 ]; then npx prettier --check .; else echo "Prettier is not installed. Skipping Prettier check."; @@ -129,7 +129,7 @@ jobs: - name: Unused Exports Check run: | - if npx ts-unused-exports --version > /dev/null 2>&1; then + if [ npx ts-unused-exports --version > /dev/null 2>&1 ]; then npx ts-unused-exports ./tsconfig.json; else echo "ts-unused-exports is not installed. Skipping unused exports check."; From df3790c7ce23efb2bce3b001cc2d284f0abc87c6 Mon Sep 17 00:00:00 2001 From: Luigi Ruocco Date: Wed, 10 Dec 2025 16:23:28 +0100 Subject: [PATCH 15/20] fix: set working directory for old code structure (#13) --- .github/workflows/platform-tests.yaml | 10 ++++++++++ .github/workflows/push-build-latest.yaml | 12 ++++++++++++ 2 files changed, 22 insertions(+) diff --git a/.github/workflows/platform-tests.yaml b/.github/workflows/platform-tests.yaml index 5a0ffc0..3a83110 100644 --- a/.github/workflows/platform-tests.yaml +++ b/.github/workflows/platform-tests.yaml @@ -22,9 +22,18 @@ jobs: - uses: oNaiPs/secrets-to-env-action@b64e0192bc4bd2ec0682dee8696470d4866577fa with: secrets: ${{ toJSON(secrets) }} + + - name: Check if we have tests folder + run: | + if [ -f "./code/package.json" ]; then + echo "SOURCE_DIR=./code" >> $GITHUB_ENV + else + echo "SOURCE_DIR=." >> $GITHUB_ENV + fi - name: Install dependencies run: npm install + working-directory: ${{ env.SOURCE_DIR }} - name: Test run: | @@ -45,3 +54,4 @@ jobs: --job-url "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" \ --repository "${{ github.repository }}" exit $return_code + working-directory: ${{ env.SOURCE_DIR }} diff --git a/.github/workflows/push-build-latest.yaml b/.github/workflows/push-build-latest.yaml index bc0f616..ade7e26 100644 --- a/.github/workflows/push-build-latest.yaml +++ b/.github/workflows/push-build-latest.yaml @@ -21,7 +21,19 @@ jobs: - uses: oNaiPs/secrets-to-env-action@b64e0192bc4bd2ec0682dee8696470d4866577fa with: secrets: ${{ toJSON(secrets) }} + + - name: Check if we have tests folder + run: | + if [ -f "./code/package.json" ]; then + echo "SOURCE_DIR=./code" >> $GITHUB_ENV + else + echo "SOURCE_DIR=." >> $GITHUB_ENV + fi + - name: Install dependencies run: npm install + working-directory: ${{ env.SOURCE_DIR }} + - name: Build and Test actor build run: npx apify-test-tools release --push-event-path ${{ github.event_path }} + working-directory: ${{ env.SOURCE_DIR }} From 1fc3f149ff3f2830b74dec20f6b95958fbc8a661 Mon Sep 17 00:00:00 2001 From: Luigi Ruocco Date: Fri, 12 Dec 2025 14:49:22 +0100 Subject: [PATCH 16/20] feat: use inputs to set different working directory (#14) --- .github/workflows/platform-tests.yaml | 20 +++--- .github/workflows/pr-build-test.yaml | 77 ++++++++++++------------ .github/workflows/push-build-latest.yaml | 18 +++--- 3 files changed, 55 insertions(+), 60 deletions(-) diff --git a/.github/workflows/platform-tests.yaml b/.github/workflows/platform-tests.yaml index 3a83110..780bee7 100644 --- a/.github/workflows/platform-tests.yaml +++ b/.github/workflows/platform-tests.yaml @@ -7,12 +7,19 @@ on: type: string default: "" required: false + working-directory: + type: string + default: . + required: false jobs: scheduledPlatformTests: name: Scheduled Platform tests if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' runs-on: ubuntu-latest + defaults: + run: + working-directory: ${{ inputs.working-directory }} steps: - name: Checkout Repository uses: actions/checkout@v4 @@ -22,18 +29,9 @@ jobs: - uses: oNaiPs/secrets-to-env-action@b64e0192bc4bd2ec0682dee8696470d4866577fa with: secrets: ${{ toJSON(secrets) }} - - - name: Check if we have tests folder - run: | - if [ -f "./code/package.json" ]; then - echo "SOURCE_DIR=./code" >> $GITHUB_ENV - else - echo "SOURCE_DIR=." >> $GITHUB_ENV - fi - name: Install dependencies run: npm install - working-directory: ${{ env.SOURCE_DIR }} - name: Test run: | @@ -50,8 +48,8 @@ jobs: return_code=$? npx apify-test-tools report-tests \ --report-file ./test-output.json \ + --workspace . \ --workflow-name "${{ github.workflow }}" \ --job-url "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" \ --repository "${{ github.repository }}" - exit $return_code - working-directory: ${{ env.SOURCE_DIR }} + exit $return_code \ No newline at end of file diff --git a/.github/workflows/pr-build-test.yaml b/.github/workflows/pr-build-test.yaml index 83c0687..5ad025d 100644 --- a/.github/workflows/pr-build-test.yaml +++ b/.github/workflows/pr-build-test.yaml @@ -2,32 +2,53 @@ name: Test on: workflow_call: + inputs: + working-directory: + type: string + default: . + required: false + skip-platform-tests: + type: boolean + default: false + required: false concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: + + checkTestFolder: + if: ${{ !inputs.skip-platform-tests }} + runs-on: ubuntu-latest + defaults: + run: + working-directory: ${{ inputs.working-directory }} + + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Check for test folder + id: check + run: | + if [ ! -d "test/platform" ]; then + echo "No platform test folder found. Failing the workflow." + exit 1 + fi + platformTest: + if: ${{ !inputs.skip-platform-tests }} + needs: checkTestFolder runs-on: ubuntu-latest + defaults: + run: + working-directory: ${{ inputs.working-directory }} steps: - name: Checkout Repository uses: actions/checkout@v4 with: fetch-depth: 0 - # We want platform tests but some repos that we migrate may not have unit tests or have only standalone-actors - - name: Check if we have tests folder - run: | - if [ -d "code/test/platform" ]; then - echo "TEST_DIR=./code" >> $GITHUB_ENV - elif [ -d "test/platform" ]; then - echo "TEST_DIR=." >> $GITHUB_ENV - else - echo "Test folder not found at /test or /code/test. Skipping tests." - exit 0 - fi - - uses: oNaiPs/secrets-to-env-action@b64e0192bc4bd2ec0682dee8696470d4866577fa with: secrets: ${{ toJSON(secrets) }} @@ -41,7 +62,6 @@ jobs: - name: Install dependencies run: npm install - working-directory: ${{ env.TEST_DIR }} - name: Build id: build @@ -49,16 +69,12 @@ jobs: export base_commit=$(cat base_commit.txt) actor_builds=$(npx apify-test-tools build --source-branch "origin/${{ github.head_ref }}" --target-branch "origin/${{ github.base_ref }}" $(test $base_commit && echo "--base-commit $base_commit" || echo "")) echo "actor_builds=$actor_builds" | tee -a $GITHUB_OUTPUT - working-directory: ${{ env.TEST_DIR }} - name: Test - # Skip step when tests are missing to avoid ci failures - if: env.TEST_DIR != '' run: | export ACTOR_BUILDS='${{ steps.build.outputs.actor_builds }}' export RUN_PLATFORM_TESTS=1 npx vitest ./test/platform --run --maxConcurrency 20 --fileParallelism=true --maxWorkers 100 - working-directory: ${{ env.TEST_DIR }} # NOTE: we want to cache the latest commit only if the tests are successfull - name: Cache latest commit @@ -69,32 +85,22 @@ jobs: unitTest: # TODO: only run on changes to code runs-on: ubuntu-latest + defaults: + run: + working-directory: ${{ inputs.working-directory }} steps: - name: Checkout repository uses: actions/checkout@v4 - # We want unit tests but some repos that we migrate may not have unit tests or have only standalone-actors - - name: Check if we have tests folder - run: | - if [ -d "code/test" ]; then - echo "TEST_DIR=./code" >> $GITHUB_ENV - elif [ -d "test" ]; then - echo "TEST_DIR=." >> $GITHUB_ENV - else - echo "Test folder not found at /test or /code/test. Skipping tests." - exit 0 - fi + - name: Use Node.js 20 uses: actions/setup-node@v3 - with: node-version: 20 cache: 'npm' - cache-dependency-path: ${{ env.TEST_DIR }} # https://github.com/actions/setup-node/issues/706 - + cache-dependency-path: ${{ inputs.working-directory }} # https://github.com/actions/setup-node/issues/706 - name: Install Dependencies run: npm ci - working-directory: ${{ env.TEST_DIR }} - name: TypeScript # Some repos require custom build checks, so we check if the `build-check` script exists and run it if @@ -106,17 +112,12 @@ jobs: else npm run build-check; fi - working-directory: ${{ env.TEST_DIR }} - name: Lint run: npm run lint - working-directory: ${{ env.TEST_DIR }} - name: Test - # Skip step when tests are missing to avoid ci failures - if: env.TEST_DIR != '' run: npm test - working-directory: ${{ env.TEST_DIR }} - name: Prettier Check run: | @@ -125,7 +126,6 @@ jobs: else echo "Prettier is not installed. Skipping Prettier check."; fi - working-directory: ${{ env.TEST_DIR }} - name: Unused Exports Check run: | @@ -134,4 +134,3 @@ jobs: else echo "ts-unused-exports is not installed. Skipping unused exports check."; fi - working-directory: ${{ env.TEST_DIR }} diff --git a/.github/workflows/push-build-latest.yaml b/.github/workflows/push-build-latest.yaml index ade7e26..45cf13c 100644 --- a/.github/workflows/push-build-latest.yaml +++ b/.github/workflows/push-build-latest.yaml @@ -2,6 +2,11 @@ name: Build latest and report to slack on: workflow_call: + inputs: + working-directory: + type: string + default: . + required: false jobs: pushBuildLatest: @@ -11,6 +16,9 @@ jobs: !contains(github.event.head_commit.message, '[skip platform-test]') runs-on: ubuntu-latest + defaults: + run: + working-directory: ${{ inputs.working-directory }} steps: - uses: actions/checkout@v4 @@ -22,18 +30,8 @@ jobs: with: secrets: ${{ toJSON(secrets) }} - - name: Check if we have tests folder - run: | - if [ -f "./code/package.json" ]; then - echo "SOURCE_DIR=./code" >> $GITHUB_ENV - else - echo "SOURCE_DIR=." >> $GITHUB_ENV - fi - - name: Install dependencies run: npm install - working-directory: ${{ env.SOURCE_DIR }} - name: Build and Test actor build run: npx apify-test-tools release --push-event-path ${{ github.event_path }} - working-directory: ${{ env.SOURCE_DIR }} From f6bd3bffeac9a2ec11d6c04c3145f046ca918011 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Pr=C5=AF=C5=A1a?= Date: Wed, 31 Dec 2025 16:43:47 +0100 Subject: [PATCH 17/20] chore: upload vitest json output as artifact --- .github/workflows/platform-tests.yaml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/platform-tests.yaml b/.github/workflows/platform-tests.yaml index 780bee7..85a79f7 100644 --- a/.github/workflows/platform-tests.yaml +++ b/.github/workflows/platform-tests.yaml @@ -52,4 +52,10 @@ jobs: --workflow-name "${{ github.workflow }}" \ --job-url "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" \ --repository "${{ github.repository }}" - exit $return_code \ No newline at end of file + exit $return_code + + - name: Upload Vitest JSON artifact + uses: actions/upload-artifact@v6 + with: + name: vitest-results + path: ./test-output.json \ No newline at end of file From d230d916af122c75bf6879252d681ca1f3818191 Mon Sep 17 00:00:00 2001 From: Luigi Ruocco Date: Thu, 26 Feb 2026 11:48:40 +0000 Subject: [PATCH 18/20] feat: ensure JSON artifact upload (#15) --- .github/workflows/platform-tests.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/platform-tests.yaml b/.github/workflows/platform-tests.yaml index 85a79f7..74b785d 100644 --- a/.github/workflows/platform-tests.yaml +++ b/.github/workflows/platform-tests.yaml @@ -56,6 +56,7 @@ jobs: - name: Upload Vitest JSON artifact uses: actions/upload-artifact@v6 + if: always() with: name: vitest-results path: ./test-output.json \ No newline at end of file From 0f3f5d1cf67e074adb874add32f170ea73906c1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20K=C5=99ivka?= Date: Thu, 5 Mar 2026 12:29:24 +0100 Subject: [PATCH 19/20] fix(build-test): make unused exports check work and support Knip (#16) * fix(build-test): make unused exports check work and support Knip * also fix prettier --- .github/workflows/pr-build-test.yaml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pr-build-test.yaml b/.github/workflows/pr-build-test.yaml index 5ad025d..5f46dd5 100644 --- a/.github/workflows/pr-build-test.yaml +++ b/.github/workflows/pr-build-test.yaml @@ -121,7 +121,7 @@ jobs: - name: Prettier Check run: | - if [ npx prettier --version > /dev/null 2>&1 ]; then + if [ -d "node_modules/prettier" ]; then npx prettier --check .; else echo "Prettier is not installed. Skipping Prettier check."; @@ -129,8 +129,12 @@ jobs: - name: Unused Exports Check run: | - if [ npx ts-unused-exports --version > /dev/null 2>&1 ]; then + if [ -d "node_modules/knip" ]; then + echo "Knip is installed. Running knip to check for unused exports."; + npx knip --include exports,types; + elif [ -d "node_modules/ts-unused-exports" ]; then + echo "Knip is not installed, but ts-unused-exports is. Running ts-unused-exports to check for unused exports."; npx ts-unused-exports ./tsconfig.json; else - echo "ts-unused-exports is not installed. Skipping unused exports check."; + echo "knip nor ts-unused-exports are installed. Skipping unused exports check."; fi From 4cc0dbe58450b979afb9bf924c70a4aeee0c1d04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20K=C5=99ivka?= Date: Thu, 5 Mar 2026 19:16:38 +0100 Subject: [PATCH 20/20] perf/debug: Don't cache base (last validated) commit on cosmetic changes and add logs/comments (#17) * perf/debug: log base_commit and store it only after functional changes (builds & tests happened) * More explanations * More explanations * suggesting comments * suggesting comments --- .github/workflows/pr-build-test.yaml | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pr-build-test.yaml b/.github/workflows/pr-build-test.yaml index 5f46dd5..c9ed236 100644 --- a/.github/workflows/pr-build-test.yaml +++ b/.github/workflows/pr-build-test.yaml @@ -53,20 +53,26 @@ jobs: with: secrets: ${{ toJSON(secrets) }} - - name: Cache base commit + - name: Pick last validated commit from cache id: base_commit uses: actions/cache@v4 with: + # We have to call it base commit for the library but it makes more sense as "last validated commit" path: ./base_commit.txt key: base_commit - name: Install dependencies run: npm install + # Consider forcing usage of latest test tools + # - name: Enforce latest test tools version + # run: npm install apify-test-tools@latest || true + - name: Build id: build run: | export base_commit=$(cat base_commit.txt) + echo "Last validated (base) commit to be used for build & test: $base_commit" actor_builds=$(npx apify-test-tools build --source-branch "origin/${{ github.head_ref }}" --target-branch "origin/${{ github.base_ref }}" $(test $base_commit && echo "--base-commit $base_commit" || echo "")) echo "actor_builds=$actor_builds" | tee -a $GITHUB_OUTPUT @@ -76,11 +82,15 @@ jobs: export RUN_PLATFORM_TESTS=1 npx vitest ./test/platform --run --maxConcurrency 20 --fileParallelism=true --maxWorkers 100 - # NOTE: we want to cache the latest commit only if the tests are successfull - - name: Cache latest commit + # NOTE: This is an optimization that if we did functional changes and later only cosmetic changes (e.g. dev reamde), we will compare changes files only for the last commit. We want to cache the latest commit only if the tests are successful + - name: Store last validated commit to cache + # We only want to store base commit if there were functional changes. If there are no functional changes, not having base commit will allow us to compare branches directly with git diff target_branch...source_branch which can understand that functional changes come from merge commit with target branch. This way we don't have to run tests if we have just readme changes but we need to merge master in. If there were no functional changes, base commit is useless anyway. + if: steps.build.outputs.actor_builds != '[]' run: | export base_commit=$(cat base_commit.txt) + echo "Old last validated (base) commit: $base_commit" npx apify-test-tools get-latest-commit --source-branch "origin/${{ github.head_ref }}" --target-branch "origin/${{ github.base_ref }}" $(test $base_commit && echo "--base-commit $base_commit" || echo "") > ./base_commit.txt + echo "New last validated (base) commit: $(cat base_commit.txt)" unitTest: # TODO: only run on changes to code