2024-04-16 15:02:03 +08:00
|
|
|
---
|
|
|
|
|
|
|
|
name: 🏗️
|
|
|
|
|
|
|
|
on: # yamllint disable-line rule:truthy
|
|
|
|
pull_request:
|
|
|
|
push:
|
|
|
|
branches: ["release/*", "unstable/*"]
|
2024-05-28 02:39:55 +08:00
|
|
|
workflow_dispatch:
|
|
|
|
inputs:
|
|
|
|
tag:
|
2024-09-15 02:05:40 +08:00
|
|
|
description: Docker image tag
|
|
|
|
required: true
|
2024-05-28 02:39:55 +08:00
|
|
|
type: string
|
2024-04-16 15:02:03 +08:00
|
|
|
|
|
|
|
jobs:
|
|
|
|
build-and-push:
|
|
|
|
runs-on: ubuntu-latest
|
2024-04-19 10:01:29 +08:00
|
|
|
timeout-minutes: 10
|
2024-04-16 15:02:03 +08:00
|
|
|
steps:
|
|
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Build Docker image
|
|
|
|
run: |
|
2024-09-08 02:28:31 +08:00
|
|
|
DOCKER_TAG="${DOCKER_TAG/'/'/'-'}"
|
|
|
|
DOCKER_TAG_MAJOR=$(echo "$DOCKER_TAG" | cut -d '.' -f 1)
|
|
|
|
DOCKER_TAG_MAJOR_MINOR=$(echo "$DOCKER_TAG" | cut -d '.' -f 1-2)
|
|
|
|
IMAGE="ghcr.io/$GITHUB_REPOSITORY:${DOCKER_TAG}"
|
|
|
|
IMAGE_MAJOR="ghcr.io/$GITHUB_REPOSITORY:${DOCKER_TAG_MAJOR}"
|
|
|
|
IMAGE_MAJOR_MINOR="ghcr.io/$GITHUB_REPOSITORY:${DOCKER_TAG_MAJOR_MINOR}"
|
2024-04-16 15:02:03 +08:00
|
|
|
echo "IMAGE=$IMAGE" >>"$GITHUB_ENV"
|
2024-09-08 02:28:31 +08:00
|
|
|
echo "IMAGE_MAJOR=$IMAGE_MAJOR" >>"$GITHUB_ENV"
|
|
|
|
echo "IMAGE_MAJOR_MINOR=$IMAGE_MAJOR_MINOR" >>"$GITHUB_ENV"
|
2024-04-16 15:02:03 +08:00
|
|
|
docker build . \
|
|
|
|
--build-arg BUILDKIT_INLINE_CACHE=1 \
|
|
|
|
--cache-from $IMAGE \
|
|
|
|
--tag $IMAGE
|
2024-09-08 02:28:31 +08:00
|
|
|
docker tag $IMAGE $IMAGE_MAJOR
|
|
|
|
docker tag $IMAGE $IMAGE_MAJOR_MINOR
|
2024-05-28 02:39:55 +08:00
|
|
|
env:
|
|
|
|
DOCKER_TAG: ${{ inputs.tag || github.ref_name }}
|
2024-04-27 07:08:30 +08:00
|
|
|
- name: Log in to GHCR
|
2024-04-16 15:02:03 +08:00
|
|
|
if: github.event_name != 'pull_request'
|
2024-05-28 02:00:48 +08:00
|
|
|
run: >-
|
2024-04-16 15:02:03 +08:00
|
|
|
echo ${{ secrets.GITHUB_TOKEN }} |
|
|
|
|
docker login ghcr.io -u $GITHUB_ACTOR --password-stdin
|
2024-04-27 07:08:30 +08:00
|
|
|
- name: Push Docker image to GHCR
|
|
|
|
if: github.event_name != 'pull_request'
|
2024-09-08 02:28:31 +08:00
|
|
|
run: |
|
|
|
|
docker push $IMAGE
|
|
|
|
docker push $IMAGE_MAJOR
|
|
|
|
docker push $IMAGE_MAJOR_MINOR
|