Skip to content

Commit

Permalink
Reusable workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
Spacetown committed Aug 14, 2024
1 parent b45621b commit 121cc05
Show file tree
Hide file tree
Showing 5 changed files with 282 additions and 251 deletions.
35 changes: 35 additions & 0 deletions .github/actions/setup-python/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Set up python
# Schema: https://json.schemastore.org/github-action.json

inputs:
os:
type: string
description: 'The operating system of the runner'
required: true
python-version:
type: string
description: 'The Python version to use'
required: true

runs:
using: 'composite'
steps:
- name: Set up Python ${{ inputs.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}

- name: Get pip cache dir
id: pip-cache
run: |
echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT
shell: bash

- name: Cache pip
uses: actions/cache@v4
with:
path: ${{ steps.pip-cache.outputs.dir }}
# Look to see if there is a cache hit for the corresponding requirements file
key: ${{ inputs.os }}-python${{ inputs.python-version }}-pip-${{ hashFiles('noxfile.py', 'doc/requirements.txt') }}
restore-keys: |
${{ inputs.os }}-python${{ inputs.python-version }}-pip
50 changes: 50 additions & 0 deletions .github/actions/setup-runner/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Set up runner
# Schema: https://json.schemastore.org/github-action.json

inputs:
os:
type: string
description: 'The operating system of the runner'
required: true
gcc:
type: string
description: 'The GCC version to use'
required: true

runs:
using: 'composite'
steps:
- name: Install build commands, GCC and libxml2 (Linux)
if: ${{ startsWith(inputs.os,'ubuntu-') }}
shell: bash
run: |
sudo apt update
sudo apt-get install -y \
make \
ninja-build \
${{ inputs.gcc }} \
$(echo ${{ inputs.gcc }} | sed -e 's/gcc/g\+\+/') \
libxml2-utils
- name: Install msys with GCC (Windows)
if: ${{ startsWith(inputs.os,'windows-') }}
uses: msys2/setup-msys2@v2
with:
install: gcc make
cache: true

- name: Install ninja (Windows)
if: ${{ startsWith(inputs.os,'windows-') }}
shell: bash
run: |
choco install ninja
- name: Install ninja and libxml2 (MacOs)
if: ${{ startsWith(inputs.os,'macos-') }}
shell: bash
run: |
export HOMEBREW_NO_AUTO_UPDATE=1
export HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK=1
brew update
brew install ninja
brew install libxml2
44 changes: 20 additions & 24 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,42 +44,32 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5

- name: Set up runner
uses: "./.github/actions/setup-runner"
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Cache pip
uses: actions/cache@v4
os: 'ubuntu-22.04'
gcc: ${{ env.CC }}

- name: Set up python
uses: "./.github/actions/setup-python"
with:
# This path is specific to Ubuntu
path: ~/.cache/pip
# Look to see if there is a cache hit for the corresponding requirements file
key: ${{ runner.os }}-pip-${{ hashFiles('noxfile.py', 'doc/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install build commands and GCC
run: |
sudo apt update
sudo apt-get install -y \
make \
ninja-build \
$CC \
$(echo $CC | sed -e 's/gcc/g\+\+/')
sudo apt-get clean
- name: Install libxml2
run: |
sudo apt-get install -y libxml2-utils
sudo apt-get clean
os: 'ubuntu-22.04'
python-version: ${{ env.PYTHON_VERSION }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install nox requests
- name: Lint files
run: |
nox --non-interactive --session lint
- name: Test with pytest
run: |
nox --non-interactive --session tests
- name: Generate documentation
run: |
nox --non-interactive --session doc
Expand All @@ -94,21 +84,26 @@ jobs:
exit 1
fi
exit 0
- name: Test bundle of app
run: |
nox --non-interactive --session bundle_app
- name: Build wheel
run: |
nox --non-interactive --session build_wheel
- name: Check wheel
run: |
nox --non-interactive --session check_wheel
- name: Upload distribution
if: ${{ success() }}
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/**

- name: Apply new tag if version is bumped
if: ${{ success() && (github.event.ref == 'refs/heads/main') }}
run: |
Expand Down Expand Up @@ -138,6 +133,7 @@ jobs:
echo "Skip pushing tag for development build"
echo "TAG_PUSHED=false" >> $GITHUB_ENV
fi
- name: Publish
if: ${{ success() && (github.event.ref == 'refs/heads/main') && (env.TAG_PUSHED == 'true') }}
env:
Expand Down
156 changes: 156 additions & 0 deletions .github/workflows/job.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
name: Run gcovr CI job
# Schema: https://json.schemastore.org/github-action.json

on:
workflow_call:
inputs:
container:
type: boolean
description: 'Running in docker container'
default: false
os:
type: string
description: 'The operating system of the runner'
default: 'ubuntu-22.04' # Default used for container
gcc:
type: string
description: 'The GCC version to use'
required: true
python-version:
type: string
description: 'The Python version to use'
required: false # Only needed if not in container
upload-app:
type: boolean
description: 'Upload the standalone application'
default: false

defaults:
run:
shell: bash

jobs:
gcovr-ci-job:
runs-on: ${{ inputs.container && 'ubuntu-22.04' || inputs.os }}
env:
FORCE_COLOR: "1"
timeout-minutes: 10
steps:
- uses: actions/checkout@v4

- name: Set up runner
if: ${{ !inputs.container }}
uses: "./.github/actions/setup-runner"
with:
os: ${{ inputs.os}}
gcc: ${{ inputs.gcc }}

- name: Set up python
if: ${{ !inputs.container }}
uses: "./.github/actions/setup-python"
with:
os: ${{ inputs.os }}
python-version: ${{ inputs.python-version }}

- name: Set up environment
run: |
# Enable coverage for specific target configurations
if [ "${{ inputs.container }}" == "true" ] ; then
case "${{ inputs.gcc }}" in
gcc-5) USE_COVERAGE=true ;;
gcc-14) USE_COVERAGE=true ;;
clang-10) USE_COVERAGE=true ;;
clang-15) USE_COVERAGE=true ;;
*) USE_COVERAGE=false ;;
esac
else
case "${{ inputs.os }}/${{ inputs.gcc }}/${{ inputs.python-version }}" in
ubuntu-22.04/gcc-11/3.11) USE_COVERAGE=true ;;
windows-2019/gcc-8/3.12) USE_COVERAGE=true ;;
macos-14/gcc/3.9) USE_COVERAGE=true ;;
macos-14/gcc-13/3.12) USE_COVERAGE=true ;;
*) USE_COVERAGE=false ;;
esac
fi
echo "USE_COVERAGE=$USE_COVERAGE" >> $GITHUB_ENV
# Set the CC environment
echo "CC=${{ inputs.gcc }}" >> $GITHUB_ENV
- name: Expose GitHub Runtime for Docker cache
uses: crazy-max/ghaction-github-runtime@v3

- name: Install dependencies
run: |
python3 -m pip install --upgrade pip
python3 -m pip install nox requests
- name: Build Docker
if: ${{ inputs.container }}
run: |
nox --non-interactive --session "docker_build_compiler(${{ inputs.gcc }})"
- name: Lint files
run: |
nox --non-interactive${{ inputs.container && format(' --session "docker_run_compiler({0})" --', inputs.gcc) || '' }} --session lint
- name: Test with pytest
run: |
nox --non-interactive${{ inputs.container && format(' --session "docker_run_compiler({0})" --', inputs.gcc) || '' }} --session tests -- --archive_differences
- name: Upload pytest test results
if: ${{ failure() }}
uses: actions/upload-artifact@v4
with:
name: "diffs-${{ inputs.container && format('docker-{0}', inputs.gcc) || format('{0}-{1}-{2}', inputs.os, inputs.gcc, inputs.python-version) }}"
path: tests/diff.zip

- name: Upload coverage to Codecov
if: ${{ (github.repository == 'gcovr/gcovr') && (env.USE_COVERAGE) }}
uses: codecov/codecov-action@v4
with:
env_vars: OS,PYTHON
fail_ci_if_error: true
disable_search: true
plugins: pycoverage
files: ./coverage.xml${{ inputs.container && ((inputs.gcc == 'gcc-5') || (inputs.gcc == 'clang-10')) && format(',./tests/nested/reference/{0}/coverage.lcov', inputs.gcc) || '' }}
name: "${{ inputs.container && 'docker' || inputs.os }}-${{ inputs.gcc }}"
verbose: true
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

- name: Generate documentation
if: ${{ (!inputs.container && (! startsWith(inputs.python-version,'pypy')) && (! startsWith(inputs.os,'windows-')) && (inputs.python-version != '3.8')) || (inputs.container && (inputs.gcc != 'gcc-5') && (inputs.gcc != 'gcc-6') && (inputs.gcc != 'gcc-8') && (inputs.gcc != 'gcc-9') && (inputs.gcc != 'clang-10')) }}
run: |
nox --non-interactive ${{ inputs.container && format(' --session "docker_run_compiler({0})" --', inputs.gcc) || '' }} --session doc || exit 1
# Check if files are modified (outdated screenshots)
Status=$(git status --porcelain | grep -F '.jpeg' || exit 0)
if [ -n "$Status" ] ; then
echo "Following files are modified:"
echo "$Status"
echo "Please regenerate the screenshots!"
exit 1
fi
exit 0
- name: Test bundle of app
if: ${{ (!inputs.container && !startsWith(inputs.python-version,'pypy')) || (inputs.container && (inputs.gcc != 'gcc-5') && (inputs.gcc != 'gcc-6')) }}
run: |
nox --non-interactive${{ inputs.container && format(' --session "docker_run_compiler({0})" --', inputs.gcc) || '' }} --session bundle_app
- name: Upload app bundle artifacts
if: ${{ inputs.upload-app == true }}
uses: actions/upload-artifact@v4
with:
name: app-${{ inputs.os }}
path: artifacts/gcovr*

- name: Build wheel
run: |
nox --non-interactive${{ inputs.container && format(' --session "docker_run_compiler({0})" --', inputs.gcc) || '' }} --session build_wheel
- name: Check wheel
run: |
nox --non-interactive${{ inputs.container && format(' --session "docker_run_compiler({0})" --', inputs.gcc) || '' }} --session check_wheel
Loading

0 comments on commit 121cc05

Please sign in to comment.