|
| 1 | +--- |
| 2 | +name: Test for "docker/create-images-manifests" action |
| 3 | +run-name: Test for "docker/create-images-manifests" action |
| 4 | + |
| 5 | +on: # yamllint disable-line rule:truthy |
| 6 | + workflow_call: |
| 7 | + |
| 8 | +permissions: {} |
| 9 | + |
| 10 | +jobs: |
| 11 | + build-original-tag: |
| 12 | + name: Arrange - Build original tag |
| 13 | + uses: ./.github/workflows/docker-build-images.yml |
| 14 | + permissions: |
| 15 | + contents: read |
| 16 | + id-token: write |
| 17 | + issues: read |
| 18 | + packages: write |
| 19 | + pull-requests: read |
| 20 | + secrets: |
| 21 | + oci-registry-password: ${{ secrets.GITHUB_TOKEN }} |
| 22 | + with: |
| 23 | + sign: false |
| 24 | + images: | |
| 25 | + [ |
| 26 | + { |
| 27 | + "name": "test-create-manifests-clone-tag", |
| 28 | + "context": ".", |
| 29 | + "dockerfile": "./tests/application/Dockerfile", |
| 30 | + "target": "prod", |
| 31 | + "platforms": ["linux/amd64"], |
| 32 | + "tag": "1.0.0-rc.0" |
| 33 | + } |
| 34 | + ] |
| 35 | +
|
| 36 | + clone-tag: |
| 37 | + name: Act/Assert - Clone 1.0.0-rc.0 to 1.0.0 |
| 38 | + needs: build-original-tag |
| 39 | + runs-on: ubuntu-latest |
| 40 | + permissions: |
| 41 | + contents: read |
| 42 | + packages: write |
| 43 | + steps: |
| 44 | + - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 |
| 45 | + with: |
| 46 | + persist-credentials: false |
| 47 | + |
| 48 | + - uses: ./actions/docker/setup |
| 49 | + with: |
| 50 | + oci-registry: ghcr.io |
| 51 | + oci-registry-username: ${{ github.repository_owner }} |
| 52 | + oci-registry-password: ${{ secrets.GITHUB_TOKEN }} |
| 53 | + |
| 54 | + - id: create-images-manifests-input |
| 55 | + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 |
| 56 | + env: |
| 57 | + BUILT_IMAGES_OUTPUT: ${{ needs.build-original-tag.outputs.built-images }} |
| 58 | + with: |
| 59 | + script: | |
| 60 | + const builtImages = JSON.parse(process.env.BUILT_IMAGES_OUTPUT); |
| 61 | +
|
| 62 | + const imageName = "test-create-manifests-clone-tag"; |
| 63 | + const originalImage = builtImages[imageName]; |
| 64 | + if (!originalImage) { |
| 65 | + throw new Error(`Missing "${imageName}" entry in "built-images" output`); |
| 66 | + } |
| 67 | +
|
| 68 | + const cloneInput = { |
| 69 | + [imageName]: { |
| 70 | + ...originalImage, |
| 71 | + tags: ["1.0.0"], |
| 72 | + images: [`${originalImage.registry}/${originalImage.repository}:1.0.0-rc.0`], |
| 73 | + "multi-platform": true, |
| 74 | + }, |
| 75 | + }; |
| 76 | +
|
| 77 | + core.setOutput("built-images", JSON.stringify(cloneInput)); |
| 78 | +
|
| 79 | + - id: clone-tag |
| 80 | + uses: ./actions/docker/create-images-manifests |
| 81 | + with: |
| 82 | + oci-registry: ghcr.io |
| 83 | + oci-registry-username: ${{ github.repository_owner }} |
| 84 | + oci-registry-password: ${{ secrets.GITHUB_TOKEN }} |
| 85 | + built-images: ${{ steps.create-images-manifests-input.outputs.built-images }} |
| 86 | + |
| 87 | + - name: Assert - Cloned image digest and tag |
| 88 | + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 |
| 89 | + env: |
| 90 | + ORIGINAL_BUILT_IMAGES_OUTPUT: ${{ needs.build-original-tag.outputs.built-images }} |
| 91 | + CLONED_BUILT_IMAGES_OUTPUT: ${{ steps.clone-tag.outputs.built-images }} |
| 92 | + with: |
| 93 | + script: | |
| 94 | + const assert = require("assert"); |
| 95 | +
|
| 96 | + const imageName = "test-create-manifests-clone-tag"; |
| 97 | +
|
| 98 | + const originalBuiltImages = JSON.parse(process.env.ORIGINAL_BUILT_IMAGES_OUTPUT); |
| 99 | + const clonedBuiltImages = JSON.parse(process.env.CLONED_BUILT_IMAGES_OUTPUT); |
| 100 | +
|
| 101 | + const originalImage = originalBuiltImages[imageName]; |
| 102 | + const clonedImage = clonedBuiltImages[imageName]; |
| 103 | +
|
| 104 | + assert(originalImage, `Missing "${imageName}" in original built-images output`); |
| 105 | + assert(clonedImage, `Missing "${imageName}" in cloned built-images output`); |
| 106 | +
|
| 107 | + assert.equal(clonedImage.tags.length, 1, `Expected one cloned tag for "${imageName}"`); |
| 108 | + assert.equal(clonedImage.tags[0], "1.0.0", `Unexpected cloned tag for "${imageName}"`); |
| 109 | +
|
| 110 | + assert.match(clonedImage.digest, /^sha256:[a-f0-9]{64}$/, `Invalid digest format for "${imageName}"`); |
| 111 | + assert.equal( |
| 112 | + clonedImage.digest, |
| 113 | + originalImage.digest, |
| 114 | + `Digest mismatch for "${imageName}": expected cloned digest to match original digest`, |
| 115 | + ); |
| 116 | +
|
| 117 | + const expectedClonedImage = `${clonedImage.registry}/${clonedImage.repository}:1.0.0@${clonedImage.digest}`; |
| 118 | + assert( |
| 119 | + clonedImage.images.includes(expectedClonedImage), |
| 120 | + `Expected cloned image reference not found: ${expectedClonedImage}`, |
| 121 | + ); |
0 commit comments