Skip to content

Commit 851aff6

Browse files
committed
Add test for update release assets script
1 parent 4348f8e commit 851aff6

File tree

4 files changed

+68
-1
lines changed

4 files changed

+68
-1
lines changed

.github/workflows/tooling-unit-tests.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,22 @@ jobs:
9696
- name: Run PyTest
9797
run: |
9898
pytest scripts/guideline_recategorization/recategorize_test.py
99+
100+
release-tests:
101+
name: Run release tests
102+
runs-on: ubuntu-22.04
103+
steps:
104+
- name: Checkout
105+
uses: actions/checkout@v2
106+
107+
- name: Install Python
108+
uses: actions/setup-python@v4
109+
with:
110+
python-version: "3.9"
111+
112+
- name: Install Python dependencies
113+
run: pip install -r scripts/release/requirements.txt
114+
115+
- name: Run PyTest
116+
run: |
117+
pytest scripts/release/update_release_assets.py

scripts/release/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
semantic-version==2.10.0
22
PyGithub==1.59.1
33
PyYAML==6.0.1
4-
GitPython==3.1.36
4+
GitPython==3.1.36
5+
pytest==7.4.3
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
version: 0.1.0
2+
3+
layout:
4+
hello-world.txt:
5+
- shell: |
6+
echo "hello world!" > hello-world.txt
7+
hello-world.zip:
8+
- shell: |
9+
echo "hello!" > hello.txt
10+
echo "world!" > world.txt
11+
# reset the creation and modification times to a fixed value
12+
touch -a -m -t 197001010000.00 hello.txt world.txt
13+
checksums.txt:
14+
- shell: |
15+
shasum -a 256 ${{ layout.root }}/* > checksums.txt
16+
# Remove the layout root from the checksums.txt
17+
sed -i '' -e "s|${{ layout.root }}/||g" checksums.txt
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from pathlib import Path
2+
from tempfile import TemporaryDirectory
3+
import yaml
4+
from update_release_assets import ReleaseLayout
5+
6+
SCRIPT_PATH = Path(__file__)
7+
TEST_DIR = SCRIPT_PATH.parent / 'test-data'
8+
9+
def test_release_layout():
10+
spec = TEST_DIR / 'release-layout.yml'
11+
release_layout = ReleaseLayout(spec)
12+
with TemporaryDirectory() as tmp_dir:
13+
tmp_path = Path(tmp_dir)
14+
release_layout.make(tmp_path, [])
15+
16+
for artifact in yaml.safe_load(spec.read_text())['layout'].keys():
17+
artifact_path = tmp_path / artifact
18+
assert artifact_path.is_file()
19+
20+
if artifact == "hello-world.txt":
21+
content = artifact_path.read_text()
22+
assert content == "hello world!\n"
23+
if artifact == "checksums.txt":
24+
content = artifact_path.read_text()
25+
# The hash of the hello-world.txt is deterministic, so we can assert it here.
26+
assert "ecf701f727d9e2d77c4aa49ac6fbbcc997278aca010bddeeb961c10cf54d435a hello-world.txt" in content
27+
# The has of the hello-world.zip is not deterministic, so we can't assert its hash.
28+
assert "hello-world.zip" in content
29+
30+

0 commit comments

Comments
 (0)