I hope you're enjoying the Actions Hackathon 2021. I'm impressed by the participants' submissions leveraging already existing actions. Guess what? GitHub made it even easier for participants to use existing workflows and actions with a new feature called reusable workflows.
Prior to the launch of this feature, if you wanted to reuse an existing workflow, you had to copy and paste the workflow into your new workflow. This can make workflows seem overly verbose. As software engineers, we want to follow best practices. One of my favorite best practices for writing clean code is the DRY principle, which is an acronym for Don't Repeat Yourself. Adopting reusable workflows also makes it easier to manage workflows. Now, with reusable workflows, you can write clean, maintainable Actions.
- Terms to know
- Caller workflow: a workflow that uses another workflow
- Called workflow: the reusable workflow
You can make a workflow reusable by adding a
workflow_call trigger to the called workflow. A
workflow_call trigger looks like this:
Inside of the
workflow_call trigger, you can pass in the necessary inputs and secrets similar to the example below:
on: workflow_call: inputs: ring: description: 'Identifier for the target deployment ring' default: 'ring-0' required: false type: string environment: required: false type: string secrets: token: required: false
Your caller workflow can call multiple workflows; however, a called workflow cannot call other reusable workflows.
If a workflow meets one of the criteria below, it can gain access to another workflow:
- The called workflow is stored in a public repository.
- Both workflows are in the same repository.
- The called workflow is stored in an internal repository, and the settings for that repository allow it to be accessed. Click here to learn how to configure those settings.
Below is a list of resources that may help you build and use your own reusable workflows:
- CoderDave uses reusable workflows to build and publish a docker image
- GitHub's official documentation about reusable workflows (with examples)
- Colin Dembovsky's detailed review of reusable workflows
From now until December 8th, GitHub is running a Hackathon. By participating, you have the chance to win gift cards and swag. The challenge is to create and submit a workflow leveraging already existing actions. GitHub Marketplace currently has over 10,000 actions.
Read here to learn more about participating in the hackathon.
And if you need any help regarding actions, I'll be available to answer questions in this thread.
Tell me about a use case where reusable workflows would benefit you!