Giter VIP home page Giter VIP logo

wait-on-check-action's Introduction

Wait on Check action

This action can be used to halt any workflow until required checks for a given git ref (branch, tag, or commit SHA) pass successfully. It uses GitHub Check Runs API to poll for a check result—until a check either succeeds or else.

On successful check, the action will yield control to next step. In any other case, the action will exit with status 1, failing the whole workflow.

🎉 It allows to work around a GitHub Actions limitation of non-interdependent workflows (we can only depend on jobs inside a single workflow).

In other words, you can run your workflows in parallel and only proceed with workflow B after workflow A completes and reports success.

A real-world scenario

  • A push to master triggers a test workflow that runs tests on application code.
  • A push to master triggers a webhook that builds an image on external service (Quay, DockerHub, etc.)
  • Once the image is built, a repository_dispatch hook is triggered from a third-party service that launches a deploy workflow.
  • We don't want the deploy workflow to succeed until we're sure that the master branch is green in test workflow.
  • We add the "Wait on tests" step to make sure deploy does not succeed before test for a master branch.

Example workflow code

# .github/workflows/deploy-dispatch.yml
name: Trigger deploy on external event
on:
  repository_dispatch:
    types: [build_success]

jobs:
  deploy:
    # see https://github.com/lewagon/quay-github-actions-dispatch for use-case
    if: startsWith(github.sha, github.event.client_payload.text)
    name: Deploy new image
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@master

      # This step will retry until required check passes
      # and will fail the whole workflow if the check conclusion is not a success
      - name: Wait on tests
        uses: lewagon/[email protected]
        with:
          ref: master # can be commit SHA or tag too
          check-name: test # name of the existing check
          repo-token: ${{ secrets.GITHUB_TOKEN }}
          wait-interval: 20 # seconds

      # Deploy step
      - name: Save DigitalOcean kubeconfig
        uses: digitalocean/action-doctl@master
        env:
          DIGITALOCEAN_ACCESS_TOKEN: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
        with:
          args: kubernetes cluster kubeconfig show my-cluster > $GITHUB_WORKSPACE/.kubeconfig

      - name: Upgrade/install chart
        run: export KUBECONFIG=$GITHUB_WORKSPACE/.kubeconfig && make deploy latest_sha=$(echo $GITHUB_SHA | head -c7)}}

Figruring out check name

curl -X GET https://api.github.com/repos/OWNER/REPO/commits/REF/check-runs \
-H 'Accept: application/vnd.github.antiope-preview+json' \
-H 'Authorization: token GITHUB_REPO_READ_TOKEN' | jq '[.check_runs[].name]'

To figure out a check name—use the curl command above. Note that by default this will be a value of jobs key, unless the name is provided.

# .github/workflows/test.yml
name: Rspec
on:
  push:
    branches:
      - master
  # Will run once the PR is opened or a new commit is pushed against it
  pull_request:
    types:
      - opened
      - synchronize
jobs:
  test:
    runs-on: ubuntu-latest
      steps:
      ...

☝️ Name is test.

# .github/workflows/test.yml
name: Rspec
on:
  push:
    branches:
      - master
  # Will run once the PR is opened or a new commit is pushed against it
  pull_request:
    types:
      - opened
      - synchronize
jobs:
  test:
    name: "My test workflow"
    runs-on: ubuntu-latest
      steps:
      ...

☝️ Name is My test workflow

wait-on-check-action's People

Contributors

axtgr avatar ssaunier avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.