mirror of
https://github.com/storytold/craft-common-actions.git
synced 2026-11-21 23:53:02 +00:00
13f14e1788
GitHub's Ubuntu mirror is sometimes slow: a FilmCraft CI run spent 5 min 42 s downloading 21 MB of build dependencies (storytold/filmcraft#2860), and FigCraft's apt step took 4 to 9 minutes in two of eight runs (craft-common-actions#60). The action points apt's archive directory at a cached folder, so a run with a warm cache downloads only the package lists.
39 lines
1.4 KiB
Python
39 lines
1.4 KiB
Python
"""The cached apt install action: pinned actions, and PR runs that never write the cache."""
|
|
from pathlib import Path
|
|
import re
|
|
import unittest
|
|
|
|
import yaml
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
ACTION = ROOT / 'actions/install-apt-packages/action.yml'
|
|
|
|
|
|
def steps():
|
|
return yaml.load(ACTION.read_text(), Loader=yaml.BaseLoader)['runs']['steps']
|
|
|
|
|
|
class InstallAptPackagesTests(unittest.TestCase):
|
|
def test_every_used_action_is_pinned_to_a_commit(self):
|
|
for step in steps():
|
|
if 'uses' in step:
|
|
with self.subTest(step=step.get('name')):
|
|
self.assertRegex(step['uses'], r'@[0-9a-f]{40}$')
|
|
|
|
def test_restore_and_save_use_the_same_key_and_path(self):
|
|
restore = next(s for s in steps() if s.get('id') == 'restore')
|
|
save = next(s for s in steps() if 'cache/save' in s.get('uses', ''))
|
|
self.assertEqual(restore['with']['key'], save['with']['key'])
|
|
self.assertEqual(restore['with']['path'], save['with']['path'])
|
|
|
|
def test_by_default_only_pushes_to_the_default_branch_save(self):
|
|
save = next(s for s in steps() if 'cache/save' in s.get('uses', ''))
|
|
condition = re.sub(r'\s+', ' ', save['if'])
|
|
self.assertIn("github.event_name == 'push'", condition)
|
|
self.assertIn('github.ref_name == github.event.repository.default_branch', condition)
|
|
self.assertIn("cache-hit != 'true'", condition)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|