Skip to content

Commit 4cb4770

Browse files
committed
test: clean up and improve the workflow & Makefile
1 parent cbcea56 commit 4cb4770

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

.github/workflows/pr-change-set.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ jobs:
2222
with:
2323
disable-pip-audit: ${{ vars.DISABLE_PIP_AUDIT == 'true' }}
2424

25-
test:
25+
verify_artifacts:
2626
needs: [build]
27-
name: test
27+
name: verify_artifacts
2828
runs-on: ubuntu-latest
2929
permissions:
3030
contents: read
@@ -35,6 +35,10 @@ jobs:
3535
with:
3636
fetch-depth: 0
3737

38+
# Download all uploaded artifacts in the build job into the 'downloads' directory.
39+
# This includes built package distributions and SHA256 hash files from all matrix jobs.
40+
# The `path` input ensures all artifacts are placed under the 'downloads/' folder while
41+
# maintaining their respective artifact subdirectory structure.
3842
- name: Download artifact
3943
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
4044
with:

Makefile

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,13 @@ SHELL := bash
77
PACKAGE_NAME := package
88
PACKAGE_VERSION := $(shell python -c $$'try: import $(PACKAGE_NAME); print($(PACKAGE_NAME).__version__, end="");\nexcept: print("unknown");')
99

10-
OS_NAME := "$(shell uname)"
11-
ifeq ($(OS_NAME), "Darwin")
12-
OS := darwin
13-
else
14-
ifeq ($(OS_NAME), "Linux")
15-
OS := linux
16-
endif
17-
endif
10+
# Determine the OS and architecture.
11+
OS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
12+
13+
ARCH := $(shell uname -m)
1814

19-
ARCH := $(shell echo `uname -m` | xargs)# E.g., arm64 or x86_64.
15+
# Construct full package identifier.
16+
PACKAGE_FULL_NAME := $(PACKAGE_NAME)-$(PACKAGE_VERSION)-$(OS)-$(ARCH)
2017

2118
# This variable contains the first goal that matches any of the listed goals
2219
# here, else it contains an empty string. The net effect is to filter out
@@ -118,7 +115,7 @@ upgrade-quiet:
118115
# Generate a Software Bill of Materials (SBOM).
119116
.PHONY: sbom
120117
sbom: requirements
121-
cyclonedx-py requirements --output-format json --outfile dist/$(PACKAGE_NAME)-$(PACKAGE_VERSION)-$(OS)-$(ARCH)-sbom.json
118+
cyclonedx-py requirements --output-format json --outfile dist/$(PACKAGE_FULL_NAME)-sbom.json
122119

123120
# Generate a requirements.txt file containing version and integrity hashes for all
124121
# packages currently installed in the virtual environment. There's no easy way to
@@ -140,14 +137,14 @@ requirements.txt: pyproject.toml
140137
[[ $$pkg =~ (.*)==(.*) ]] && curl -s https://pypi.org/pypi/$${BASH_REMATCH[1]}/$${BASH_REMATCH[2]}/json | python -c "import json, sys; print(''.join(f''' \\\\\n --hash=sha256:{pkg['digests']['sha256']}''' for pkg in json.load(sys.stdin)['urls']));" >> requirements.txt; \
141138
done
142139
echo -e -n "$(PACKAGE_NAME)==$(PACKAGE_VERSION)" >> requirements.txt
143-
if [ -f dist/$(PACKAGE_NAME)-$(PACKAGE_VERSION)-$(OS)-$(ARCH).tar.gz ]; then \
144-
echo -e -n " \\\\\n $$(python -m pip hash --algorithm sha256 dist/$(PACKAGE_NAME)-$(PACKAGE_VERSION)-$(OS)-$(ARCH).tar.gz | grep '^\-\-hash')" >> requirements.txt; \
140+
if [ -f dist/$(PACKAGE_FULL_NAME).tar.gz ]; then \
141+
echo -e -n " \\\\\n $$(python -m pip hash --algorithm sha256 dist/$(PACKAGE_FULL_NAME).tar.gz | grep '^\-\-hash')" >> requirements.txt; \
145142
fi
146143
if [ -f dist/$(PACKAGE_NAME)-$(PACKAGE_VERSION)-py3-$(OS)-$(ARCH).whl ]; then \
147144
echo -e -n " \\\\\n $$(python -m pip hash --algorithm sha256 dist/$(PACKAGE_NAME)-$(PACKAGE_VERSION)-py3-$(OS)-$(ARCH).whl | grep '^\-\-hash')" >> requirements.txt; \
148145
fi
149146
echo "" >> requirements.txt
150-
cp requirements.txt dist/$(PACKAGE_NAME)-$(PACKAGE_VERSION)-$(OS)-$(ARCH)-requirements.txt
147+
cp requirements.txt dist/$(PACKAGE_FULL_NAME)-requirements.txt
151148

152149
# Audit the currently installed packages. Skip packages that are installed in
153150
# editable mode (like the one in development here) because they may not have
@@ -186,19 +183,19 @@ test:
186183
# When building these artifacts, we need the environment variable SOURCE_DATE_EPOCH
187184
# set to the build date/epoch. For more details, see: https://flit.pypa.io/en/latest/reproducible.html
188185
.PHONY: dist
189-
dist: dist/$(PACKAGE_NAME)-$(PACKAGE_VERSION)-py3-none-any.whl dist/$(PACKAGE_NAME)-$(PACKAGE_VERSION).tar.gz dist/$(PACKAGE_NAME)-$(PACKAGE_VERSION)-docs-html.zip dist/$(PACKAGE_NAME)-$(PACKAGE_VERSION)-docs-md.zip dist/$(PACKAGE_NAME)-$(PACKAGE_VERSION)-$(OS)-$(ARCH)-build-epoch.txt
186+
dist: dist/$(PACKAGE_NAME)-$(PACKAGE_VERSION)-py3-none-any.whl dist/$(PACKAGE_NAME)-$(PACKAGE_VERSION).tar.gz dist/$(PACKAGE_NAME)-$(PACKAGE_VERSION)-docs-html.zip dist/$(PACKAGE_NAME)-$(PACKAGE_VERSION)-docs-md.zip dist/$(PACKAGE_FULL_NAME)-build-epoch.txt
190187
dist/$(PACKAGE_NAME)-$(PACKAGE_VERSION)-py3-none-any.whl:
191188
SOURCE_DATE_EPOCH=$(SOURCE_DATE_EPOCH) flit build --setup-py --format wheel
192189
mv dist/$(PACKAGE_NAME)-$(PACKAGE_VERSION)-py3-none-any.whl dist/$(PACKAGE_NAME)-$(PACKAGE_VERSION)-py3-$(OS)-$(ARCH).whl
193190
dist/$(PACKAGE_NAME)-$(PACKAGE_VERSION).tar.gz:
194191
SOURCE_DATE_EPOCH=$(SOURCE_DATE_EPOCH) flit build --setup-py --format sdist
195-
mv dist/$(PACKAGE_NAME)-$(PACKAGE_VERSION).tar.gz dist/$(PACKAGE_NAME)-$(PACKAGE_VERSION)-$(OS)-$(ARCH).tar.gz
192+
mv dist/$(PACKAGE_NAME)-$(PACKAGE_VERSION).tar.gz dist/$(PACKAGE_FULL_NAME).tar.gz
196193
dist/$(PACKAGE_NAME)-$(PACKAGE_VERSION)-docs-html.zip: docs-html
197194
python -m zipfile -c dist/$(PACKAGE_NAME)-$(PACKAGE_VERSION)-docs-html.zip docs/_build/html/
198195
dist/$(PACKAGE_NAME)-$(PACKAGE_VERSION)-docs-md.zip: docs-md
199196
python -m zipfile -c dist/$(PACKAGE_NAME)-$(PACKAGE_VERSION)-docs-md.zip docs/_build/markdown/
200-
dist/$(PACKAGE_NAME)-$(PACKAGE_VERSION)-$(OS)-$(ARCH)-build-epoch.txt:
201-
echo $(SOURCE_DATE_EPOCH) > dist/$(PACKAGE_NAME)-$(PACKAGE_VERSION)-$(OS)-$(ARCH)-build-epoch.txt
197+
dist/$(PACKAGE_FULL_NAME)-build-epoch.txt:
198+
echo $(SOURCE_DATE_EPOCH) > dist/$(PACKAGE_FULL_NAME)-build-epoch.txt
202199

203200
# Build the HTML and Markdown documentation from the package's source.
204201
DOCS_SOURCE := $(shell git ls-files docs/source)

0 commit comments

Comments
 (0)