Example Workflows

Example workflows used in CCBR repositories

You can copy these to your own repository in the .github/workflows/ directory and modify them for your needs.

add-issue-label-list

Source

name: add-issue-label-list

on:
  workflow_dispatch:
    inputs:
      issue-num:
        required: true
        type: string
        description: "Number of the issue to update (issue should already exist!)"
      label-name:
        required: true
        type: string
        description: "Name of the label to create a task list for (eg. RENEE, ccbr1310, etc.)"

jobs:
  add-list:
    runs-on: ubuntu-latest
    steps:
      - uses: CCBR/actions/add-issue-label-list
        with:
          github-token: ${{ github.token }}
          issue-num: ${{ inputs.issue-num }}
          label-name: ${{ inputs.label-name }}

auto-format

Source

name: auto-format

on:
  workflow_dispatch:
  pull_request:

env:
  GH_TOKEN: ${{ github.token }}

jobs:
  auto-format:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4
        if: github.event_name == 'pull_request'
        with:
          fetch-depth: 0
          ref: ${{ github.head_ref }}

      - uses: actions/checkout@v4
        if: github.event_name == 'push'
        with:
          fetch-depth: 0
          ref: ${{ github.ref_name }}

      - name: format
        uses: pre-commit/action@v3.0.1
        continue-on-error: true

      - name: commit & push
        run: |
          git config --global user.name "github-actions[bot]"
          git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
          git add .
          git commit -m "ci: 🤖 format everything with pre-commit" && git push || echo "nothing to commit"

build-docker-auto

Source

# This GitHub Actions workflow is designed to trigger a manual Docker build for each modified Dockerfile.
#
# Workflow Name: build-docker-auto
# Short Description: Trigger Build Docker Manual for Each modified Dockerfile
#
# Triggers:
# - On push events to any branch except 'main' and 'dev', if any Dockerfile.* is modified.
# - On pull request events to 'main' and 'dev' branches, if any Dockerfile.* is modified.
#
# Jobs:
#   - Runs on the latest Ubuntu environment.
#   - Steps:
#     1. Check out the repository using actions/checkout@v4.
#     2. Identify modified Dockerfiles using git diff and store them in the environment variable 'dockerfiles'.
#     3. For each modified Dockerfile, trigger the 'build-docker-manual' workflow with the Dockerfile path and additional parameters.
#
# Environment Variables:
# - GITHUB_TOKEN: Used for authentication to trigger the 'build-docker-manual' workflow.

name: build-docker-auto

on:
  push:
    branches:
      - "**autobuild**" # Only trigger if the branch name contains "autobuild"
    paths:
      - "**/Dockerfile.*" # Only trigger if a Dockerfile.* is modified in any directory

  pull_request:
    branches:
      - main
      - dev
    paths:
      - "**/Dockerfile.*" # Only trigger if a Dockerfile.* is modified in any directory

env:
  suffix: ${{ github.base_ref == 'main' && github.event_name == 'pull_request' && 'main' || github.base_ref == 'dev' && github.event_name == 'pull_request' && 'dev' || 'feat' }}

jobs:
  get-files:
    runs-on: ubuntu-latest
    outputs:
      json: ${{ steps.changed-files.outputs.matched_files_json }}
    steps:
      - name: Checkout repository
        id: checkout
        uses: actions/checkout@v4

      - id: changed-files
        name: Check changed files
        uses: knu/changed-files@v1
        with:
          paths: |
            **/Dockerfile.*

      - name: Show changed files
        id: matrix
        run: |
          echo "matched files:"
          echo "${{ steps.changed-files.outputs.matched_files }}" | sed 's/^/  /'

  build-docker:
    needs: [get-files]
    strategy:
      matrix:
        file: "${{ fromJson(needs.get-files.outputs.json) }}"
      max-parallel: 1
      fail-fast: false
    continue-on-error: true
    runs-on: ubuntu-latest
    permissions:
      contents: write
      pull-requests: write
    steps:
      - uses: actions/checkout@v4
        name: "checkout PR ${{ github.head_ref }}"
        if: github.event_name == 'pull_request'
        with:
          fetch-depth: 0
          ref: ${{ github.head_ref }} # branch name of PR

      - uses: actions/checkout@v4
        name: "checkout push ${{ github.ref_name }}"
        if: github.event_name == 'push'
        with:
          fetch-depth: 0
          ref: ${{ github.ref_name }} # branch name of push

      - uses: CCBR/actions/build-docker@v0.2
        with:
          dockerfile: ${{ matrix.file }}
          dockerhub-namespace: nciccbr
          dockerhub-username: ${{ secrets.DOCKERHUB_USERNAME_VK }}
          dockerhub-token: ${{ secrets.DOCKERHUBRW_TOKEN_VK }}
          suffix: ${{ env.suffix }}
          push: true
          ccbr-actions-version: v0.2
          github-token: ${{ github.token }}
          json-file: "scripts/tool_version_commands.json"

build-docker-manual

Source

# This GitHub Actions workflow is designed to manually build and optionally push a Docker image to DockerHub.
#
# Workflow Name: build-docker-manual
#
# Inputs:
# - dockerfile: Path to the Dockerfile in the repository (e.g., common/ccbr_bwa/Dockerfile). This input is required.
# - dockerhub-namespace: DockerHub namespace or organization name (e.g., nciccbr). This input is required and defaults to 'nciccbr'.
# - push: Boolean flag to determine whether to push the built image to DockerHub. This input is required and defaults to 'false'.
#
# Jobs:
# - build-docker: This job runs on an Ubuntu latest runner and performs the following steps:
#   - Checks out the repository.
#   - Logs in to DockerHub if the 'push' input is set to 'true'.
#   - Prepares build-time variables by running a custom script.
#   - Checks variables and creates a temporary README file with build details.
#   - Builds and optionally pushes the Docker image using the docker/build-push-action.
#   - Lists Docker images on the runner.
#   - Updates the DockerHub description with the contents of the temporary README file if the image was successfully pushed.

name: build-docker-manual
run-name: build-docker ${{ inputs.dockerfile }}-${{ inputs.suffix }}

on:
  workflow_dispatch:
    inputs:
      dockerfile:
        type: string
        description: path to the Dockerfile in the repo (e.g. common/ccbr_bwa/Dockerfile)
        required: true
      dockerhub-namespace:
        type: string
        description: dockerhub namespace or org name (e.g. nciccbr)
        required: true
        default: nciccbr
      suffix:
        type: string
        description: Suffix to add to image tag eg. "dev" to add "-dev"
        required: true
        default: feat
      push:
        type: boolean
        description: Push to DockerHub (leave unchecked to just build the container without pushing)
        required: true
        default: false
      ccbr-actions-version:
        description: "The version of ccbr_actions to use"
        required: true
        default: "v0.2"

jobs:
  build-docker:
    runs-on: ubuntu-latest
    permissions:
      contents: write
      pull-requests: write
    steps:
      - name: Checkout repository
        id: checkout
        uses: actions/checkout@v4

      - uses: CCBR/actions/build-docker@v0.2
        with:
          dockerfile: ${{ github.event.inputs.dockerfile }}
          dockerhub-namespace: ${{ github.event.inputs.dockerhub-namespace }}
          dockerhub-username: ${{ secrets.DOCKERHUB_USERNAME_VK }}
          dockerhub-token: ${{ secrets.DOCKERHUBRW_TOKEN_VK }}
          suffix: ${{ github.event.inputs.suffix }}
          push: ${{ github.event.inputs.push }}
          ccbr-actions-version: ${{ github.event.inputs.ccbr-actions-version }}
          github-token: ${{ github.token }}
          json-file: "scripts/tool_version_commands.json"

build-nextflow

Source

name: build
# TODO replace tool_name with the name of your tool

on:
  push:
    branches:
      - main
      - develop
  pull_request:
    branches:
      - main
      - develop

jobs:
  build:
    runs-on: ubuntu-latest
    timeout-minutes: 2
    strategy:
      matrix:
        python-version: ["3.11"]
    steps:
      - uses: actions/checkout@v3
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.python-version }}
          cache: "pip"
      - name: Install nextflow
        uses: nf-core/setup-nextflow@v1
      - name: Install Python dependencies
        run: |
          python -m pip install --upgrade pip setuptools
          pip install .[dev,test]
      - name: Check CLI basics
        run: |
          which tool_name
          tool_name --help
          tool_name --version
          tool_name --citation
      - name: Stub run
        run: |
          mkdir -p tmp && pushd tmp
          tool_name init
          tool_name run -c conf/ci_stub.config -stub
          popd
      - name: "Upload Artifact"
        uses: actions/upload-artifact@v3
        if: always() # run even if previous steps fail
        with:
          name: nextflow-log
          path: .nextflow.log

  build-status: # https://github.com/orgs/community/discussions/4324#discussioncomment-3477871
    runs-on: ubuntu-latest
    needs: [build]
    if: always()
    steps:
      - name: Successful build
        if: ${{ !(contains(needs.*.result, 'failure')) }}
        run: exit 0
      - name: Failing build
        if: ${{ contains(needs.*.result, 'failure') }}
        run: exit 1

build-python

Source

# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: build

on:
  push:
    branches:
      - main
      - master
  pull_request:
    branches:
      - main
      - master

env:
  GH_TOKEN: ${{ github.token }}

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        python-version: ["3.11"]

    steps:
      - uses: actions/checkout@v4
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v3
        with:
          python-version: ${{ matrix.python-version }}
      - name: Lint
        uses: psf/black@stable
        continue-on-error: true
        with:
          options: "--check --verbose"
          use_pyproject: true
      - name: Install dependencies
        run: |
          python -m pip install .[dev,test] --upgrade pip
      - name: Test
        run: |
          python -m pytest --cov src
      - uses: codecov/codecov-action@v4
        with:
          token: ${{ secrets.CODECOV_TOKEN }}

  build-status: # https://github.com/orgs/community/discussions/4324#discussioncomment-3477871
    runs-on: ubuntu-latest
    needs: [build]
    if: always()
    steps:
      - name: Successful build
        if: ${{ !(contains(needs.*.result, 'failure')) }}
        run: exit 0
      - name: Failing build
        if: ${{ contains(needs.*.result, 'failure') }}
        run: exit 1

build-snakemake

Source

name: build

on:
  push:
    branches:
      - master
      - main
      - develop
  pull_request:

jobs:
  dryrun-lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: docker://snakemake/snakemake:v7.32.4
      - name: Dry-run
        run: |
          docker run -v $PWD:/opt2 -w /opt2 snakemake/snakemake:v7.32.4 \
            ./bin/renee run \
              --input .tests/KO_S3.R1.fastq.gz .tests/KO_S3.R2.fastq.gz .tests/KO_S4.R1.fastq.gz .tests/KO_S4.R2.fastq.gz .tests/WT_S1.R1.fastq.gz .tests/WT_S1.R2.fastq.gz .tests/WT_S2.R1.fastq.gz .tests/WT_S2.R2.fastq.gz \
              --output output \
              --genome config/genomes/biowulf/hg38_30.json \
              --shared-resources .tests/shared_resources/ \
              --mode local \
              --dry-run
      - name: Lint
        continue-on-error: true
        run: |
          docker run -v $PWD:/opt2 snakemake/snakemake:v7.32.4 \
            snakemake --lint -s /opt2/output/workflow/Snakefile -d /opt2/output || \
          echo 'There may have been a few warnings or errors. Please read through the log to determine if its harmless.'

  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: ["3.11"]
        snakemake-version: ["7.32.3"]
    steps:
      - uses: actions/checkout@v4
      - uses: mamba-org/setup-micromamba@v1
        with:
          environment-name: test
          cache-environment: true
          condarc: |
            channels:
              - conda-forge
              - bioconda
          create-args: >-
            python=${{ matrix.python-version }}
            snakemake=${{ matrix.snakemake-version }}
            setuptools
            pip
            pytest
      - name: check CLI basics
        run: |
          ./bin/renee --help
          ./bin/renee --version
        shell: micromamba-shell {0}
      - name: pip install python package
        run: |
          pip install .[dev,test]
        shell: micromamba-shell {0}
      - name: Test
        run: |
          python -m pytest
        env:
          TMPDIR: ${{ runner.temp }}
        shell: micromamba-shell {0}

  build-status: # https://github.com/orgs/community/discussions/4324#discussioncomment-3477871
    runs-on: ubuntu-latest
    needs: [dryrun-lint, test]
    if: always()
    steps:
      - name: Successful build
        if: ${{ !(contains(needs.*.result, 'failure')) }}
        run: exit 0
      - name: Failing build
        if: ${{ contains(needs.*.result, 'failure') }}
        run: exit 1

docs-mkdocs

Source

name: docs
# this workflow requires:
#  - an mkdocs config file (`mkdocs.yml`)
#  - website dependencies in `docs/requirements.txt`
on:
  workflow_dispatch:
  release:
    types:
      - published
  push:
    branches:
      - main
    paths:
      - "docs/**"
      - "**.md"
      - .github/workflows/docs-mkdocs.yml
      - mkdocs.yml

jobs:
  mkdocs:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - uses: CCBR/actions/mkdocs-mike@v0.1
        with:
          github-token: ${{ github.token }}

docs-quarto

Source

name: docs

on:
  workflow_dispatch:
  push:
    branches: main
    paths:
      - "docs/**"
      - ".github/workflows/quarto-publish.yml"

permissions:
  contents: write
  pages: write

jobs:
  build-deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Check out repository
        uses: actions/checkout@v4

      - name: Set up Quarto
        uses: quarto-dev/quarto-actions/setup@v2

      - name: Publish to GitHub Pages (and render)
        uses: quarto-dev/quarto-actions/publish@v2
        with:
          target: gh-pages
          path: docs/
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

draft-release

Source

name: draft-release

on:
  workflow_dispatch:
    inputs:
      version-tag:
        description: |
          Semantic version tag for next release.
          If not provided, it will be determined based on conventional commit history.
          Example: v2.5.11
        required: false
        type: string
        default: ""

jobs:
  draft-release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0 # required to include tags
      - uses: CCBR/actions/draft-release@v0.1
        with:
          github-token: ${{ github.token }}
          version-tag: ${{ github.event.inputs.version-tag }}

label-issues-repo-name

Source

name: label-issues-repo-name

on:
  issues:
    types:
      - opened
  pull_request:
    types:
      - opened

jobs:
  add-label:
    runs-on: ubuntu-latest
    steps:
      - uses: CCBR/actions/label-issue-repo-name
        with:
          github-token: ${{ github.token }}

post-release

Source

name: post-release

on:
  release:
    types:
      - published

jobs:
  cleanup:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - uses: CCBR/actions/post-release@v0.1
        with:
          github-token: ${{ github.token }}

techdev-project

Source

name: TechDev-project

on:
  issues:
    types:
      - opened
  pull_request:
    types:
      - opened

jobs:
  add-to-project:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/add-to-project@v1.0.2
        with:
          project-url: https://github.com/orgs/CCBR/projects/17
          github-token: ${{ secrets.ADD_TO_PROJECT_PAT }}

update-cff-R

Source

# Workflow derived from https://github.com/r-lib/actions/tree/master/examples
# The action runs when:
# - A new release is published
# - The DESCRIPTION or inst/CITATION are modified
# - Can be run manually
# For customizing the triggers, visit https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows
on:
  release:
    types: [published]
  pull_request:
    branches: [master, main]
    paths:
      - .github/workflows/update-citation-cff.yaml
      - DESCRIPTION
      - inst/CITATION
  workflow_dispatch:

name: Update CITATION.cff

jobs:
  update-citation-cff:
    runs-on: macos-latest
    env:
      GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
    steps:
      - uses: actions/checkout@v3
        with:
          ref: ${{ github.head_ref }}
          fetch-depth: 0
      - uses: r-lib/actions/setup-r@v2
      - uses: r-lib/actions/setup-r-dependencies@v2
        with:
          extra-packages: |
            any::cffr
            any::V8
            any::docopt

      - name: Update CITATION.cff
        run: |

          library(cffr)

          # Customize with your own code
          # See https://docs.ropensci.org/cffr/articles/cffr.html

          # Write your own keys
          mykeys <- list()

          # Create your CITATION.cff file
          cff_write(keys = mykeys)

        shell: Rscript {0}
      - uses: pre-commit/action@v3.0.0
        with:
          extra_args: --files CITATION.cff
        continue-on-error: true
      - name: Commit results
        run: |
          git config --local user.name "github-actions[bot]"
          git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
          git add CITATION.cff
          git commit -m 'chore: update CITATION.cff' || echo "No changes to commit"
          git push origin || echo "No changes to commit"

user-projects

Source

name: personal-projects

on:
  issues:
    types:
      - assigned
  pull_request:
    types:
      - assigned

jobs:
  add-to-project:
    uses: CCBR/.github/.github/workflows/auto-add-user-project.yml@v0.1.0
    secrets: inherit