Skip to content

Commit

Permalink
workflows: calculate artifact basenames in pre-commit job
Browse files Browse the repository at this point in the history
Avoid redundant name calculations.

Signed-off-by: Benjamin Gilbert <[email protected]>
  • Loading branch information
bgilbert committed Nov 18, 2023
1 parent 5fc5833 commit be22f90
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ jobs:
pre-commit:
name: Rerun pre-commit checks
runs-on: ubuntu-latest
outputs:
dist-base: ${{ steps.paths.outputs.dist }}
docs-base: ${{ steps.paths.outputs.docs }}
steps:
- name: Check out repo
uses: actions/checkout@v4
Expand All @@ -26,6 +29,11 @@ jobs:
python-version: '3.12'
- name: Run pre-commit hooks
uses: pre-commit/[email protected]
- name: Define artifact paths
run: |
suffix="$GITHUB_RUN_NUMBER-$(echo $GITHUB_SHA | cut -c-10)"
echo "dist=openslide-python-dist-$suffix" >> $GITHUB_OUTPUT
echo "docs=openslide-python-docs-$suffix" >> $GITHUB_OUTPUT
tests:
name: Tests
Expand Down Expand Up @@ -106,27 +114,25 @@ jobs:
exit 1
fi
esac
basename=openslide-python-dist-$GITHUB_RUN_NUMBER-$(echo $GITHUB_SHA | cut -c-10)
mkdir -p "artifacts/${basename}"
mv dist/* "artifacts/${basename}"
echo "basename=${basename}" >> $GITHUB_ENV
mkdir -p "artifacts/${{ needs.pre-commit.outputs.dist-base }}"
mv dist/* "artifacts/${{ needs.pre-commit.outputs.dist-base }}"
# save version-specific wheels and oldest abi3 wheel
python -c 'import sys
if sys.version_info < (3, 12): print("archive_wheel=1")' >> $GITHUB_ENV
- name: Install
run: pip install artifacts/${basename}/*.whl
run: pip install artifacts/${{ needs.pre-commit.outputs.dist-base }}/*.whl
- name: Run tests
run: pytest -v
- name: Tile slide
run: python examples/deepzoom/deepzoom_tile.py --viewer -o tiled tests/fixtures/small.svs
- name: Remove wheel from upload
if: matrix.sdist && ! env.archive_wheel
run: rm artifacts/$basename/*.whl
run: rm artifacts/${{ needs.pre-commit.outputs.dist-base }}/*.whl
- name: Archive dist
if: matrix.sdist || env.archive_wheel
uses: actions/upload-artifact@v3
with:
name: ${{ env.basename }}
name: ${{ needs.pre-commit.outputs.dist-base }}
path: artifacts

windows:
Expand Down Expand Up @@ -163,15 +169,13 @@ jobs:
- name: Build wheel
run: |
python -m build -w
basename=openslide-python-dist-$GITHUB_RUN_NUMBER-$(echo $GITHUB_SHA | cut -c-10)
mkdir -p "artifacts/${basename}"
mv dist/*.whl "artifacts/${basename}"
echo "basename=${basename}" >> $GITHUB_ENV
mkdir -p "artifacts/${{ needs.pre-commit.outputs.dist-base }}"
mv dist/*.whl "artifacts/${{ needs.pre-commit.outputs.dist-base }}"
# save version-specific wheels and oldest abi3 wheel
python -c 'import sys
if sys.version_info < (3, 12): print("archive_wheel=1")' >> $GITHUB_ENV
- name: Install
run: pip install artifacts/${basename}/*.whl
run: pip install artifacts/${{ needs.pre-commit.outputs.dist-base }}/*.whl
- name: Run tests
# Reads OPENSLIDE_PATH
run: pytest -v
Expand All @@ -188,7 +192,7 @@ jobs:
if: env.archive_wheel
uses: actions/upload-artifact@v3
with:
name: ${{ env.basename }}
name: ${{ needs.pre-commit.outputs.dist-base }}
path: artifacts

docs:
Expand All @@ -207,12 +211,9 @@ jobs:
python -m pip install --upgrade pip
pip install sphinx
- name: Build
run: |
basename=openslide-python-docs-$GITHUB_RUN_NUMBER-$(echo $GITHUB_SHA | cut -c-10)
sphinx-build -d doctrees doc artifact/${basename}
echo "basename=${basename}" >> $GITHUB_ENV
run: sphinx-build -d doctrees doc artifact/${{ needs.pre-commit.outputs.docs-base }}
- name: Archive
uses: actions/upload-artifact@v3
with:
name: ${{ env.basename }}
name: ${{ needs.pre-commit.outputs.docs-base }}
path: artifact

0 comments on commit be22f90

Please sign in to comment.