-
Notifications
You must be signed in to change notification settings - Fork 1
47 lines (39 loc) · 1.42 KB
/
Copy pathdockerimage.yaml
File metadata and controls
47 lines (39 loc) · 1.42 KB
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
name: Build and Push Docker Image to GHCR
on:
push:
branches:
- '**' # Now triggers on every commit to any branch
tags:
- '*' # Keeps triggering on tags
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Log in to GitHub Container Registry
# Logic check: Only log in if the push is a tag
if: github.ref_type == 'tag'
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin
- name: Extract Tag Name
id: tag
run: |
# If it's a tag, use it. If it's a branch, use a fallback name for the build.
if [ "${{ github.ref_type }}" = "tag" ]; then
echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
else
echo "TAG=local-check" >> $GITHUB_ENV
fi
- name: Build Docker Image
run: |
docker build -t ghcr.io/weselben/freshware:${{ env.TAG }} .
- name: Push Docker Image
# Logic check: Only push if the push is a tag
if: github.ref_type == 'tag'
run: |
docker tag ghcr.io/weselben/freshware:${{ env.TAG }} ghcr.io/weselben/freshware:latest
docker push ghcr.io/weselben/freshware:${{ env.TAG }}
docker push ghcr.io/weselben/freshware:latest