Skip to content

Commit

Permalink
Run less tests (#17046)
Browse files Browse the repository at this point in the history
* feat(ci): Rerun only what failed

* fix(ci): Minor adjustments
  • Loading branch information
HajekOndrej authored Feb 19, 2025
1 parent 8586a18 commit 032177a
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 8 deletions.
64 changes: 64 additions & 0 deletions .github/actions/check-previous-test-runs/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: 'Check Previous Runs'
description: 'Check if a previous run of a job was successful to skip tests'
inputs:
github_token:
description: 'GitHub token for accessing the API'
required: true
pr_branch:
description: 'The branch of the pull request'
required: true
repo:
description: 'The repository name'
required: true
workflow_name:
description: 'The workflow name to filter runs'
required: true
job_name:
description: 'The name of the job to check success'
required: true
outputs:
skip_tests:
description: 'Indicates whether tests should be skipped'
value: ${{ steps.check-previous-runs.outputs.skip_tests }}
runs:
using: 'composite'
steps:
- name: Check Previous Test Runs
id: check-previous-runs
env:
GH_TOKEN: ${{ inputs.github_token }}
run: |
PR_BRANCH="${{ inputs.pr_branch }}"
REPO="${{ inputs.repo }}"
WORKFLOW_NAME="${{ inputs.workflow_name }}"
JOB_NAME="${{ inputs.job_name }}"
# Fetch workflow ID
WORKFLOW_ID=$(gh workflow list \
--repo "$REPO" \
--json id,name \
--jq ".[] | select(.name == \"${WORKFLOW_NAME}\") | .id")
# Fetch previous PR runs
PREVIOUS_RUN_JOBS_URL=$(curl -s -H "Authorization: Bearer ${GH_TOKEN}" \
"https://api.github.com/repos/$REPO/actions/workflows/${WORKFLOW_ID}/runs?event=pull_request&branch=${PR_BRANCH}&status=completed&per_page=1" | \
jq -r '.workflow_runs[] | .jobs_url')
if [ -z "${PREVIOUS_RUN_JOBS_URL}" ]; then
echo "No previous runs found. Running tests as usual"
echo "skip_tests=false" >> $GITHUB_OUTPUT
exit 0
fi
SUCCESSFUL_JOB_URL=$(curl -s -H "Authorization: Bearer ${GH_TOKEN}" "${PREVIOUS_RUN_JOBS_URL}" | \
jq -r --arg JOB_NAME "${JOB_NAME}" '.jobs[] | select(.name == $JOB_NAME and .conclusion == "success") | .html_url')
if [ -z "${SUCCESSFUL_JOB_URL}" ]; then
echo "No previous successful job found. Running tests as usual"
echo "skip_tests=false" >> $GITHUB_OUTPUT
exit 0
fi
echo "Previous successful job found: ${SUCCESSFUL_JOB_URL} - skipping the rest of the job"
echo "skip_tests=true" >> $GITHUB_OUTPUT
shell: bash
31 changes: 25 additions & 6 deletions .github/workflows/test-suite-desktop-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,41 @@ jobs:
CONTAINERS: "trezor-user-env-unix bitcoin-regtest"

steps:
# Electron requires unprivileged user namespaces to function properly.
# Disabling this security rule allows Electron to create sandboxed processes
# without requiring elevated privileges, which is essential for running the application.
# This is workaround until electron builder solves this issue in future release.
- uses: actions/checkout@v4
- name: Check previous runs
id: check-previous-runs
if: github.event_name == 'pull_request' && github.run_attempt == 1
uses: './.github/actions/check-previous-test-runs'
with:
github_token: ${{ secrets.TREZOR_BOT_TOKEN }}
pr_branch: ${{ github.head_ref }}
repo: ${{ github.repository }}
workflow_name: ${{ github.workflow }}
job_name: "${{ github.job }} (${{ join(matrix.*, ', ') }})"

# Electron requires unprivileged user namespaces to function properly.
# Disabling this security rule allows Electron to create sandboxed processes
# without requiring elevated privileges, which is essential for running the application.
# This is workaround until electron builder solves this issue in future release.
- name: Disable security rule 'Restricted unprivileged user namespaces'
if: steps.check-previous-runs.outputs.skip_tests != 'true'
run: sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0

- name: Checkout
if: steps.check-previous-runs.outputs.skip_tests != 'true'
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Setup node
if: steps.check-previous-runs.outputs.skip_tests != 'true'
uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: yarn

- name: Install dependencies, build libs and pull docker images
if: steps.check-previous-runs.outputs.skip_tests != 'true'
env:
COMPOSE_FILE: ./docker/docker-compose.suite-desktop-ci.yml
run: |
Expand All @@ -79,11 +95,13 @@ jobs:
docker compose pull ${{ matrix.CONTAINERS }}
- name: Build electron app.js for tests
if: steps.check-previous-runs.outputs.skip_tests != 'true'
run: |
yarn workspace @trezor/suite-desktop build:app
yarn workspace @trezor/suite-desktop build:ui
- name: Run Playwright e2e desktop tests
if: steps.check-previous-runs.outputs.skip_tests != 'true'
env:
COMPOSE_FILE: ./docker/docker-compose.suite-desktop-ci.yml
GITHUB_ACTION: true
Expand All @@ -96,15 +114,15 @@ jobs:
yarn workspace @trezor/suite-desktop-core test:e2e:desktop --forbid-only --grep=${{ matrix.TEST_GROUP }}
- name: Extract Trezor-user-env and Regtest logs
if: ${{ ! cancelled() }}
if: ${{ !cancelled() && steps.check-previous-runs.outputs.skip_tests != 'true' }}
run: |
docker cp docker-trezor-user-env-unix-1:/trezor-user-env/logs/debugging.log trezor-user-env-debugging.log || true
docker cp docker-trezor-user-env-unix-1:/trezor-user-env/logs/emulator_bridge.log tenv-emulator-bridge-debugging.log || true
docker cp docker-trezor-user-env-unix-1:/trezor-user-env/docker/version.txt trezor-user-env-version.txt || true
docker logs docker-electrum-regtest-1 > electrum-regtest.txt || true
- name: Upload Trezor-user-env and Regtest logs
if: ${{ ! cancelled() }}
if: ${{ !cancelled() && steps.check-previous-runs.outputs.skip_tests != 'true' }}
uses: actions/upload-artifact@v4
with:
name: emulator-logs-${{ matrix.TEST_GROUP }}
Expand All @@ -116,6 +134,7 @@ jobs:
retention-days: 30

- name: Docker compose down
if: steps.check-previous-runs.outputs.skip_tests != 'true'
env:
COMPOSE_FILE: ./docker/docker-compose.suite-desktop-ci.yml
run: docker compose down
Expand Down
20 changes: 18 additions & 2 deletions .github/workflows/test-suite-web-e2e-pw.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,32 @@ jobs:
ref: ${{github.event.after}}
fetch-depth: 2

- name: Check previous runs
id: check-previous-runs
if: github.event_name == 'pull_request' && github.run_attempt == 1
uses: './.github/actions/check-previous-test-runs'
with:
github_token: ${{ secrets.TREZOR_BOT_TOKEN }}
pr_branch: ${{ github.head_ref }}
repo: ${{ github.repository }}
workflow_name: ${{ github.workflow }}
job_name: "${{ github.job }} (${{ join(matrix.*, ', ') }})"

- name: Setup node
if: steps.check-previous-runs.outputs.skip_tests != 'true'
uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: yarn

- name: Extract branch name
if: steps.check-previous-runs.outputs.skip_tests != 'true'
id: extract_branch
run: |
echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
- name: Install dependencies and pull docker images
if: steps.check-previous-runs.outputs.skip_tests != 'true'
env:
COMPOSE_FILE: ./docker/docker-compose.suite-ci-pw.yml
run: |
Expand All @@ -148,6 +162,7 @@ jobs:
docker compose pull ${{ matrix.CONTAINERS }}
- name: Run Playwright e2e web tests
if: steps.check-previous-runs.outputs.skip_tests != 'true'
env:
COMPOSE_FILE: ./docker/docker-compose.suite-ci-pw.yml
BASE_URL: https://dev.suite.sldev.cz/suite-web/${{ steps.extract_branch.outputs.branch }}/web/
Expand All @@ -162,15 +177,15 @@ jobs:
yarn workspace @trezor/suite-desktop-core test:e2e:web --forbid-only --grep="(?=.*${{ matrix.TEST_GROUP }})(?=.*@webOnly)"
- name: Extract Trezor-user-env and Regtest logs
if: ${{ ! cancelled() }}
if: ${{ !cancelled() && steps.check-previous-runs.outputs.skip_tests != 'true' }}
run: |
docker cp docker-trezor-user-env-unix-1:/trezor-user-env/logs/debugging.log trezor-user-env-debugging.log || true
docker cp docker-trezor-user-env-unix-1:/trezor-user-env/logs/emulator_bridge.log tenv-emulator-bridge-debugging.log || true
docker cp docker-trezor-user-env-unix-1:/trezor-user-env/docker/version.txt trezor-user-env-version.txt || true
docker logs docker-electrum-regtest-1 > electrum-regtest.txt || true
- name: Upload Trezor-user-env and Regtest logs
if: ${{ ! cancelled() }}
if: ${{ !cancelled() && steps.check-previous-runs.outputs.skip_tests != 'true' }}
uses: actions/upload-artifact@v4
with:
name: emulator-logs-${{ matrix.TEST_GROUP }}
Expand All @@ -182,6 +197,7 @@ jobs:
retention-days: 30

- name: Docker compose down
if: steps.check-previous-runs.outputs.skip_tests != 'true'
env:
COMPOSE_FILE: ./docker/docker-compose.suite-ci-pw.yml
run: docker compose down
Expand Down

0 comments on commit 032177a

Please sign in to comment.