Skip to content

Commit

Permalink
test matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
daya0576 committed Dec 8, 2024
1 parent 8a95dc9 commit f1d25b9
Showing 1 changed file with 15 additions and 67 deletions.
82 changes: 15 additions & 67 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,7 @@ env:
REGISTRY_IMAGE: daya0576/beaverhabits

jobs:
pre-deploy-test:
name: Unit tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install --no-interaction --no-ansi
- name: Test with pytest
run: poetry run pytest tests

build:
needs: pre-deploy-test
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -46,16 +26,6 @@ jobs:
- name: Prepare
id: prep
run: |
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/v}
TAGS="${{ env.REGISTRY_IMAGE }}:${VERSION},${{ env.REGISTRY_IMAGE }}:latest"
else
VERSION=debug
TAGS="${{ env.REGISTRY_IMAGE }}:${VERSION}"
fi
echo $TAGS
echo ::set-output name=tags::${TAGS}
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
Expand All @@ -80,12 +50,12 @@ jobs:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push
- name: Build and push by digest
uses: docker/build-push-action@v6
with:
platforms: ${{ matrix.platform }}
labels: ${{ steps.meta.outputs.labels }}
file: ${{ matrix.dockerfile }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true

- name: Export digest
Expand All @@ -107,12 +77,6 @@ jobs:
needs:
- build
steps:
- name: Download meta bake definition
uses: actions/download-artifact@v4
with:
name: bake-meta
path: /tmp

- name: Download digests
uses: actions/download-artifact@v4
with:
Expand All @@ -129,39 +93,23 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.target."docker-metadata-action".tags | map(select(startswith("${{ env.REGISTRY_IMAGE }}")) | "-t " + .) | join(" ")' /tmp/bake-meta.json) \
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:$(jq -r '.target."docker-metadata-action".args.DOCKER_META_VERSION' /tmp/bake-meta.json)
verify:
needs: merge
runs-on: ubuntu-latest
steps:
- name: Pull and Test Container
env:
VERSION: latest
run: |
docker pull ${{ env.REGISTRY_IMAGE }}:${VERSION}
docker run -d --name test_container ${{ env.REGISTRY_IMAGE }}:${VERSION}
sleep 3
CONTAINER_OUTPUT=$(docker logs test_container)
# Check if the container is still running
CONTAINER_STATUS=$(docker inspect -f '{{.State.Running}}' test_container)
if [ "${CONTAINER_STATUS}" != "true" ]; then
echo "The container is not running!"
exit 1
fi
# Check if the "Error" string is present in the container output
if echo "${CONTAINER_OUTPUT}" | grep -i -q "Error"; then
echo "Error found in container output!"
echo "${CONTAINER_OUTPUT}"
exit 1
fi
docker stop test_container
docker rm test_container
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}

0 comments on commit f1d25b9

Please sign in to comment.