Skip to content

Commit

Permalink
Update workflows to get wheels built
Browse files Browse the repository at this point in the history
  • Loading branch information
dwoz committed Sep 3, 2024
1 parent e589e45 commit 5b66183
Show file tree
Hide file tree
Showing 8 changed files with 268 additions and 69 deletions.
97 changes: 96 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,37 @@ on:

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
Expand All @@ -44,5 +72,72 @@ jobs:
- pre-commit
with:
kind: "${{ inputs.kind }}"
cmd: "${{ inputs.package_command }}"
cmd: python -m build
#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 }}
110 changes: 46 additions & 64 deletions .github/workflows/package-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,80 +25,62 @@ on:
jobs:
build:
name: Build Python Wheel
strategy:
matrix:
host:
- x86_64
- aarch64
runs-on:
- self-hosted
- linux
- src-build
- ${{ matrix.host }}
runs-on: ubuntu-latest
container:
image: debian:11
outputs:
version: ${{ steps.version.outputs.version }}

steps:
- uses: actions/checkout@master
- uses: actions/checkout@master

# - name: Set up Python 3.10
# uses: actions/setup-python@v4
# with:
# python-version: "3.10"
- name: Update Apt
run: >-
apt-get update
- name: Install pypa/build
run: >-
python -m
pip install
build
--user
- name: Install OS Dependencies
run: >-
apt-get install -y gcc python3
python3-pip python3-venv flex make
texinfo unzip help2man gawk libtool-bin libncurses5-dev
bison wget rsync git
- name: Install pypa/pkginffo
run: >-
python -m
pip install
pkginfo
--user
- name: Create virtualenv
run: >-
python3 -m venv venv
- name: Install relenv
run: >-
python -m
pip install
relenv
--user
- name: Activate virtualenv
run: |
. venv/bin/activate
echo PATH=$PATH >> $GITHUB_ENV
- name: Install relenv toolchain
run: >-
python -m
relenv
toolchain
fetch
- name: Python Version
run: >-
python3 --version
- name: Install relenv fetch
run: >-
python -m
relenv
fetch
- name: Install Python Dependencies
run: >-
pip install build wheel setuptools pkginfo
- name: Echo Build Wheel Command
run: echo "${{ inputs.cmd }}"
- name: Echo Build Wheel Command
run: echo "${{ inputs.cmd }}"

- name: Build Wheel
run: "${{ inputs.cmd }}"
- name: Build Wheel
run: |
${{ inputs.cmd }}
- name: Wheel Artifact ${{matrix.host}}
uses: actions/upload-artifact@v3
if: always()
with:
name: relenv-gdb-debug-${{ matrix.host }}-wheel
path: dist/*.whl
retention-days: 5
- 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
- name: Read Version
run: >-
python3
-c
"from pkginfo import Wheel; s = Wheel('''$(ls dist/*.whl)'''); print('version='+str(s.version))"
>>
$GITHUB_OUTPUT
id: version
8 changes: 7 additions & 1 deletion .github/workflows/pre-commit-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_call:
inputs:
changed-files:
required: false
required: true
type: string
description: JSON string containing information about changed files

Expand All @@ -30,5 +30,11 @@ jobs:
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 }}
39 changes: 39 additions & 0 deletions .github/workflows/test-action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
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 pytest
- name: Run tests
run: |
pytest -v
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
requires = [
"setuptools",
"wheel",
"relenv@git+https://github.com/saltstack/relative-environment-for-python@buildenv",
"relenv",
]
build-backend = "build"
backend-path = ["src/relenv_gdb"]
Expand Down
Loading

0 comments on commit 5b66183

Please sign in to comment.