Skip to content

Build and Release Production #29

Build and Release Production

Build and Release Production #29

Workflow file for this run

name: Build and Release Production
on:
workflow_dispatch:
inputs:
target:
required: true
description: New tag (e.g., v1.2.3)
env:
IMAGE_NAME: ghcr.io/${{ github.repository }}
jobs:
build-and-push:
name: Build and Push Docker Image
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Set Image Tags
id: set-tag
run: |
RAW_TAG="${{ github.event.inputs.target }}"
if [[ ! "$RAW_TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Invalid tag format. Please use vX.Y.Z format."
exit 1
fi
echo "IMAGE_TAG=${RAW_TAG#v}" >> "$GITHUB_ENV"
echo "IMAGE_NAME=ghcr.io/${GITHUB_REPOSITORY,,}" >> "$GITHUB_ENV"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and Push Docker Image
uses: docker/build-push-action@v3
with:
file: Dockerfile
push: true
tags: ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
cache-from: type=registry,ref=${{ env.IMAGE_NAME }}:buildcache
cache-to: type=registry,ref=${{ env.IMAGE_NAME }}:buildcache,mode=max
release_commit:
name: Release Commit
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
filter: 'blob:none'
fetch-depth: 0
- name: Generate a Changelog
uses: orhun/git-cliff-action@v3
with:
config: cliff.toml
args: '--verbose --tag ${{ github.event.inputs.target }}'
env:
OUTPUT: CHANGELOG.md
GITHUB_REPO: ${{ github.repository }}
- name: Update package.json Version
run: |
# Remove 'v' prefix for package.json version
VERSION="${{ github.event.inputs.target }}"
VERSION="${VERSION#v}"
PACKAGEJSON=$(jq --indent 2 ".version = \"$VERSION\"" package.json)
echo "$PACKAGEJSON" > package.json
- name: Commit Release
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: 'chore(release): prepare for ${{ github.event.inputs.target }}'
release_github:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: release_commit
permissions:
contents: write
packages: write
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Generate a Changelog for Release
uses: orhun/git-cliff-action@v3
id: git-cliff
with:
config: cliff.toml
args: --verbose --unreleased --strip all --tag ${{ github.event.inputs.target }}
env:
OUTPUT: CHANGES.md
GITHUB_REPO: ${{ github.repository }}
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
body_path: CHANGES.md
tag_name: ${{ github.event.inputs.target }}
generate_release_notes: true