Skip to content

Commit 6e44b71

Browse files
authored
Make package name part of contents header (#169)
* Make package name part of contents header * add changelog
1 parent 296c432 commit 6e44b71

File tree

2 files changed

+52
-41
lines changed

2 files changed

+52
-41
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1212
- New output: `package_name` is the name of the built package as stored in metadata.
1313
[#162](https://github.com/hynek/build-and-inspect-python-package/pull/162)
1414

15+
- The package name is now part of the action summary which is helpful when you build more than one package from a repository.
16+
[#169](https://github.com/hynek/build-and-inspect-python-package/pull/169)
17+
1518

1619
### Changed
1720

action.yml

Lines changed: 49 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,6 @@ runs:
141141
with:
142142
subject-path: "/tmp/baipp/dist/*"
143143

144-
- name: Add contents header
145-
shell: bash
146-
run: echo -e '\n### Package Contents' >> $GITHUB_STEP_SUMMARY
147-
148144
- name: Set output
149145
id: dist-location-setter
150146
shell: bash
@@ -178,34 +174,74 @@ runs:
178174
--strict
179175
/tmp/baipp/dist/*
180176
181-
- name: Show package contents hierarchically, including metadata.
182-
shell: bash
177+
- name: Extract built package
183178
working-directory: ${{ inputs.path }}
179+
shell: bash
184180
run: |
185181
cd /tmp/baipp/dist
186182
mkdir -p out/sdist
187183
tar xf *.tar.gz -C out/sdist
188184
185+
if [[ "${{ inputs.skip-wheel }}" != 'true' ]]; then
186+
mkdir -p out/wheels
187+
/tmp/baipp/bin/python -m wheel unpack --dest out/wheels *.whl
188+
fi
189+
190+
- name: Extract packaging metadata
191+
id: metadata-setter
192+
shell: bash
193+
working-directory: /tmp/baipp/dist/out/sdist/
194+
run: |
195+
cat */PKG-INFO | python -c '
196+
import email.parser
197+
import json, pathlib, re, sys
198+
199+
pkg_info = email.parser.Parser().parsestr(sys.stdin.read())
200+
201+
version_tokens = []
202+
for classifier in pkg_info.get_all("Classifier", []):
203+
if match := re.match(r"Programming Language :: Python :: (\d+\.\d+)$", classifier):
204+
version_tokens.append(match.group(1))
205+
206+
package_name = pkg_info.get("Name")
207+
if package_name is None:
208+
raise RuntimeError("Package name is not set")
209+
210+
pathlib.Path("package_name.txt").write_text(package_name)
211+
212+
package_version = pkg_info.get("Version", "0.0.0")
213+
214+
print(f"package_name={package_name}")
215+
print(f"package_version={package_version}")
216+
print(f"supported_python_classifiers_json_array={json.dumps(version_tokens)}")
217+
print(f"""supported_python_classifiers_json_job_matrix_value={json.dumps({"python-version": version_tokens})}""")
218+
' >> $GITHUB_OUTPUT
219+
220+
echo -e "\n### Contents of the <code>$(cat package_name.txt)</code> package" >> $GITHUB_STEP_SUMMARY
221+
rm -f package_name.txt
222+
223+
224+
- name: Show package contents hierarchically, including metadata.
225+
working-directory: /tmp/baipp/dist/out/sdist/
226+
shell: bash
227+
run: |
189228
if ! command -v tree &> /dev/null; then
190229
sudo apt-get install tree
191230
fi
192231
193232
echo -e '\n<details><summary>SDist contents</summary>\n' >> $GITHUB_STEP_SUMMARY
194-
(cd /tmp/baipp/dist/out/sdist && tree -Da --timefmt="%Y-%m-%dT%H:%M:%SZ" * | sed 's/^/ /' | tee -a $GITHUB_STEP_SUMMARY)
233+
tree -Da --timefmt="%Y-%m-%dT%H:%M:%SZ" * | sed 's/^/ /' | tee -a $GITHUB_STEP_SUMMARY
195234
echo -e '\n</details>\n' >> $GITHUB_STEP_SUMMARY
196235
197-
if [[ "${{ inputs.skip-wheel }}" != 'true' ]]; then
198-
mkdir -p out/wheels
199-
/tmp/baipp/bin/python -m wheel unpack --dest out/wheels *.whl
200-
236+
if [ -d "../wheels" ]; then
201237
echo -e '\n<details><summary>Wheel contents</summary>\n' >> $GITHUB_STEP_SUMMARY
202-
(cd /tmp/baipp/dist/out/wheels && tree -a * | sed 's/^/ /' | tee -a $GITHUB_STEP_SUMMARY)
238+
(cd ../wheels && tree -a * | sed 's/^/ /' | tee -a $GITHUB_STEP_SUMMARY)
203239
echo -e '\n</details>\n' >> $GITHUB_STEP_SUMMARY
204240
fi
205241
206242
echo ----- Metadata Follows -----
207243
echo -e '\n<details><summary>Metadata</summary>\n' >> $GITHUB_STEP_SUMMARY
208-
cat out/sdist/*/PKG-INFO | sed 's/^/ /' | tee -a $GITHUB_STEP_SUMMARY
244+
cat */PKG-INFO | sed 's/^/ /' | tee -a $GITHUB_STEP_SUMMARY
209245
echo -e '\n</details>\n' >> $GITHUB_STEP_SUMMARY
210246
echo ----- End of Metadata -----
211247
@@ -237,31 +273,3 @@ runs:
237273
with:
238274
name: PyPI README${{ inputs.upload-name-suffix }}
239275
path: /tmp/baipp/dist/out/sdist/PyPI-README.*
240-
241-
- name: Generate JSON objects of supported Python versions
242-
id: metadata-setter
243-
shell: bash
244-
working-directory: /tmp/baipp/dist/out/sdist/
245-
run: |
246-
cat */PKG-INFO | python -c '
247-
import email.parser
248-
import json, re, sys
249-
250-
pkg_info = email.parser.Parser().parsestr(sys.stdin.read())
251-
252-
version_tokens = []
253-
for classifier in pkg_info.get_all("Classifier", []):
254-
if match := re.match(r"Programming Language :: Python :: (\d+\.\d+)$", classifier):
255-
version_tokens.append(match.group(1))
256-
257-
package_name = pkg_info.get("Name")
258-
if package_name is None:
259-
raise RuntimeError("Package name is not set")
260-
261-
package_version = pkg_info.get("Version", "0.0.0")
262-
263-
print(f"package_name={package_name}")
264-
print(f"package_version={package_version}")
265-
print(f"supported_python_classifiers_json_array={json.dumps(version_tokens)}")
266-
print(f"""supported_python_classifiers_json_job_matrix_value={json.dumps({"python-version": version_tokens})}""")
267-
' >> $GITHUB_OUTPUT

0 commit comments

Comments
 (0)