Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split cache step into two, always save cache, fix hash files #422

Merged
merged 26 commits into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions composite/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,13 @@ runs:
esac
shell: bash

- name: Cache PIP Packages
uses: actions/cache@v3
- name: Restore PIP packages cache
uses: actions/cache/restore@v3

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can I use this branch directly?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uses: EnricoMi/publish-unit-test-result-action/composite@branch-composite-cache-pip-packages-2

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went for the direct hash, so it's clear which commit was used, but now I realize that "Set up job" lists them.

id: cache
continue-on-error: true
with:
path: ${{ steps.os.outputs.pip-cache }}
key: enricomi-publish-action-${{ runner.os }}-${{ runner.arch }}-pip-${{ steps.python.outputs.version }}-${{ hashFiles('**/requirements.txt', 'composite/action.yml') }}
key: enricomi-publish-action-${{ runner.os }}-${{ runner.arch }}-pip-${{ steps.python.outputs.version }}-f3f2c295046c91ed612b4efb6c9fb352

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw you were fighting with this, in the end you'll update it manually for each release?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you pull in https://github.com/actions/github-script and call hashFiles directly from JS?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you'll update it manually for each release

yes, but only if requirements.txt changes

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and call hashFiles directly from JS?

maybe, but I'd prefer not to add more complexity


- name: Install Python dependencies

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this affect steps.python.outputs.version, so that when it comes to cache/save it's a different version but it's still using the old key?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't get it. With key: ${{ steps.cache.outputs.cache-primary-key }}, the same key is used when saving the cache. Why should the python version change?

run: |
Expand Down Expand Up @@ -238,6 +239,14 @@ runs:
LOG_LEVEL: ${{ inputs.log_level }}
shell: bash

- name: Save PIP packages cache
uses: actions/cache/save@v3
if: ( success() || failure() ) && ! steps.cache.outputs.cache-hit
continue-on-error: true
with:
path: ${{ steps.os.outputs.pip-cache }}
key: ${{ steps.cache.outputs.cache-primary-key }}

branding:
icon: 'check-circle'
color: 'green'
13 changes: 13 additions & 0 deletions python/test/test_action_yml.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import hashlib
import pathlib
import sys
import unittest

import yaml
Expand Down Expand Up @@ -28,6 +30,17 @@ 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
# this md5 is linux-based (on Windows, git uses different newlines, which changes the hash)
if sys.platform != 'win32':
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