Publish autodarts docker image #96
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This workflow uses actions that are not certified by GitHub. | |
# They are provided by a third-party and are governed by | |
# separate terms of service, privacy policy, and support | |
# documentation. | |
# GitHub recommends pinning actions to a commit SHA. | |
# To get a newer version, you will need to update the SHA. | |
# You can also reference a tag or branch, but the action may change without warning. | |
name: Publish autodarts docker image | |
#trigger when a new version tag is set | |
on: | |
schedule: | |
- cron: '0 10 * * *' | |
workflow_dispatch: null | |
permissions: | |
contents: read | |
env: | |
AUTODARTS_IMAGE_NAME: michvllni/autodarts | |
jobs: | |
get_target_version: | |
name: Get latest release from autodarts | |
runs-on: ubuntu-latest | |
outputs: | |
version: ${{ steps.autodarts-latest-release.outputs.version }} | |
steps: | |
- name: Get latest release from autodarts | |
id: autodarts-latest-release | |
run: | | |
latestVersion=$(curl -s https://get.autodarts.io/detection/latest/linux/arm64/RELEASES.json | jq -r '.currentVersion') | |
echo "Latest version from autodarts: $latestVersion" | |
#get current version from docker hub michvllni/autodarts-docker | |
currentVersion=$(curl -s https://hub.docker.com/v2/repositories/michvllni/autodarts/tags/ | jq -r '.results[].name' | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -n 1) | |
echo "Current version from docker hub: v$currentVersion" | |
if [ "$latestVersion" != "v$currentVersion" ]; then | |
echo "New version available" | |
echo "version=$latestVersion" >> $GITHUB_OUTPUT | |
else | |
echo "No new version available" | |
fi | |
shell: bash | |
push_to_registry: | |
name: Build and Push Docker image to Github Container Registry | |
runs-on: ubuntu-latest | |
needs: get_target_version | |
if: needs.get_target_version.outputs.version != null && needs.get_target_version.outputs.version != '' | |
steps: | |
- name: Check out the repo | |
uses: actions/checkout@v4 | |
# https://github.com/docker/setup-qemu-action | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
# https://github.com/docker/setup-buildx-action | |
- name: Set up Docker Buildx | |
id: buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to Docker Hub | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Set Docker Image Metadata | |
id: set_image_metadata | |
uses: docker/metadata-action@v5 | |
with: | |
# list of Docker images to use as base name for tags | |
images: | | |
docker.io/${{ env.AUTODARTS_IMAGE_NAME }} | |
# Docker tags based on the following events/attributes | |
tags: | | |
type=schedule | |
type=ref,event=branch | |
type=ref,event=pr | |
type=semver,pattern={{version}},value=${{ needs.get_target_version.outputs.version }} | |
type=semver,pattern={{major}}.{{minor}},value=${{ needs.get_target_version.outputs.version }} | |
type=semver,pattern={{major}},value=${{ needs.get_target_version.outputs.version }} | |
type=sha | |
latest | |
- name: Build and push | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
provenance: false | |
platforms: linux/amd64,linux/arm64 | |
build-args: VERSION=${{ needs.get_target_version.outputs.version }} | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.set_image_metadata.outputs.tags }} | |
labels: ${{ steps.set_image_metadata.outputs.labels }} |