'Why github actions cant timeout a single job

I have a workflow in which a run request runs infinitely. i want to stop that run after 5 minutes of it running.

my workflow file:-

name: MSBuild

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

env:
  # Path to the solution file relative to the root of the project.
  SOLUTION_FILE_PATH: ./genshincheat.sln

  # Configuration type to build.
  # You can convert this to a build matrix if you need coverage of multiple configuration types.
  # https://docs.github.com/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
  BUILD_CONFIGURATION: Release

permissions:
  contents: read

jobs:
  build:
    runs-on: windows-latest

    steps:
    - uses: actions/checkout@v1
      with:
        submodules: recursive
    - name: Add MSBuild to PATH
      uses: microsoft/[email protected]

    - name: Restore NuGet packages
      working-directory: ${{env.GITHUB_WORKSPACE}}
      run: nuget restore ${{env.SOLUTION_FILE_PATH}}
      

    - name: Build
      working-directory: ${{env.GITHUB_WORKSPACE}}
      # Add additional options to the MSBuild command line here (like platform or verbosity level).
      # See https://docs.microsoft.com/visualstudio/msbuild/msbuild-command-line-reference
      run: msbuild /m /p:Configuration=${{env.BUILD_CONFIGURATION}} ${{env.SOLUTION_FILE_PATH}}
      
    
    - uses: montudor/action-zip@v1
      with:
        args: zip -qq -r bin.zip dir
    - uses: actions/checkout@v2

    - run: mkdir -p path/to/artifact

    - run: echo hello > path/to/artifact/world.txt

    - uses: actions/upload-artifact@v3
      with:
        name: bin.zip
        path: ./bin.zip

the "build" runs infinitely any way to stop it after 5 mins so it can carry out next jobs? it runs infinitely becauseafter build it runs the built program so i cant exit that ;-;. any help is appreciated



Solution 1:[1]

There are different fields that can help you achieve what you want.

At the job level: job.<id>.timeout-minutes (defining a job timeout)

At the step level: job.<id>.steps.timeout-minutes (defining a step timeout)


Which would look like this in your case:

At the job level:

build:
 runs-on: windows-latest
 timeout-minutes: 5
 steps:
   [...]

At the step which never ends (example):

- name: Build
 timeout-minutes: 5
 working-directory: ${{env.GITHUB_WORKSPACE}}
 # Add additional options to the MSBuild command line here (like platform or verbosity level).
 # See https://docs.microsoft.com/visualstudio/msbuild/msbuild-command-line-reference
 run: msbuild /m /p:Configuration=${{env.BUILD_CONFIGURATION}} ${{env.SOLUTION_FILE_PATH}}

Another reference on the Github Community

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 GuiFalourd