Skip to content

fix: update version to 1.0.5 in package.json #25

fix: update version to 1.0.5 in package.json

fix: update version to 1.0.5 in package.json #25

name: Build and Push Docker Image
on:
push:
branches:
- main
tags:
- "v*"
pull_request:
branches:
- main
workflow_dispatch: # Allow manual trigger
inputs:
no_cache:
description: "Build without cache (fresh build)"
required: false
type: boolean
default: false
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Get version from package.json
id: package-version
run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels)
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
# Set latest tag for default branch
type=raw,value=latest,enable={{is_default_branch}}
# Tag with version from package.json (e.g., 1.0.4)
type=raw,value=${{ steps.package-version.outputs.version }},enable={{is_default_branch}}
# Tag with branch name
# type=ref,event=branch
# Tag with PR number
# type=ref,event=pr
# Tag with git tag (v1.0.0)
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
# Tag with short SHA
type=sha,prefix=
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: ${{ inputs.no_cache && '' || 'type=gha' }}
cache-to: type=gha,mode=max
platforms: linux/amd64,linux/arm64