Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Github Actions: check steps status

Tags:

I have in my job for CI some steps which can throw an error. I don't want restart workflow on every step with error and want to go to the last step that checks those steps and complete this job as fail. But I can't get status info previously steps.

name: CI on: [pull_request] jobs:   myjob:     runs-on: ubuntu-latest     steps:       - name: Step 1         id: hello         run: <any>          continue-on-error: true       - name: Step 2         id: world         run: <any>          continue-on-error: true       - name: Check on failures         if: job.steps.hello.status == failure() || job.steps.world.status == failure()         run: exit 1 

When I use next constructions in "if" or "run" then will get: steps -> {}, job.steps -> null.

How can I get status information?

like image 327
Maxim Avatar asked Sep 09 '19 08:09

Maxim


People also ask

How do I check action status in GitHub?

You can see the overall state of the last commit to a branch on your repository's branches page or in your repository's list of pull requests. If status checks are required for a repository, the required status checks must pass before you can merge your branch into the protected branch.

How long do actions take GitHub?

Each workflow can run for up to 58 minutes (including queuing and execution time). Each workflow can run up to 100 actions (including build and other meta steps). Only two workflows can be running concurrently per repository. Actions are not allowed to trigger other Workflows.

What is actions checkout in GitHub Actions?

This action checks-out your repository under $GITHUB_WORKSPACE , so your workflow can access it. Only a single commit is fetched by default, for the ref/SHA that triggered the workflow. Set fetch-depth: 0 to fetch all history for all branches and tags.

Is GitHub Actions fast?

All told, our test suite now takes around 7 minutes to run (not counting the pre-test build step), which is roughly 95% faster than a naive approach. Even factoring in the fixed build process, our CI now runs 10x faster overall. Not too shabby! GitHub Actions is remarkable versatile.


1 Answers

Update: The steps context now contains detail about the execution of each step by default. Using the outcome property of each step we can check the result of its execution.

name: CI on: [pull_request] jobs:   myjob:     runs-on: ubuntu-latest     steps:       - name: Step 1         id: hello         run: <any>          continue-on-error: true       - name: Step 2         id: world         run: <any>          continue-on-error: true       - name: Check on failures         if: steps.hello.outcome != 'success' || steps.world.outcome != 'success'         run: exit 1 

Original answer Looking at the documentation for the steps context, it doesn't look like it contains any information about the step other than outputs. These must be explicitly defined by steps. That is why the steps context is empty {}.

https://help.github.com/en/articles/contexts-and-expression-syntax-for-github-actions#steps-context

Unfortunately, as far as I can tell, there is no default status for a step that can be accessed. The solution involves manually defining a status output variable from each step.

name: CI on: [pull_request] jobs:   myjob:     runs-on: ubuntu-latest     steps:       - name: Step 1         id: hello         run: echo ::set-output name=status::failure         continue-on-error: true       - name: Step 2         id: world         run: echo ::set-output name=status::success         continue-on-error: true       - name: Dump steps context         env:           STEPS_CONTEXT: ${{ toJson(steps) }}         run: echo "$STEPS_CONTEXT"       - name: Check on failures         if: steps.hello.outputs.status == 'failure' || steps.world.outputs.status == 'failure'         run: exit 1 

This creates the following context output and the job fails.

{   "hello": {     "outputs": {       "status": "failure"     }   },   "world": {      "outputs": {       "status": "success"     }   } } 

https://help.github.com/en/articles/metadata-syntax-for-github-actions#outputs https://help.github.com/en/articles/development-tools-for-github-actions#set-an-output-parameter-set-output

like image 78
peterevans Avatar answered Sep 19 '22 16:09

peterevans