Section 4 - The deploy reusable workflow
Last updated
Last updated
Similarly to the reusable test and the build and push job , the reusable deploy job will closely resemble the one we created in Chapter 2, Section 5. The main difference is that this new workflow job will be part of a reusable workflow, allowing it to be called from other repositories.
We’ll start by referencing the logic used in Chapter 2, Section 5 (The deploy job) and refactor it to be part of a reusable workflow.
First, we will rename the reusable-test-build.yaml
file located in the .github/workflows/
directory of the repository to reusable-test-build-deploy.yaml
Next, we’ll refactor the deploy workflow job by copying it from one of our service repositories and placing it below the build and push
job in our newly renamed reusable workflow file. For this example, we'll use the from the test-build-and-deploy
workflow in the user-management-service
repository and modify it to be reusable.
To make the deploy
job reusable, we’ll follow a similar process as with the build and push
job. Since it’s now part of a reusable workflow file, we only need to introduce the necessary inputs and utilize them within the job.
We’ll add the following inputs, providing default values for each:
deploy-commit: wether to commit changes for deploy
defaults to: ${{ github.event_name != 'pull_request' }}
deploy-create-pr: wethe to create the pr for deploy
defauts to: ${{ github.event_name != 'pull_request' }}
We’ll now place the deploy
job into the reusable workflow, integrating the inputs we just defined: