Skip to content

Commit

Permalink
Modified the test-action.yml file so that there is a precondition ste…
Browse files Browse the repository at this point in the history
…p to prepopulate the cache. Once populated, we run the cache-hit test to verify there is a cache hit, using the same cache key. For the cache-miss test, we purposely make sure to use a different, randomized cache key to validate that the logic works properly to pull fresh images during a forced cache flush or in cases where the cache key is not pointing to cached data.
  • Loading branch information
jamesmortensen committed Jan 20, 2024
1 parent 5403eeb commit 438d394
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 15 deletions.
72 changes: 57 additions & 15 deletions .github/workflows/test-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,41 @@ defaults:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
cache-hit:
prepopulate-cache:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Information on prepopulating cache
run: |
echo "This makes sure the cache has something in it before running the cache-hit test."
echo "The same key is used in the prepopulate-cache job as in the cache-hit job."
- name: Cache Container Images
id: cache-container-images
uses: ./
with:
runtime: podman
prefix-key: 'podman-cache-hit ${{ github.run_id }}'
images: |
selenium/node-chrome:4.1.2-20220130
selenium/hub:4.1.2-20220130
cache-hit-test:
# The type of runner that the job will run on
runs-on: ubuntu-latest
needs: prepopulate-cache

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Information on cache-hit test
run: |
echo "Attempt to pull images using same key used in prepopulate-cache."
echo "Since something is in the cache, we expect this test to pass with a cache HIT."
- name: Cache Container Images
id: cache-container-images
Expand All @@ -35,6 +61,7 @@ jobs:
uses: ./
with:
runtime: podman
prefix-key: 'podman-cache-hit ${{ github.run_id }}'
images: |
selenium/node-chrome:4.1.2-20220130
selenium/hub:4.1.2-20220130
Expand All @@ -45,12 +72,17 @@ jobs:
echo "Attempting to install podman-compose. If it installs successfully, then permissions are ok"
pip3 install podman-compose
- name: Show output of cache hit
run: echo "${{ steps.cache-container-images.outputs.cache-hit }}"
- name: Pass test only if there is a cache hit
if: ${{ steps.cache-container-images.outputs.cache-hit == 'true' }}
shell: bash
run: echo "Container images are found in the cache. Test passes!"

- name: Terminate if cache was not hit
- name: Fail test if there is a cache miss
if: ${{ steps.cache-container-images.outputs.cache-hit != 'true' }}
run: exit 1
shell: bash
run: |
echo "Container images are not found in the cache! Test FAILS!"
exit 1
- name: Start and stop container with podman
run: |
Expand All @@ -63,22 +95,27 @@ jobs:
podman stop --cidfile cid-hub
cache-miss:
cache-miss-test:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Information on cache-miss test
run: |
echo "Attempt to pull images using randomized key."
echo "Nothing should be in the cache, we expect this test to pass with a cache MISS."
- name: Cache Container Images
id: cache-container-images
# In your project you replace local version "./" with following
# uses: jamesmortensen/cache-container-images-action@master
uses: ./
with:
prefix-key: 'podman-cache ${{ github.run_id }}'
prefix-key: 'podman-cache-miss ${{ github.run_id }}'
images: |
selenium/node-chrome:latest
selenium/hub:latest
Expand All @@ -89,12 +126,17 @@ jobs:
echo "Attempting to install podman-compose. If it installs successfully, then permissions are ok"
pip3 install podman-compose
- name: Show output of cache hit
run: echo "${{ steps.cache-container-images.outputs.cache-hit }}"

- name: Terminate if cache was hit
- name: Fail test if there is a cache hit
if: ${{ steps.cache-container-images.outputs.cache-hit == 'true' }}
run: exit 1
shell: bash
run: |
echo "Container images are found in the cache! Test FAILS!"
exit 1
- name: Pass test only if there is a cache miss
if: ${{ steps.cache-container-images.outputs.cache-hit != 'true' }}
shell: bash
run: echo "Container images are not found in the cache. Test passes!"

- name: Start and stop container with podman
run: |
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.DS_Store

0 comments on commit 438d394

Please sign in to comment.