Skip to content

Publish and Release #10

Publish and Release

Publish and Release #10

Workflow file for this run

name: Publish and Release
on:
push:
tags:
- "v*"
workflow_dispatch:
permissions:
contents: write
packages: write
id-token: write
jobs:
check:
name: Check
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')
uses: ./.github/workflows/check.yml
publish:
name: Publish
needs: check
runs-on: ubuntu-latest
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Set lower case image name
run: |
echo "IMAGE_NAME=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV
- name: Install Cosign
uses: sigstore/cosign-installer@v3.7.0
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker registry
uses: docker/login-action@v3
with:
registry: dhi.io
username: ${{ secrets.DHI_USERNAME }}
password: ${{ secrets.DHI_TOKEN }}
- name: Log in to GitHub registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) || startsWith(github.ref, 'refs/tags/') }}
type=ref,event=branch
type=ref,event=tag
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
annotations: ${{ steps.meta.outputs.annotations }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Sign the published Docker image
env:
TAGS: ${{ steps.meta.outputs.tags }}
DIGEST: ${{ steps.build-and-push.outputs.digest }}
run: |
images=""
for tag in ${TAGS}; do
images+="${tag}@${DIGEST} "
done
cosign sign --yes ${images}
release:
name: Release
if: startsWith(github.ref, 'refs/tags/')
needs: publish
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Prepare Release Body
run: |
TAG=${{ github.ref_name }}
REPO_NAME=${GITHUB_REPOSITORY,,}
echo "## Quick Start" > release_body.md
echo "" >> release_body.md
echo " \`\`\`bash" >> release_body.md
echo "docker pull ghcr.io/${REPO_NAME}:${TAG}" >> release_body.md
echo " \`\`\`" >> release_body.md
echo "" >> release_body.md
echo "---" >> release_body.md
- name: Create Release
uses: softprops/action-gh-release@v2
with:
body_path: release_body.md
generate_release_notes: true