Skip to content

Test Action (Integration) #2302

Test Action (Integration)

Test Action (Integration) #2302

name: "Test Action (Integration)"
on:
schedule:
- cron: "*/37 12 * * *"
push:
branches:
- "**"
env:
registry: ghcr.io
repository: "${{ github.repository }}"
tag: "test-${{ github.run_id }}"
image-writable: "ghcr.io/${{ github.repository }}:test-${{ github.run_id }}"
image-unwritable: "ghcr.io/${{ github.repository }}-unwritable:test-${{ github.run_id }}"
username: "${{ github.repository_owner }}"
password: "${{ github.token }}"
token: "${{ github.token }}"
jobs:
tag-example-image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Javascript dependencies via npm
if: ${{ github.ref != 'refs/heads/release' }}
run: npm install
- name: Package action for integration tests
if: ${{ github.ref != 'refs/heads/release' }}
run: npm run package
- name: Log In to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: "${{ env.registry }}"
username: "${{ env.username }}"
password: "${{ env.password }}"
- name: Add example image to container registry for test repository
run: |
docker pull hello-world
docker tag hello-world ${{ env.image-writable }}
docker push ${{ env.image-writable }}
- name: Add One Tag
uses: ./
with:
registry: "${{ env.registry }}"
repository: "${{ env.repository }}"
target: "${{ env.tag }}"
tags: "${{ env.tag }}-single"
- name: Add Multiple Tags
uses: ./
with:
registry: "${{ env.registry }}"
repository: "${{ env.repository }}"
target: "${{ env.tag }}"
tags: |
${{ env.tag }}-multiple-a
${{ env.tag }}-multiple-b
- name: Install latest Skopeo # GitHub's ubuntu 22 uses Skopeo 1.4 but we need 1.14
run: |
sudo apt clean
echo 'deb https://download.opensuse.org/repositories/home:/alvistack/xUbuntu_22.04/ /' | sudo tee /etc/apt/sources.list.d/home:alvistack.list
curl -fsSL https://download.opensuse.org/repositories/home:alvistack/xUbuntu_22.04/Release.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/home_alvistack.gpg > /dev/null
sudo apt update
sudo apt -o Dpkg::Options::="--force-overwrite" install skopeo
- name: Add example OCI image to container registry
run: |
token=$(echo -n $token | base64)
skopeo copy --all \
"docker:https://docker.io/library/hello-world:latest" \
"docker:https://${{ env.image-writable }}-oci" \
--dest-registry-token $token \
-f oci
- name: Add signle tag to OCI image
uses: ./
with:
registry: "${{ env.registry }}"
repository: "${{ env.repository }}"
target: "${{ env.tag }}-oci"
tags: "${{ env.tag }}-oci-single"
assert-tags-exist:
runs-on: ubuntu-latest
needs:
- tag-example-image
strategy:
matrix:
include:
- tag: single
version: "docker.distribution.manifest.v2"
- tag: multiple-a
version: "docker.distribution.manifest.v2"
- tag: multiple-b
version: "docker.distribution.manifest.v2"
- tag: oci-single
version: "oci.image.index.v1"
fail-fast: false
env:
repository: "https://ghcr.io/v2/${{ github.repository }}"
tag: "test-${{ github.run_id }}-${{ matrix.tag }}"
version: "${{ matrix.version }}"
steps:
- name: Assert image has tag ${{ matrix.tag }}
run: |
token=$(echo -n $token | base64)
curl -sf $repository/manifests/$tag \
-H "Authorization: Bearer $token" \
-H "Accept: application/vnd.$version+json" \
|| (echo "::error::$tag not found" && exit 1)
try-to-tag-unwritable-image:
runs-on: ubuntu-latest
steps:
- name: Log In to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: "${{ env.registry }}"
username: "${{ env.username }}"
password: "${{ env.password }}"
- id: write-image
name: Attempt to write image that cannot be written to
continue-on-error: true
run: |
docker pull hello-world
docker tag hello-world ${{ env.image-unwritable }}
docker push ${{ env.image-unwritable }}
- if: steps.write-image.outcome != 'failure'
uses: actions/github-script@v3
with:
script: core.setFailed('Did not throw error when trying to write an unwritable image')