forked from StormPacer/yatb
-
Notifications
You must be signed in to change notification settings - Fork 1
49 lines (45 loc) · 1.7 KB
/
ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
name: Build
on: [push]
jobs:
build:
name: Docker Build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Prepare
id: prepare
run: |
IMAGE_NAME=yatb
GIT_REPO='https://github.com/${{ github.repository }}'
DOCKER_USER=`echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]'`
DOCKER_IMAGE=ghcr.io/$DOCKER_USER/$IMAGE_NAME
VERSION=`git rev-parse --short HEAD`
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/v}
fi
echo ::set-output name=git_repo::${GIT_REPO}
echo ::set-output name=docker_user::${DOCKER_USER}
echo ::set-output name=docker_image::${DOCKER_IMAGE}
echo ::set-output name=version::${VERSION}
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ steps.prepare.outputs.docker_user }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and Push
uses: docker/build-push-action@v5
with:
context: .
push: ${{ (github.ref == 'refs/heads/master') || (contains(github.ref, 'refs/tags/') == true) }}
tags: |
${{ steps.prepare.outputs.docker_image }}:latest
${{ steps.prepare.outputs.docker_image }}:${{ steps.prepare.outputs.version }}
build-args: |
GIT_VERSION=${{ steps.prepare.outputs.version }}
GIT_REPO=${{ steps.prepare.outputs.git_repo }}
cache-from: type=gha
cache-to: type=gha,mode=max