Templates for GitHub Actions?

Templates are a really useful part of Azure DevOps pipelines, I was curious if that functionality would be ported over to GitHub Actions. I’m aware that I can just create an “action” but it would be easier sometimes to maintain small specialized templates in my repo of concern rather than creating a generalized action each time.

https://docs.microsoft.com/en-us/azure/devops/pipelines/process/templates?view=azure-devops

1 Like

@adithyabsk ,

Thanks for your feedback.
Currently, GitHub Actions does not support Templates  like as that in YAML pipelines of Azure Pipelines.

GitHub takes your suggestions very seriously, and the suggestions are very helpful for improving GitHub.
I recommend you directly share your suggestion here. That will allow you to directly interact with the appropriate engineering team, and make it more convenient for the engineering team to collect and categorize your suggestions.

1 Like

I recommend you directly share your suggestion here .

I have submitted a feature request, but I would like to leave the same message here, for an open discussion.


Hi there,

is there a way to reuse a certain part of a workflow? Azure can handle templates, I am curious what is the preferred way to achieve the same with GitHub Actions, if there is any. The Azure to GH Actions migration guide does not mention it.

Here is my use case:
In a single repo, I would like to set up a snapshot, a nightly, and a release workflow.
This is how it is done now:
.github/workflows/all-in-one.yml:

name: All in one build

on:
  push:
    branches:
      - master # snapshot
    tags:
      - '[0-9]+.[0-9]+.[0-9]+*' # release
  pull_request:
    branches:
      - master # snapshot
  schedule:
    - cron: '0 3 * * *' # nightly

jobs:

  build:
    strategy:
      matrix:
        config:
          - os: windows-latest
          - os: ubuntu-latest
          - os: macos-latest
    runs-on: ${{ matrix.config.os }}
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Package
        shell: bash
        run: ./package.sh

      - name: Upload [GitHub Actions]
        uses: actions/upload-artifact@v2

  publish:
    needs: build
    if: github.event_name == 'schedule'
    runs-on: ubuntu-latest
    steps:
      - name: Download [GitHub Actions]
        uses: actions/download-artifact@v2

      - name: Publish Nightly [S3]
        uses: my-cool-action/push-to-s3

  release:
    needs: build
    if: startsWith(github.ref, 'refs/tags/')
    runs-on: ubuntu-latest
    steps:
      - name: Download [GitHub Actions]
        uses: actions/download-artifact@v2

      - name: Create Release [GitHub]
        uses: actions/create-release@v1

      - name: Publish Release [GitHub]
        uses: my-cool-action/publish-gh-release

      - name: Publish Release [S3]
        uses: my-cool-action/push-to-s3

Instead of having one single workflow file, I would like to have three distinct ones and somehow reuse multiple steps as a template:
.github/workflows/snapshot.yml:

name: Snapshot

on:
  push:
    branches:
      - master # snapshot
  pull_request:
    branches:
      - master # snapshot

jobs:

  build:
    strategy:
      matrix:
        config:
          - os: windows-latest
          - os: ubuntu-latest
          - os: macos-latest
    runs-on: ${{ matrix.config.os }}
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Package
        shell: bash
        run: ./package.sh

      - name: Upload [GitHub Actions]
        uses: actions/upload-artifact@v2

.github/workflows/nightly.yml:

name: Nightly

on:
  schedule:
    - cron: '0 3 * * *' # nightly

jobs:

  build:
    steps:
        template: '.github/workflows/snapshot.yml'

  publish:
    needs: build
    # NOTE: this is not required anymore here `if: github.event_name == 'schedule'`
    runs-on: ubuntu-latest
    steps:
      - name: Download [GitHub Actions]
        uses: actions/download-artifact@v2

      - name: Publish Nightly [S3]
        uses: my-cool-action/push-to-s3

.github/workflows/release.yml:

name: Release

on:
  push:
    tags:
      - '[0-9]+.[0-9]+.[0-9]+*' # release
jobs:

  build:
    steps:
        template: '.github/workflows/snapshot.yml'

  release:
    needs: build
    # NOTE: this is not required anymore here `if: startsWith(github.ref, 'refs/tags/')`
    runs-on: ubuntu-latest
    steps:
      - name: Download [GitHub Actions]
        uses: actions/download-artifact@v2

      - name: Create Release [GitHub]
        uses: actions/create-release@v1

      - name: Publish Release [GitHub]
        uses: my-cool-action/publish-gh-release

      - name: Publish Release [S3]
        uses: my-cool-action/push-to-s3

My use-case is different than the one mentioned here. I do not want to reuse the same workflow files among multiple repositories. Is this possible?

Thank you!

Related threads:

Are you looking for this ?

Thank you for the quick reply, @varunsridharan. Not really. The description of your action says:

This Github Action can come in handy when you have lot of projects like i do. where in some case certain projects users action workflow which are common across projects.

My use case is different. I have one repo only. I tried to be clear about it, sorry if it led to confusion:

My use-case is different than the one mentioned here. I do not want to reuse the same workflow files among multiple repositories. Is this possible?

I also supprot request of templates. Custom github action does not allow to use other action inside. So its does not allow to extract common steeps to single template and force code repetition.