Skip to content

Release and Docker Push #8

Release and Docker Push

Release and Docker Push #8

Workflow file for this run

name: Release and Docker Push
on:
push:
branches: [v3]
paths:
- package.json
workflow_dispatch:
permissions:
contents: write
packages: write
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Read versions
id: versions
run: |
set -euo pipefail
CUR_VERSION=$(node -p "require('./package.json').version")
echo "current=$CUR_VERSION" >> "$GITHUB_OUTPUT"
echo "LOG: Current version found in package.json: $CUR_VERSION"
PREV_TAG=$(git tag --list "v*" --sort=-v:refname | head -n 1 || true)
if [ -z "${PREV_TAG:-}" ]; then
PREV_VERSION=""
echo "LOG: No previous tag found"
else
PREV_VERSION="${PREV_TAG#v}"
echo "LOG: Previous tag found: $PREV_TAG (version $PREV_VERSION)"
fi
echo "previous=$PREV_VERSION" >> "$GITHUB_OUTPUT"
- name: Version comparison
id: check
run: |
set -euo pipefail
echo "LOG: Running semantic version comparison"
echo "LOG: Compare current=${{ steps.versions.outputs.current }} against previous=${{ steps.versions.outputs.previous || '<none>' }}"
node - <<'NODE' >> "$GITHUB_OUTPUT"
const cur = process.env.CUR;
const prev = process.env.PREV;
function parse(v) {
if (!v) return null;
const m = String(v).trim().replace(/^v/, "").match(/^(\d+)\.(\d+)\.(\d+)(?:[-+].*)?$/);
return m ? m.slice(1, 4).map(Number) : null;
}
function gt(a, b) {
for (let i = 0; i < 3; i++) {
if (a[i] !== b[i]) return a[i] > b[i];
}
return false;
}
const a = parse(cur);
const b = parse(prev);
let should = false;
if (!a) {
should = false;
} else if (!prev) {
should = true;
} else if (a && b) {
should = gt(a, b);
} else {
should = cur !== prev;
}
console.log(`should_release=${should}`);
NODE
env:
CUR: ${{ steps.versions.outputs.current }}
PREV: ${{ steps.versions.outputs.previous }}
- name: Logging decision
run: |
echo "LOG: should_release=${{ steps.check.outputs.should_release }}"
- name: GitHub Release
if: steps.check.outputs.should_release == 'true'
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ steps.versions.outputs.current }}
name: v${{ steps.versions.outputs.current }}
generate_release_notes: true
- name: Set up Docker Buildx
if: steps.check.outputs.should_release == 'true'
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
if: steps.check.outputs.should_release == 'true'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
if: steps.check.outputs.should_release == 'true'
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.versions.outputs.current }}
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
cache-from: type=gha
cache-to: type=gha,mode=max