Gvegayon usable scripts #74
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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:${{ steps.twostep-2.outputs.tag }} \ | |
| --format='{{ index .Config.Labels "GH_SHA" }}' > _${{ github.sha }}_labels.json | |
| if [ "$(cat _${{ github.sha }}_labels.json)" != "${{ github.sha }}" ]; then | |
| echo "The argument GH_SHA does not match the expected value." | |
| exit 1 | |
| fi | |
| - name: Check the output | |
| run: | | |
| if [ "${{ steps.twostep-2.outputs.summary }}" == "rebuilt" ]; then | |
| echo "Using a re-built version (OK)" | |
| else | |
| echo "This was supposed to use the cache version" | |
| exit 1 | |
| fi | |
| test-azure-cr: | |
| runs-on: cfa-cdcgov | |
| name: Build and push image | |
| steps: | |
| - name: Login to Azure | |
| id: azure_login_2 | |
| uses: azure/login@v2 | |
| with: | |
| creds: ${{ secrets.AZ_SERVICE_PRINCIPAL_CREDS_STRING }} | |
| - name: Login to ACR | |
| run: az acr login --name ${{ vars.AZ_CONTAINER_REGISTRY_NAME }} | |
| - name: Build and push image | |
| id: build-push | |
| uses: CDCgov/cfa-actions/twostep-container-build@v1.2.0 | |
| with: | |
| 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-test | |
| build-args-2: | | |
| GH_SHA=${{ github.sha }} | |
| push-image-1: true | |
| push-image-2: true | |
| - name: Clean up by deleting image | |
| id: delete-images | |
| run: az acr repository delete --name {{ vars.AZ_CONTAINER_REGISTRY_NAME }} --repository cdcgov/_cfa-actions-test | |