Skip to content

Merge pull request #3 from BYLinMou/feat/UI-enhancement #15

Merge pull request #3 from BYLinMou/feat/UI-enhancement

Merge pull request #3 from BYLinMou/feat/UI-enhancement #15

Workflow file for this run

name: Release
on:
push:
branches:
- main
workflow_dispatch:
permissions:
contents: write
packages: write
jobs:
release:
name: Create Release And Publish Images
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
tag_exists: ${{ steps.tag_check.outputs.exists }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Read version
id: version
shell: bash
run: |
VERSION="$(tr -d '\r\n' < VERSION)"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "VERSION=$VERSION" >> "$GITHUB_ENV"
- name: Check if tag exists
id: tag_check
shell: bash
run: |
if git rev-parse "v${VERSION}" >/dev/null 2>&1; then
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Create git tag
if: steps.tag_check.outputs.exists == 'false'
shell: bash
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git tag "v${VERSION}"
git push origin "v${VERSION}"
- name: Create GitHub release
if: steps.tag_check.outputs.exists == 'false'
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ steps.version.outputs.version }}
name: HKUgram v${{ steps.version.outputs.version }}
generate_release_notes: true
body: |
Automated release for version `${{ steps.version.outputs.version }}`.
Published images:
- `ghcr.io/${{ github.repository_owner }}/hkugram-backend:${{ steps.version.outputs.version }}`
- `ghcr.io/${{ github.repository_owner }}/hkugram-frontend:${{ steps.version.outputs.version }}`
docker:
name: Build And Push Docker Images
runs-on: ubuntu-latest
needs: release
if: needs.release.outputs.tag_exists == 'false'
strategy:
matrix:
include:
- image_name: hkugram-backend
context: ./backend
dockerfile: ./backend/Dockerfile
- image_name: hkugram-frontend
context: ./frontend
dockerfile: ./frontend/Dockerfile
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository_owner }}/${{ matrix.image_name }}
tags: |
type=raw,value=${{ needs.release.outputs.version }}
type=raw,value=latest
- name: Build and push image
uses: docker/build-push-action@v6
with:
context: ${{ matrix.context }}
file: ${{ matrix.dockerfile }}
push: true
provenance: false
sbom: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}