Skip to content

[Sharp-API] Fix workflow #47

[Sharp-API] Fix workflow

[Sharp-API] Fix workflow #47

Workflow file for this run

name: Sharp-API Docker Build and Push
on:
push:
tags:
- 'js-sharp-api-*'
jobs:
build-and-push:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
platform: linux/amd64
- os: buildjet-4vcpu-ubuntu-2204-arm
platform: linux/arm64
outputs:
version: ${{ env.version }}
latest: ${{ env.IS_LATEST }}
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Check out Sharp-API repo
uses: actions/checkout@v4
with:
repository: 'carry0987/Sharp-API'
token: ${{ secrets.GH_CLONE_TOKEN }}
path: 'JS/Sharp-API/source'
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Prepare the Docker tags list
id: prep
run: |
FULL_VERSION=$(echo ${{ github.ref }} | sed -e 's,.*/js-sharp-api-,,')
VERSION=${FULL_VERSION%-latest}
TAGS="${{ secrets.DOCKER_USERNAME }}/sharp-api:${VERSION}"
IS_LATEST=false
if [[ ${{ matrix.platform }} == "linux/amd64" ]]; then
SUFFIX="-amd64"
elif [[ ${{ matrix.platform }} == "linux/arm64" ]]; then
SUFFIX="-arm64"
fi
TAGS="${{ secrets.DOCKER_USERNAME }}/sharp-api:${VERSION}${SUFFIX}"
if [[ "$FULL_VERSION" == *"-latest" ]]; then
TAGS="$TAGS,${{ secrets.DOCKER_USERNAME }}/sharp-api:latest${SUFFIX}"
IS_LATEST=true
fi
echo "TAGS=$TAGS" >> $GITHUB_ENV
echo "PROGRAM_VERSION=${VERSION%}" >> $GITHUB_ENV
echo "version=${VERSION%}" >> $GITHUB_ENV
echo "IS_LATEST=$IS_LATEST" >> $GITHUB_ENV
echo "PROGRAM_VERSION=${VERSION%}"
echo "Building with tags: $TAGS"
- name: Start multi-arch build and push
uses: docker/build-push-action@v5
with:
context: JS/Sharp-API
file: JS/Sharp-API/Dockerfile
build-args: PROGRAM_VERSION=${{ env.PROGRAM_VERSION }}
push: true
tags: ${{ env.TAGS }}
platforms: ${{ matrix.platform }}
provenance: false
- name: Logout from DockerHub
run: docker logout
manifest:
needs: build-and-push
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Set image prefix
run: echo "IMAGE_PREFIX=${{ secrets.DOCKER_USERNAME }}/sharp-api:${{ needs.build-and-push.outputs.version }}" >> $GITHUB_ENV
- name: Create and push manifest images
uses: Noelware/docker-manifest-action@master
with:
inputs: ${{ secrets.DOCKER_USERNAME }}/sharp-api:${{ needs.build-and-push.outputs.version }}
images: ${{ env.IMAGE_PREFIX }}-amd64,${{ env.IMAGE_PREFIX }}-arm64
push: true
amend: true
- name: Check outputs for latest
run: echo "Latest ${{ needs.build-and-push.outputs.latest }}"
- name: Set image prefix for latest
if: ${{ needs.build-and-push.outputs.latest == 'true' }}
run: echo "IMAGE_PREFIX=${{ secrets.DOCKER_USERNAME }}/sharp-api:latest" >> $GITHUB_ENV
- name: Create and push manifest images for latest
if: ${{ needs.build-and-push.outputs.latest == 'true' }}
uses: Noelware/docker-manifest-action@master
with:
inputs: ${{ env.IMAGE_PREFIX }}
images: ${{ env.IMAGE_PREFIX }}-amd64,${{ env.IMAGE_PREFIX }}-arm64
push: true
amend: true
- name: Logout from DockerHub
run: docker logout