Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: don't timeout if the runner is slow to pick up the job #1521

Merged
merged 24 commits into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ jobs:
unit-tests:
name: unit tests
runs-on: ${{ matrix.os }}
timeout-minutes: 1
strategy:
fail-fast: false
matrix:
os: [ubuntu-24.04, macos-latest]
#run: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
steps:
- uses: actions/checkout@v4
- uses: ./.github/workflows/timeout
id: timeout
- name: install uv and dependencies
run: |
curl -LsSf https://astral.sh/uv/install.sh | sh
Expand All @@ -30,13 +30,18 @@ jobs:
uv pip install -e .[testing,docs] setuptools
- run: uv run scons -j8
- run: uv run pytest .
- uses: ./.github/workflows/timeout
with:
start_time: ${{ steps.timeout.outputs.start_time }}
duration: 60

static-analysis:
name: static analysis
runs-on: ubuntu-24.04
timeout-minutes: 1
steps:
- uses: actions/checkout@v4
- uses: ./.github/workflows/timeout
id: timeout
- run: sudo apt install --no-install-recommends -y cppcheck
- name: setup python
run: |
Expand All @@ -51,3 +56,7 @@ jobs:
restore-keys: |
${{ runner.os }}-pre-commit-
- run: uv run pre-commit run --all
- uses: ./.github/workflows/timeout
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

other actions have something like a "Post checkout" that runs at the end. can we do that here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only possible with JS actions. Created a really simple one here: https://github.com/commaai/timeout
We now only have to do this once:

- uses: commaai/timeout@v1

or to specify a timeout other than 60 seconds:

- uses: commaai/timeout@v1
  with:
    timeout: 20

with:
start_time: ${{ steps.timeout.outputs.start_time }}
duration: 60
29 changes: 29 additions & 0 deletions .github/workflows/timeout/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: 'timeout'

inputs:
duration:
description: 'Maximum duration allowed for a workflow'
required: false
default: 60
start_time:
description: 'Starting time of the workflow'
required: false
default: -1
outputs:
start_time:
description: 'Saved starting time of the workflow'
value: ${{ steps.timeout-check.outputs.start_time }}

runs:
using: "composite"
steps:
- if: ${{ inputs.start_time >= 0 }}
shell: bash
run: |
if [[ $(( $(date +%s) - ${{ inputs.start_time }} )) -gt ${{ inputs.duration }} ]]; then
echo -e "\033[0;31mTHIS WORKFLOW TOOK MORE THAN ${{ inputs.duration }}s !\033[0m" && exit 1;
fi
- id: timeout-check
shell: bash
run: |
echo "start_time=$(date +%s)" >> "$GITHUB_OUTPUT"