Skip to content

Shared template for GitHub Actions

Notifications You must be signed in to change notification settings

soulsbros/CICD-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

CICD-template

Test workflow

Shared template for GitHub Actions

Usage

For example, to build on all branches and tags, add this to .github/workflows/your-workflow.yml:

name: your-workflow

on:
  push:
    branches:
      - "*"
    tags:
      - "*"

jobs:
  build-tags:
    # Build and push the image with the tag name
    uses: steeven9/CICD-template/.github/workflows/docker-build.yml@main
    if: github.ref_type == 'tag'
    with:
      image-name: some-org/some-image:${{ github.ref_name }}  # TODO adapt to your needs
      push: true
    secrets:
      DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
      DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}

  build-branches:
    # Build all branches but push only in main
    uses: steeven9/CICD-template/.github/workflows/docker-build.yml@main
    if: github.ref_type == 'branch'
    with:
      image-name: some-org/some-image:latest  # TODO adapt to your needs
      push: ${{ github.ref_name == 'main' }}
      ping_webhook: ${{ github.ref_name == 'main' }}
    secrets:
      DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
      DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
      WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }}

You can also override the Dockerfile location with the dockerfile input.

Resources

Actions used

https://github.com/docker/login-action

https://github.com/docker/build-push-action

Documentation

https://docs.github.com/en/actions/sharing-automations/reusing-workflows#creating-a-reusable-workflow