Skip to content

Commit

Permalink
Check cache hash is up-to-date in unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
EnricoMi committed Mar 16, 2023
1 parent bb61605 commit d5f8056
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions python/test/test_action_yml.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import hashlib
import pathlib
import unittest

Expand Down Expand Up @@ -28,6 +29,15 @@ def test_composite_action(self):
self.assertEqual(dockerfile_action_wo_runs, composite_action_wo_runs)
self.assertIn(('using', 'composite'), composite_action.get('runs', {}).items())

# check cache key hash is up-to-date in composite action
with open(project_root / 'python' / 'requirements.txt', mode='rb') as r:
expected_hash = hashlib.md5(r.read()).hexdigest()
cache_hash = next(step.get('with', {}).get('key', '').split('-')[-1]
for step in composite_action.get('runs', {}).get('steps', [])
if step.get('uses', '').startswith('actions/cache/restore@'))
self.assertEqual(expected_hash, cache_hash, msg='Changing python/requirements.txt requires '
'to update the MD5 hash in composite/action.yaml')

def test_composite_inputs(self):
with open(project_root / 'composite/action.yml', encoding='utf-8') as r:
action = yaml.safe_load(r)
Expand Down

0 comments on commit d5f8056

Please sign in to comment.