This repository has been archived by the owner on Nov 23, 2024. It is now read-only.
Update docker-publish.yml #14
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
name: Docker | |
on: | |
push: | |
branches: [ "main" ] | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
id-token: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3.0.0 | |
- name: Log into registry ${{ env.REGISTRY }} | |
uses: docker/login-action@v3.0.0 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract Docker metadata | |
id: meta | |
uses: docker/metadata-action@v5.0.0 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
- name: Get the current version tag | |
id: get_version | |
run: | | |
git fetch --tags | |
TAG=$(git describe --tags $(git rev-list --tags --max-count=1) || echo "v0.0.0") | |
echo "Current Tag: $TAG" | |
echo "CURRENT_TAG=$TAG" >> $GITHUB_ENV | |
- name: Calculate next version | |
id: calculate_version | |
run: | | |
# Strip the 'v' from the tag and split into an array | |
VERSION=${CURRENT_TAG#v} | |
IFS='.' read -r -a VERSION_PARTS <<< "$VERSION" | |
MAJOR=${VERSION_PARTS[0]} | |
MINOR=${VERSION_PARTS[1]} | |
PATCH=${VERSION_PARTS[2]} | |
# Increment the patch version | |
PATCH=$((PATCH + 1)) | |
# Form the new tag | |
NEW_TAG="v$MAJOR.$MINOR.$PATCH" | |
echo "New Tag: $NEW_TAG" | |
echo "NEW_TAG=$NEW_TAG" >> $GITHUB_ENV | |
- name: Create and push new tag | |
run: | | |
git tag ${{ env.NEW_TAG }} | |
git push origin ${{ env.NEW_TAG }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Create GitHub Release | |
id: create_release | |
uses: softprops/action-gh-release@v1 | |
with: | |
tag_name: ${{ env.NEW_TAG }} | |
name: Release ${{ env.NEW_TAG }} | |
body: "Release of version ${{ env.NEW_TAG }}." | |
draft: false | |
prerelease: false | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push Docker image | |
id: build-and-push | |
uses: docker/build-push-action@v5.0.0 | |
with: | |
context: . | |
push: true | |
tags: | | |
${{ steps.meta.outputs.tags }} | |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.NEW_TAG }} | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
build-args: | | |
BUILD_MODE=${{ github.ref_name }} |