diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index ce43e2c..518047d 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -1,14 +1,20 @@ name: Push to registry on: - push: - branches: - - "main" + create: jobs: docker: + if: startsWith(github.ref, 'refs/tags/') runs-on: ubuntu-latest steps: + - name: Install jq if not present + run: | + if ! command -v jq &> /dev/null + then + sudo apt-get update + sudo apt-get install -y jq + fi - name: Set up QEMU uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx @@ -23,10 +29,23 @@ jobs: uses: docker/build-push-action@v5 with: push: true - tags: registry.ellite.dev/raibu-web:latest + tags: registry.ellite.dev/raibu-web:${{ github.ref_name }} + - name: Update latest tag + run: | + LATEST_TAG=$(curl -s https://api.github.com/repos/${{ github.repository }}/tags | jq -r '.[].name' | sort -V | tail -n 1) + CURRENT_TAG=${{ github.ref_name }} + SEMVER_REGEX="^v([0-9]+)\.([0-9]+)\.([0-9]+)$" + if [[ ! $CURRENT_TAG =~ $SEMVER_REGEX ]]; then + echo "Error: Tag $CURRENT_TAG does not follow semantic versioning" + exit 1 + fi + if [[ "$(printf '%s\n' "$LATEST_TAG" "$CURRENT_TAG" | sort -V | tail -n 1)" == "$CURRENT_TAG" ]]; then + docker tag registry.ellite.dev/raibu-web:${{ github.ref_name }} registry.ellite.dev/raibu-web:latest + docker push registry.ellite.dev/raibu-web:latest + fi - name: Test image run: | - docker pull registry.ellite.dev/raibu-web:latest + docker pull registry.ellite.dev/raibu-web:${{ github.ref_name }} if [ $? -eq 0 ]; then echo "Image exists" else @@ -34,6 +53,7 @@ jobs: exit 1 fi tarball: + if: startsWith(github.ref, 'refs/tags/') runs-on: ubuntu-latest steps: - name: Checkout