From e27b4f3855201dc8d977226e9f4cc497bdf184fd Mon Sep 17 00:00:00 2001 From: "Daniel A. Wozniak" Date: Sat, 31 Aug 2024 01:20:18 -0700 Subject: [PATCH] Add .github directory for workflows --- .github/workflows/ci.yml | 142 ++++++++++++++++++++ .github/workflows/deploy-package-action.yml | 22 +++ .github/workflows/package-action.yml | 70 ++++++++++ .github/workflows/pr.yml | 17 +++ .github/workflows/pre-commit-action.yml | 40 ++++++ .github/workflows/release.yml | 32 +++++ .github/workflows/test-action.yml | 49 +++++++ 7 files changed, 372 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/deploy-package-action.yml create mode 100644 .github/workflows/package-action.yml create mode 100644 .github/workflows/pr.yml create mode 100644 .github/workflows/pre-commit-action.yml create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/test-action.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..a9e264f --- /dev/null +++ b/.github/workflows/ci.yml @@ -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" diff --git a/.github/workflows/deploy-package-action.yml b/.github/workflows/deploy-package-action.yml new file mode 100644 index 0000000..27605e1 --- /dev/null +++ b/.github/workflows/deploy-package-action.yml @@ -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 }} diff --git a/.github/workflows/package-action.yml b/.github/workflows/package-action.yml new file mode 100644 index 0000000..85bde7a --- /dev/null +++ b/.github/workflows/package-action.yml @@ -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 diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml new file mode 100644 index 0000000..c5c9a56 --- /dev/null +++ b/.github/workflows/pr.yml @@ -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 diff --git a/.github/workflows/pre-commit-action.yml b/.github/workflows/pre-commit-action.yml new file mode 100644 index 0000000..12d334b --- /dev/null +++ b/.github/workflows/pre-commit-action.yml @@ -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'], ' ') }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..5c458a7 --- /dev/null +++ b/.github/workflows/release.yml @@ -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 }} diff --git a/.github/workflows/test-action.yml b/.github/workflows/test-action.yml new file mode 100644 index 0000000..8c61d46 --- /dev/null +++ b/.github/workflows/test-action.yml @@ -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