Skip to content

Commit

Permalink
Add .github directory for workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
dwoz committed Aug 31, 2024
1 parent 38f104a commit e27b4f3
Show file tree
Hide file tree
Showing 7 changed files with 372 additions and 0 deletions.
142 changes: 142 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
name: CI

concurrency:
# Concurrency is defined in a way that concurrent builds against branches do
# not cancel previous builds.
# However, for every new build against the same pull request source branch,
# all older builds against that same branch get canceled.
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.repository }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

on:
workflow_call:
inputs:
kind:
required: false
type: string
default: dev
package_command:
required: false
type: string
description: Command used to build python package
default: >-
python -m
build
-C--global-option=egg_info
-C--global-option=--tag-build=+dev$(git rev-parse --short HEAD)
--wheel
--outdir dist/
secrets:
PYPI_API_TOKEN:
required: false

jobs:

get-changed-files:
name: Get Changed Files
runs-on: ubuntu-latest
permissions:
contents: read # for dorny/paths-filter to fetch a list of changed files
pull-requests: read # for dorny/paths-filter to read pull requests
outputs:
changed-files: ${{ toJSON(steps.changed-files.outputs) }}
steps:
- uses: actions/checkout@v3
- name: Get Changed Files
id: changed-files
uses: dorny/paths-filter@v2
with:
token: ${{ github.token }}
list-files: json
filters: |
repo:
- added|modified:
- '**'
deleted:
- deleted:
- '**'
pre-commit:
name: Pre-Commit
uses: ./.github/workflows/pre-commit-action.yml
needs:
- get-changed-files
with:
changed-files: ${{ needs.get-changed-files.outputs.changed-files }}

build-python-package:
name: Python Package
uses: ./.github/workflows/package-action.yml
if: always()
needs:
- pre-commit
with:
kind: "${{ inputs.kind }}"
cmd: "${{ inputs.package_command }}"

test:
name: Test
needs:
- get-changed-files
uses: ./.github/workflows/test-action.yml
with:
changed-files: ${{ needs.get-changed-files.outputs.changed-files }}

deploy-python-package:
name: Deploy Python Package
uses: ./.github/workflows/deploy-package-action.yml
if: ${{ inputs.kind == 'release' && success() }}
needs:
- pre-commit
- test
- build-python-package
secrets:
PYPI_API_TOKEN: "${{ secrets.PYPI_API_TOKEN }}"

push-tag:
name: Push Version Tag
runs-on: ubuntu-latest
permissions:
contents: write
if: ${{ inputs.kind == 'release' && success() }}
needs:
- build-python-package
- deploy-python-package
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Push Tag
uses: rickstaa/action-create-tag@v1
with:
tag: "v${{ needs.build-python-package.outputs.version }}"
message: "Version ${{ needs.build-python-package.outputs.version }}"

set-pipeline-exit-status:
# This step is just so we can make github require this step, to pass checks
# on a pull request instead of requiring all
name: Set the CI Pipeline Exit Status
runs-on: ubuntu-latest
if: always()
needs:
- pre-commit
- test
- deploy-python-package
- push-tag
steps:
- name: Get workflow information
id: get-workflow-info
uses: technote-space/workflow-conclusion-action@v3

- name: Set Pipeline Exit Status
shell: bash
run: |
if [ "${{ steps.get-workflow-info.outputs.conclusion }}" != "success" ]; then
exit 1
else
exit 0
fi
- name: Done
if: always()
run:
echo "All workflows finished"
22 changes: 22 additions & 0 deletions .github/workflows/deploy-package-action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Relenv Python Package

on:
workflow_call:
secrets:
PYPI_API_TOKEN:
required: true

jobs:
build:
name: Publish Python Wheel
runs-on: ubuntu-latest
steps:
- name: Download Python Package Artifacts
uses: actions/download-artifact@v3
with:
name: dist
path: dist
- name: Publish distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
70 changes: 70 additions & 0 deletions .github/workflows/package-action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Relenv Python Package

on:
workflow_call:
inputs:
kind:
required: false
type: string
default: dev
cmd:
required: false
type: string
description: Command used to build python package
default: >-
python -m
build
-C--global-option=egg_info
-C--global-option=--tag-build=dev$(git rev-parse --short HEAD)
--wheel
--outdir dist/
outputs:
version:
value: "${{ jobs.build.outputs.version }}"

jobs:
build:
name: Build Python Wheel
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@master
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install pypa/build
run: >-
python -m
pip install
build
--user
- name: Install pypa/pkginffo
run: >-
python -m
pip install
pkginfo
--user
- name: Echo Build Wheel Command
run: echo "${{ inputs.cmd }}"

- name: Build Wheel
run: "${{ inputs.cmd }}"

- name: Python Build Artifact
uses: actions/upload-artifact@v3
if: always()
with:
name: dist
path: dist/*
retention-days: 5
- name: Read Version
run: >-
python3
-c
"from pkginfo import Wheel; s = Wheel('dist/$(ls dist/)'); print(f'version={s.version}')"
>>
$GITHUB_OUTPUT
id: version
17 changes: 17 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Pull Request or Push

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

jobs:
ci:
name: CI
uses: ./.github/workflows/ci.yml
permissions:
contents: write
pull-requests: read
40 changes: 40 additions & 0 deletions .github/workflows/pre-commit-action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Pre-Commit

on:
workflow_call:
inputs:
changed-files:
required: true
type: string
description: JSON string containing information about changed files

jobs:
Pre-Commit:
name: Pre-Commit Checks

runs-on: ubuntu-latest

steps:

- name: Install System Deps
run: |
sudo apt-get update
sudo apt-get install -y git gcc make zlib1g-dev libc-dev libffi-dev g++ libxml2 libxml2-dev libxslt-dev libcurl4-openssl-dev libssl-dev libgnutls28-dev
- uses: actions/checkout@v3

- name: Install Pre-Commit
run: |
python -m pip install --upgrade pip
pip install pre-commit
pre-commit install --install-hooks
- name: Check ALL Files On Branch
if: github.event_name != 'pull_request'
run: |
pre-commit run --show-diff-on-failure --color=always --all-files
- name: Check Changed Files On PR
if: github.event_name == 'pull_request' && fromJSON(inputs.changed-files)['repo'] == 'true'
run: |
pre-commit run --show-diff-on-failure --color=always --files ${{ join(fromJSON(inputs.changed-files)['repo_files'], ' ') }}
32 changes: 32 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Build and Release

on:
workflow_dispatch:
inputs:
kind:
required: false
type: string
default: dev
package_command:
required: false
type: string
description: Command used to build python package
default: >-
python -m
build
--wheel
--outdir dist/
jobs:
ci:
name: CI
permissions:
contents: write
pull-requests: read
uses: ./.github/workflows/ci.yml
if: contains('["dwoz", "twangboy", "dmurphy18"]', github.actor)
with:
kind: "${{ inputs.kind }}"
package_command: "${{ inputs.package_command }}"
secrets:
PYPI_API_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
49 changes: 49 additions & 0 deletions .github/workflows/test-action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Unit Tests

on:
workflow_call:
inputs:
changed-files:
required: true
type: string
description: JSON string containing information about changed files

jobs:
test:
strategy:
fail-fast: false
matrix:
runs-on:
- ubuntu-latest
- macos-12
- macos-13-xlarge
- windows-latest

name: Unit Test ${{ matrix.runs-on }}
runs-on: ${{ matrix.runs-on }}

steps:
- uses: actions/checkout@v3

- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"

- name: Install python dependencies
run: |
pip3 install nox
- name: Install Linux dependencies
if: ${{ matrix.runs-on == 'linux' }}
run: |
apt-get install -y shellcheck
- name: Install Mac dependencies
if: ${{ matrix.runs-on == 'macos-12' || matrix.runs-on == 'macos-13-xlarge' }}
run: |
brew install shellcheck
- name: Run tests
run: |
nox -e tests

0 comments on commit e27b4f3

Please sign in to comment.