Skip to content

set exit code

set exit code #2

name: Docker Image CI
on:
workflow_dispatch:
schedule:
- cron: '4 20 * * 4'
push:
branches: [ main ]
jobs:
latest_version:
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.fetch_tag.outputs.tag }}
steps:
- name: Fetch latest version
id: fetch_tag
run: |
API_TOKEN="${{ secrets.GITHUB_TOKEN }}"
REPO_OWNER="just-containers"
REPO_NAME="s6-overlay"
curl -sH "Authorization: token $API_TOKEN" https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/releases/latest > latest_version.json
tag_name=$(jq -r '.tag_name' latest_version.json)
echo "::set-output name=tag::$tag_name"
check_image_tag:
runs-on: ubuntu-latest
needs: latest_version
outputs:
image_exists: ${{ steps.check_image.outputs.exists }}
steps:
- name: Check image tag exists
id: check_image
run: |
IMAGE_NAME="hakindazz/s6-overlay-base"
IMAGE_TAG=${{ needs.latest_version.outputs.tag }}
docker pull "$IMAGE_NAME:$IMAGE_TAG" &> /dev/null
if [ $? -eq 0 ]; then
echo "::set-output name=exists::true"
else
echo "::set-output name=exists::false"
fi
exit 0
build-and-push:
runs-on: ubuntu-latest
needs: [latest_version, check_image_tag]
if: "!needs.check_image_tag.outputs.image_exists"
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
push: true
tags: |
hakindazz/s6-overlay-base:latest
hakindazz/s6-overlay-base:${{ needs.latest_version.outputs.tag }}