Skip to content

Replace actions/cache with a more robust strategy #51

Replace actions/cache with a more robust strategy

Replace actions/cache with a more robust strategy #51

name: Test twostep-container-build
on:
pull_request:
branches: [main]
paths:
- '.github/workflows/test-twostep-container-build.yml'
- 'twostep-container-build/action.yml'
push:
branches: [main]
paths:
- '.github/workflows/test-twostep-container-build.yml'
- 'twostep-container-build/action.yml'
workflow_dispatch:
jobs:
# This job is used to build and push the image.
test-no-args:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
pull-requests: write
steps:
- uses: actions/checkout@v4
name: Checkout code
- name: Two-step build
uses: ./twostep-container-build
id: twostep-1
with:
registry: ghcr.io/
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
container-file-1: twostep-container-build/examples/Containerfile.dependencies
container-file-2: twostep-container-build/examples/Containerfile
first-step-cache-key: no-args-${{ hashFiles('twostep-container-build/examples/Containerfile.dependencies') }}
image: cdcgov/cfa-actions
# This job is used to rerun the first step of the build
# to ensure that caching is working as expected.
test-no-args-rerun:
runs-on: ubuntu-latest
needs: test-no-args
permissions:
contents: read
packages: write
pull-requests: write
steps:
- uses: actions/checkout@v4
name: Checkout code
- name: Two-step build
uses: ./twostep-container-build
id: twostep-1
with:
registry: ghcr.io/
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
container-file-1: twostep-container-build/examples/Containerfile.dependencies
container-file-2: twostep-container-build/examples/Containerfile
first-step-cache-key: no-args-${{ hashFiles('twostep-container-build/examples/Containerfile.dependencies') }}
image: cdcgov/cfa-actions
push-image-1: false
push-image-2: false
- name: Check the output
run: |
if [ "${{ steps.twostep-1.outputs.summary }}" == "cached" ]; then
echo "Using the cached version (OK)"
else
echo "This was supposed to use the cache version"
exit 1
fi
# This job is used to test the action with arguments.
# Caching should also be triggered here.
test-with-args:
runs-on: ubuntu-latest
needs: test-no-args
permissions:
contents: read
packages: write
pull-requests: write
steps:
- uses: actions/checkout@v4
name: Checkout code
# Testing passing arguments
- name: Two-step build with args
id: twostep-2
uses: ./twostep-container-build
with:
registry: ghcr.io/
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
container-file-1: twostep-container-build/examples/Containerfile.dependencies
container-file-2: twostep-container-build/examples/Containerfile
first-step-cache-key: with-args-${{ hashFiles('twostep-container-build/examples/Containerfile.dependencies') }}
image: cdcgov/cfa-actions
build-args-2: |
GH_SHA=${{ github.sha }}
push-image-1: false
push-image-2: false
- name: Listing the labels from the image
run: |
docker inspect ghcr.io/cdcgov/cfa-actions-with-args:${{ steps.twostep-2.outputs.tag }} \
--format='{{json .Config.Labels}}' | jq .
- name: Check the output
run: |
if [ "${{ steps.twostep-2.outputs.summary }}" == "re-built" ]; then
echo "Using a re-built version (OK)"
else
echo "This was supposed to use the cache version"
exit 1
fi