pyreal icon indicating copy to clipboard operation
pyreal copied to clipboard

Consolidate Workflows with Organization

Open Behemyth opened this issue 3 years ago • 0 comments

Each organization comes with a special repository call .github that acts like a depot for GitHub configuration data for all repositories under the envelope of the org.

Under root/workflow-templates, workflow templates can be placed that enable new repositories under the organization to quickly add workflows with a click of a button. Coupled with workflow references, this can be a powerful thing.

Under root/.github/workflows for the .github repository you can add workflows like usual, have them be referenced by the template in a central location, and use them for all repositories in your org that need them. One workflow, multiple points of use. GitHub calls them Reusable Workflows.

If there is a bug with a workflow, it can be edited in the .github repository, and the fix automatically gets called the next time the reusable workflow is called from a different repository.

Example

A quick example for running PR tests for Python.

.github/workflow-templates/python-check.yml

name: Check Python Status
on:
  - pull_request

jobs:
  check:
    uses: sibyl-dev/.github/.github/workflows/python-check.yml@stable

A Check template for all repos. Allows itto be added once with the click of a button in the desired repositories 'Action' tab. If you have a bug in this file or you generally change the file's contents, you will have to edit the template in the .github repository and all other repositories that contain the workflow created by the old template.

.github/workflow-templates/python-check.properties.json

{
    "name": "Sibyl Org Check Python Status",
    "description": "Python status checking workflow template.",
    "iconName": "python",
    "categories": [
        "Python"
    ]
}

Metadata that is presented when the user clickes the repos 'Action' tab and searches for available actions.

.github/.github/workflows/python-check.yml

name: Python Check

on:
  workflow_call:

jobs:
  test:
    strategy:
      matrix:
        os: ["ubuntu-latest", "windows-latest"]
        python-version: ["3.10"]

    runs-on: ${{ matrix.os }}

    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Setup Python
        uses: actions/setup-python@v2
        with:
          python-version: ${{ matrix.python-version }}

      - name: Install PDM
        uses: pdm-project/setup-pdm@v2
        with:
          python-version: ${{ matrix.python-version }}
          enable-pep582: true

      - name: Install Dependencies
        run: pdm install

      - name: Test
        run: pdm run pytest tests/

  lint:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Black
        uses: psf/black@stable
        with:
          options: "--check --verbose"

Gets called by the template, installs python with PDM (an alternative to Poetry), and tests it. On the side it also lints the project. This is the workflow that allows you to edit something in one location and have it affect multiple repositories.

Behemyth avatar Jan 13 '22 01:01 Behemyth