DEV Community

sumandari
sumandari

Posted on • Edited on

1

GithubAction -- use a workflow from another workflow

It's called reusable workflow.

I have a workflow for test, and I have another workflow for release. Everytime I release a version, I want to have test passed before run release jobs.

What I have to do is to add workflow_call on my workflow

# ci.yaml
name: ci-build-and-test

on:
  push:
    branches:
      - main
  pull_request:
  workflow_call:

jobs:
  - (steps to checkout, setup dependency and run test)

Enter fullscreen mode Exit fullscreen mode

then I can call it manually from another workflow (yaml file) by using uses and path to the ci.yaml file.
If you're using the reusable workflow from different repository then you need to add your github organisation and repo name.

# cd.yaml
name: cd-build-and-publish

on:
  release:
    types:
      - released

jobs:
  compliance:
    if: github.event.release.target_commitish == 'main'
    uses: ./.github/workflows/ci.yaml

Enter fullscreen mode Exit fullscreen mode

see more at:
https://github.blog/2022-02-10-using-reusable-workflows-github-actions/

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay