Skip to content

Commit

Permalink
Add test for update release assets script
Browse files Browse the repository at this point in the history
  • Loading branch information
rvermeulen committed Nov 23, 2023
1 parent 4348f8e commit 552a7b6
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
19 changes: 19 additions & 0 deletions .github/workflows/tooling-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,22 @@ jobs:
- name: Run PyTest
run: |
pytest scripts/guideline_recategorization/recategorize_test.py
release-tests:
name: Run release tests
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install Python
uses: actions/setup-python@v4
with:
python-version: "3.9"

- name: Install Python dependencies
run: pip install -r scripts/release/requirements.txt

- name: Run PyTest
run: |
pytest scripts/release/update_release_assets_test.py
3 changes: 2 additions & 1 deletion scripts/release/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
semantic-version==2.10.0
PyGithub==1.59.1
PyYAML==6.0.1
GitPython==3.1.36
GitPython==3.1.36
pytest==7.4.3
17 changes: 17 additions & 0 deletions scripts/release/test-data/release-layout.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: 0.1.0

layout:
hello-world.txt:
- shell: |
echo "hello world!" > hello-world.txt
hello-world.zip:
- shell: |
echo "hello!" > hello.txt
echo "world!" > world.txt
# reset the creation and modification times to a fixed value
touch -a -m -t 197001010000.00 hello.txt world.txt
checksums.txt:
- shell: |
shasum -a 256 ${{ layout.root }}/* > checksums.txt
# Remove the layout root from the checksums.txt
sed -i '' -e "s|${{ layout.root }}/||g" checksums.txt
30 changes: 30 additions & 0 deletions scripts/release/update_release_assets_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from pathlib import Path
from tempfile import TemporaryDirectory
import yaml
from update_release_assets import ReleaseLayout

SCRIPT_PATH = Path(__file__)
TEST_DIR = SCRIPT_PATH.parent / 'test-data'

def test_release_layout():
spec = TEST_DIR / 'release-layout.yml'
release_layout = ReleaseLayout(spec)
with TemporaryDirectory() as tmp_dir:
tmp_path = Path(tmp_dir)
release_layout.make(tmp_path, [])

for artifact in yaml.safe_load(spec.read_text())['layout'].keys():
artifact_path = tmp_path / artifact
assert artifact_path.is_file()

if artifact == "hello-world.txt":
content = artifact_path.read_text()
assert content == "hello world!\n"
if artifact == "checksums.txt":
content = artifact_path.read_text()
# The hash of the hello-world.txt is deterministic, so we can assert it here.
assert "ecf701f727d9e2d77c4aa49ac6fbbcc997278aca010bddeeb961c10cf54d435a hello-world.txt" in content
# The has of the hello-world.zip is not deterministic, so we can't assert its hash.
assert "hello-world.zip" in content


0 comments on commit 552a7b6

Please sign in to comment.