Skip to content

Commit 7302439

Browse files
authored
Merge pull request #4 from kurtmckee/release-0.2
Release 0.2
2 parents 8df6c6b + b005d5e commit 7302439

File tree

5 files changed

+79
-73
lines changed

5 files changed

+79
-73
lines changed

.github/workflows/tox.yaml

+38-43
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
validate-config:
1717
name: "Validate config"
1818
outputs:
19-
config: "${{ steps.config-exporter.outputs.config }}"
19+
config: "${{ steps.config-transformer.outputs.config }}"
2020
runs-on: "ubuntu-latest"
2121
steps:
2222
- name: "Setup Python"
@@ -26,38 +26,12 @@ jobs:
2626

2727
- name: "Export config"
2828
id: "config-exporter"
29-
shell: "python"
30-
# Loading the workflow input from an environment variable
31-
# avoids injection attacks and allows for more robust validation.
29+
shell: "bash"
30+
# Loading the input from an environment variable avoids injection attacks.
3231
env:
3332
inputs_config: "${{ inputs.config }}"
3433
run: |
35-
# START: tox-config-writer.py
36-
import json
37-
import os
38-
import sys
39-
40-
try:
41-
config_string = os.environ["inputs_config"] # KeyError
42-
config = json.loads(config_string) # json.JSONDecodeError
43-
if not isinstance(config, dict):
44-
raise TypeError
45-
except KeyError:
46-
print("The 'inputs_config' key wasn't found in the environment")
47-
except json.JSONDecodeError:
48-
print("The config input couldn't be decoded as valid JSON")
49-
except TypeError:
50-
print("The config isn't a JSON object")
51-
else:
52-
output = json.dumps(config, sort_keys=True, separators=(",", ":"))
53-
with open("config.json", "w") as file:
54-
file.write(output)
55-
with open(os.environ["GITHUB_OUTPUT"], "a") as file:
56-
file.write(f"config={output}")
57-
sys.exit(0)
58-
59-
sys.exit(1)
60-
# END: tox-config-writer.py
34+
echo "$inputs_config" > config.json
6135
6236
# If a previous workflow run successfully validated an identical config object,
6337
# a cache hit is sufficient to demonstrate that no further validation is required.
@@ -212,6 +186,36 @@ jobs:
212186
pip install --user check-jsonschema
213187
check-jsonschema --schemafile schema.json config.json
214188
189+
- name: "Transform config"
190+
id: "config-transformer"
191+
shell: "python"
192+
run: |
193+
# START: tox-config-transformer.py
194+
import json
195+
import os
196+
197+
with open("config.json") as file:
198+
config = json.load(file)
199+
200+
# Transform the tox environments for convenience.
201+
# "pre-environments" and "post-environments" will be injected into "environments",
202+
# together with a full list of CPython and PyPy interpreter versions.
203+
# Since these keys are mutually-exclusive with "environments",
204+
# no config data are lost in this transformation.
205+
if {"pre-environments", "post-environments"} & config.get("tox", {}).keys():
206+
environments = config["tox"].pop("pre-environments", [])
207+
environments.extend(f"py{version}" for version in config.get("cpythons", []))
208+
if "cpython-beta" in config:
209+
environments.append(f"py{config['cpython-beta']}")
210+
environments.extend(f"pypy{version}" for version in config.get("pypys", []))
211+
environments.extend(config["tox"].pop("post-environments", []))
212+
config["tox"]["environments"] = environments
213+
214+
output = json.dumps(config, sort_keys=True, separators=(",", ":"))
215+
with open(os.environ["GITHUB_OUTPUT"], "a") as file:
216+
file.write(f"config={output}")
217+
# END: tox-config-transformer.py
218+
215219
tox:
216220
needs:
217221
- "validate-config"
@@ -229,11 +233,12 @@ jobs:
229233
run: |
230234
# shellcheck disable=SC2086
231235
for pattern in $FILE_PATTERNS; do
232-
if ! md5sum $pattern >> '.hash-files.md5'; then
236+
if ! ${{ runner.os == 'macOS' && 'shasum -a 1' || 'sha1sum' }} $pattern >> '.hash-files.sha'; then
233237
echo "The cache.hash-files pattern '$pattern' matched nothing"
234238
exit 1
235239
fi
236240
done
241+
cat .hash-files.sha
237242
238243
- name: "Setup Pythons"
239244
uses: "actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d" # v5.1.0
@@ -275,7 +280,7 @@ jobs:
275280
.tox/
276281
.venv/
277282
${{ fromJSON(inputs.config).cache.paths && join(fromJSON(inputs.config).cache.paths, '\n') }}
278-
key: "${{ fromJSON(inputs.config).cache.name || 'tox' }}-os=${{ fromJSON(inputs.config).runner }}-hash=${{ hashFiles('.python-identifiers', '.workflow-config.json', 'tox.ini', fromJSON(inputs.config).cache.key.hash-files && '.hash-files.md5') }}"
283+
key: "${{ fromJSON(inputs.config).cache.name || 'tox' }}-os=${{ fromJSON(inputs.config).runner }}-hash=${{ hashFiles('.python-identifiers', '.workflow-config.json', 'tox.ini', fromJSON(inputs.config).cache.key.hash-files && '.hash-files.sha') }}"
279284

280285
- name: "Identify .venv path"
281286
shell: "bash"
@@ -289,16 +294,6 @@ jobs:
289294
${{ env.venv-path }}/python -m pip install --upgrade pip setuptools wheel
290295
${{ env.venv-path }}/pip install tox
291296
292-
- name: "Prepare the tox environment list to run (specific list)"
293-
if: "fromJSON(inputs.config).tox.environments"
294-
run: |
295-
echo "tox_environments=${{ join(fromJSON(inputs.config).tox.environments, ',') }}" >> "$GITHUB_ENV"
296-
297-
- name: "Prepare the tox environment list to run (prefix/postfix)"
298-
if: "fromJSON(inputs.config).tox.pre-environments || fromJSON(inputs.config).tox.post-environments"
299-
run: |
300-
echo "tox_environments=${{ join(fromJSON(inputs.config).tox.environments, ',') }}" >> "$GITHUB_ENV"
301-
302297
- name: "Run the test suite"
303298
run: |
304-
${{ env.venv-path }}/tox run --colored yes ${{ env.tox_environments && format('-e "{0}"', env.tox_environments) }}
299+
${{ env.venv-path }}/tox run --colored yes ${{ fromJSON(needs.validate-config.outputs.config).tox.environments && format('-e "{0}"', join(fromJSON(needs.validate-config.outputs.config).tox.environments, ',')) }}

CHANGELOG.rst

+12
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ in the ``changelog.d/`` directory on GitHub.
1717

1818
.. scriv-insert-here
1919
20+
.. _changelog-0.2:
21+
22+
0.2 — 2024-05-10
23+
================
24+
25+
Fixed
26+
-----
27+
28+
* Fix ``tox.pre-environments`` and ``tox.post-environments``, which were ignored.
29+
* Fix ``cache.hash-files`` checksum calculations,
30+
which relied on a command that's unavailable on macOS.
31+
2032
.. _changelog-0.1:
2133

2234
0.1 — 2024-05-09

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tool.scriv]
2-
version = "0.1"
2+
version = "0.2"
33
categories = [
44
"Python support",
55
"Added",

src/tox-config-transformer.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# This file is a part of Kurt McKee's GitHub Workflows project.
2+
# https://github.com/kurtmckee/github-workflows
3+
# Copyright 2024 Kurt McKee <[email protected]>
4+
# SPDX-License-Identifier: MIT
5+
6+
import json
7+
import os
8+
9+
with open("config.json") as file:
10+
config = json.load(file)
11+
12+
# Transform the tox environments for convenience.
13+
# "pre-environments" and "post-environments" will be injected into "environments",
14+
# together with a full list of CPython and PyPy interpreter versions.
15+
# Since these keys are mutually-exclusive with "environments",
16+
# no config data are lost in this transformation.
17+
if {"pre-environments", "post-environments"} & config.get("tox", {}).keys():
18+
environments = config["tox"].pop("pre-environments", [])
19+
environments.extend(f"py{version}" for version in config.get("cpythons", []))
20+
if "cpython-beta" in config:
21+
environments.append(f"py{config['cpython-beta']}")
22+
environments.extend(f"pypy{version}" for version in config.get("pypys", []))
23+
environments.extend(config["tox"].pop("post-environments", []))
24+
config["tox"]["environments"] = environments
25+
26+
output = json.dumps(config, sort_keys=True, separators=(",", ":"))
27+
with open(os.environ["GITHUB_OUTPUT"], "a") as file:
28+
file.write(f"config={output}")

src/tox-config-writer.py

-29
This file was deleted.

0 commit comments

Comments
 (0)