Skip to content

Commit fd39a83

Browse files
committed
workflows: calculate artifact basenames in pre-commit job
Avoid redundant name calculations. Signed-off-by: Benjamin Gilbert <[email protected]>
1 parent d309ca3 commit fd39a83

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

.github/workflows/python.yml

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ jobs:
1717
pre-commit:
1818
name: Rerun pre-commit checks
1919
runs-on: ubuntu-latest
20+
outputs:
21+
dist-base: ${{ steps.paths.outputs.dist }}
22+
docs-base: ${{ steps.paths.outputs.docs }}
2023
steps:
2124
- name: Check out repo
2225
uses: actions/checkout@v4
@@ -26,6 +29,12 @@ jobs:
2629
python-version: '3.12'
2730
- name: Run pre-commit hooks
2831
uses: pre-commit/[email protected]
32+
- name: Define artifact paths
33+
id: paths
34+
run: |
35+
suffix="$GITHUB_RUN_NUMBER-$(echo $GITHUB_SHA | cut -c-10)"
36+
echo "dist=openslide-python-dist-$suffix" >> $GITHUB_OUTPUT
37+
echo "docs=openslide-python-docs-$suffix" >> $GITHUB_OUTPUT
2938
3039
tests:
3140
name: Tests
@@ -106,27 +115,25 @@ jobs:
106115
exit 1
107116
fi
108117
esac
109-
basename=openslide-python-dist-$GITHUB_RUN_NUMBER-$(echo $GITHUB_SHA | cut -c-10)
110-
mkdir -p "artifacts/${basename}"
111-
mv dist/* "artifacts/${basename}"
112-
echo "basename=${basename}" >> $GITHUB_ENV
118+
mkdir -p "artifacts/${{ needs.pre-commit.outputs.dist-base }}"
119+
mv dist/* "artifacts/${{ needs.pre-commit.outputs.dist-base }}"
113120
# save version-specific wheels and oldest abi3 wheel
114121
python -c 'import sys
115122
if sys.version_info < (3, 12): print("archive_wheel=1")' >> $GITHUB_ENV
116123
- name: Install
117-
run: pip install artifacts/${basename}/*.whl
124+
run: pip install artifacts/${{ needs.pre-commit.outputs.dist-base }}/*.whl
118125
- name: Run tests
119126
run: pytest -v
120127
- name: Tile slide
121128
run: python examples/deepzoom/deepzoom_tile.py --viewer -o tiled tests/fixtures/small.svs
122129
- name: Remove wheel from upload
123130
if: matrix.sdist && ! env.archive_wheel
124-
run: rm artifacts/$basename/*.whl
131+
run: rm artifacts/${{ needs.pre-commit.outputs.dist-base }}/*.whl
125132
- name: Archive dist
126133
if: matrix.sdist || env.archive_wheel
127134
uses: actions/upload-artifact@v3
128135
with:
129-
name: ${{ env.basename }}
136+
name: ${{ needs.pre-commit.outputs.dist-base }}
130137
path: artifacts
131138

132139
windows:
@@ -163,15 +170,13 @@ jobs:
163170
- name: Build wheel
164171
run: |
165172
python -m build -w
166-
basename=openslide-python-dist-$GITHUB_RUN_NUMBER-$(echo $GITHUB_SHA | cut -c-10)
167-
mkdir -p "artifacts/${basename}"
168-
mv dist/*.whl "artifacts/${basename}"
169-
echo "basename=${basename}" >> $GITHUB_ENV
173+
mkdir -p "artifacts/${{ needs.pre-commit.outputs.dist-base }}"
174+
mv dist/*.whl "artifacts/${{ needs.pre-commit.outputs.dist-base }}"
170175
# save version-specific wheels and oldest abi3 wheel
171176
python -c 'import sys
172177
if sys.version_info < (3, 12): print("archive_wheel=1")' >> $GITHUB_ENV
173178
- name: Install
174-
run: pip install artifacts/${basename}/*.whl
179+
run: pip install artifacts/${{ needs.pre-commit.outputs.dist-base }}/*.whl
175180
- name: Run tests
176181
# Reads OPENSLIDE_PATH
177182
run: pytest -v
@@ -188,7 +193,7 @@ jobs:
188193
if: env.archive_wheel
189194
uses: actions/upload-artifact@v3
190195
with:
191-
name: ${{ env.basename }}
196+
name: ${{ needs.pre-commit.outputs.dist-base }}
192197
path: artifacts
193198

194199
docs:
@@ -207,12 +212,9 @@ jobs:
207212
python -m pip install --upgrade pip
208213
pip install sphinx
209214
- name: Build
210-
run: |
211-
basename=openslide-python-docs-$GITHUB_RUN_NUMBER-$(echo $GITHUB_SHA | cut -c-10)
212-
sphinx-build -d doctrees doc artifact/${basename}
213-
echo "basename=${basename}" >> $GITHUB_ENV
215+
run: sphinx-build -d doctrees doc artifact/${{ needs.pre-commit.outputs.docs-base }}
214216
- name: Archive
215217
uses: actions/upload-artifact@v3
216218
with:
217-
name: ${{ env.basename }}
219+
name: ${{ needs.pre-commit.outputs.docs-base }}
218220
path: artifact

0 commit comments

Comments
 (0)