75 lines
2.1 KiB
YAML

name: Build and Push Docker Image
on:
workflow_dispatch:
inputs:
version:
description: 'Version to tag the image with (e.g., 1.0.0)'
required: true
type: string
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: write # Allows tagging and releasing
packages: write
pull-requests: write # Allows reading PR info if needed
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test || true
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to Container Registry
uses: docker/login-action@v2
with:
registry: ${{ github.server_url }}/${{ github.repository }}/packages
username: ${{ github.actor }}
password: ${{ secrets.PACKAGE_TOKEN }}
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ github.server_url }}/${{ github.repository }}/personal-website
tags: |
type=raw,value=${{ github.event.inputs.version }}
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: |
${{ github.server_url }}/${{ github.repository }}/personal-website:latest
${{ github.server_url }}/${{ github.repository }}/personal-website:${{ github.event.inputs.version }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Create GitHub Release
uses: mathieudutour/github-tag-action@v6.1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
custom_tag: ${{ github.event.inputs.version }}
release_branches: main
create_annotated_tag: true
tag_prefix: v