We can create templates for our github actions which is similar to Azure Devops templates. To get started lets see how we can step a simple ones. Here is the code for github templates and this goes into probably a repository call template - for example - https://github.com/mitzenjeremywoo?tab=repositories
Templates as shown here. The key thing here is workflow_call which is require together with its inputs paramters.
name: build-dotnet
on:
workflow_call:
# Introduced 'inputs' to define parameters that can be passed when calling this workflow
inputs:
project:
description: "Node version"
required: true
type: string
jobs:
build-dotnet:
runs-on: ubuntu-latest
steps:
# check out
- name: checkout repo
uses: actions/checkout@v4
# Runs a single command using the runners shell
- name: Run a one-line script
run: echo Hello, ${{ inputs.project }}!
Consumer
One we have check it in and then we can call it from one of our dotnet projects using the following yaml. An example of how this can be called are shown here: https://github.com/mitzenjeremywoo/github-workflow-consumer
# This is a basic workflow to help you get started with Actions
name: CI
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
uses: mitzenjeremywoo/github-devops-template/.github/workflows/dotnet-build.yaml@main
with:
project: "mytest"
Notice the key parameters are
"uses: mitzenjeremywoo/github-devops-template/.github/workflows/dotnet-build.yaml@main" and it reference the main branch.
Atho this is a very simple setup, we can quickly setup and build more complicated workflow from here.
Comments