-
Notifications
You must be signed in to change notification settings - Fork 2
62 lines (55 loc) · 1.51 KB
/
build_image.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
50
51
52
53
54
55
56
57
58
59
60
61
62
# github actions
name: Publish to ghcr
on:
push:
branches:
- main
- feat/**
paths-ignore:
- '**.md'
workflow_dispatch:
permissions:
actions: write
contents: read
id-token: write
packages: write
env:
IMAGE_NAME: "ghcr.io/${{ github.repository }}"
jobs:
"build":
name: "build"
runs-on: "ubuntu-latest"
steps:
- uses: GitHubSecurityLab/actions-permissions/monitor@v1
with:
config: ${{ vars.PERMISSIONS_CONFIG }}
- uses: actions/[email protected]
- name: "Add sha to environment variable"
env:
FULL_SHA: "${{github.sha}}"
REF: "${{github.ref}}"
run: |
TAG=$(git log -1 --pretty=%ad --date=format:%Y-%m-%d)-$(git log --pretty=format:'%h' -n 1)
branch=$(echo $REF | cut -c12-)
if [ $branch = main ]
then
echo "IMAGE=$IMAGE_NAME:$TAG" >> $GITHUB_ENV
else
echo "IMAGE=$IMAGE_NAME-$branch:$TAG" >> $GITHUB_ENV
fi
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Docker Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ env.IMAGE }}
cache-from: type=gha
cache-to: type=gha,mode=max