Skip to content

Commit

Permalink
Refactor GitHub workflows for better efficiency (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshLoecker authored Oct 3, 2023
1 parent e1d1afb commit 4f823a3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 50 deletions.
1 change: 0 additions & 1 deletion .github/workflows/container_build.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
name: Container Build
on:
workflow_dispatch:
push:
tags:
- "*"
Expand Down
28 changes: 4 additions & 24 deletions .github/workflows/type_checking.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ name: Python Type Checking

on:
pull_request:
types: [ opened, reopened, synchronize ]
types:
- opened
- reopened
- synchronize

jobs:
type-check:
Expand All @@ -16,40 +19,17 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

# Only execute this workflow if python files have changed
- name: Check for python changes
id: python-changes
run: |
python_changes=$(git diff --name-only ${{ github.event.before}} ${{ github.sha }} | grep '\.py$' | wc -l)
if [ "$python_changes" -eq "0" ]; then
echo "python-changed=false" >> $GITHUB_ENV
else
echo "python-changed=true" >> $GITHUB_ENV
fi
- name: Set Status Check Outcome
if: env.python-changed == 'true'
run: "echo 'Status check outcome: failure'"
continue-on-error: true

- name: Mark Status Check as Success
if: env.python-changed == 'true'
run: "echo 'Status check outcome: success'"

- name: Set up Python
uses: actions/setup-python@v4
if: env.python-changed == 'true'
with:
python-version: ${{ matrix.python-version }}

- name: Install mypy
if: env.python-changed == 'true'
run: |
python -m pip install --upgrade pip
python -m pip install mypy
- name: Type check with mypy
if: env.python-changed == 'true'
working-directory: $GITHUB_WORKSPACE/main
run: |
mypy --strict --ignore-missing-imports .
30 changes: 5 additions & 25 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
name: Unit Tests
on:
pull_request:
types: [ opened, reopened, synchronize ]
workflow_dispatch:
pull_request:
types:
- opened
- reopened
- synchronize


jobs:
Expand All @@ -18,37 +21,15 @@ jobs:
- name: Checkout Repository
uses: actions/checkout@v4

# Only execute this workflow if python files have changed
- name: Check for python changes
id: python-changes
run: |
python_changes=$(git diff --name-only ${{ github.event.before}} ${{ github.sha }} | grep '\.py$' | wc -l)
if [ "$python_changes" -eq "0" ]; then
echo "python-changed=false" >> $GITHUB_ENV
else
echo "python-changed=true" >> $GITHUB_ENV
fi
- name: Set Status Check Outcome
if: env.python-changed == 'true'
run: "echo 'Status check outcome: failure'"
continue-on-error: true

- name: Mark Status Check as Success
if: env.python-changed == 'true'
run: "echo 'Status check outcome: success'"

- name: Install Conda environment
uses: mamba-org/provision-with-micromamba@main
if: env.python-changed == 'true'
with:
environment-file: main/src/tests/environment.yaml
environment-name: como_tests
extra-specs: |
python=${{ matrix.python-version }}
- name: Lint with flake8
if: env.python-changed == 'true'
run: |
# Initialize micromamba and activate como_tests environment
eval "$(micromamba shell hook --shell=bash)" && micromamba activate como_tests
Expand All @@ -58,7 +39,6 @@ jobs:
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Run tests
if: env.python-changed == 'true'
run: |
# Initialize micromamba and activate como_tests environment
eval "$(micromamba shell hook --shell=bash)" && micromamba activate como_tests
Expand Down

0 comments on commit 4f823a3

Please sign in to comment.