Sohail Ahmed
Sohail Ahmed

Reputation: 1190

GitHub actions splitting workflow file

Is it possible to split a GitHub Actions workflow file and reference it from other? I need to deploy an application into multiple environments i.e. staging and production and would like to share half of the steps to minimize maintenance.

Upvotes: 7

Views: 6814

Answers (2)

Carl M. Cartagena
Carl M. Cartagena

Reputation: 111

You can split each action in the following file format:

folder named "test-action"

.github/test-action/action.yml

with contents

  name: test-action
  description: test action
  inputs:
    test_input:
      description: key
      required: true
  runs:
    using: composite
    steps:
      - name: echo test
        shell: bash
        run: |
          echo ${{inputs.test_input}}

then you can refer to the action from any yml:

  - name: test-action
    uses: ./.github/test-action
    with:
      test_input: "test-string-value"

the key here was to make sure that the file within your named action folder would be called "action.yml"

Upvotes: 8

banyan
banyan

Reputation: 4182

It seems like there is no way as CircleCI allows defining commands that are a set of steps: https://github.community/t5/GitHub-Actions/reusing-sharing-inheriting-steps-between-jobs-declarations/td-p/37849

At this moment, I guess we can use repository_dispatch as a workaround. In this example, it handles events between repositories, but I think we can apply this in same repository: https://blog.marcnuri.com/triggering-github-actions-across-different-repositories/

Upvotes: 1

Related Questions