Skip to content

Commit 35a7fb8

Browse files
committed
Adding condition before pushing the newly built image (3)...
1 parent 9a31f0b commit 35a7fb8

File tree

1 file changed

+18
-29
lines changed

1 file changed

+18
-29
lines changed

.github/workflows/ci.yaml

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,55 +2,44 @@ name: ci
22

33
on:
44
push:
5-
branches:
6-
- main
5+
branches: [main]
76
pull_request:
87

9-
#tags:
10-
# - v*
11-
128
env:
139
IMAGE_NAME: mdt-dialout-collector
1410

1511
jobs:
16-
ci:
12+
build:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v3
16+
17+
- name: Build image
18+
run: docker build docker --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}"
19+
20+
push:
21+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
22+
needs: build
1723
runs-on: ubuntu-latest
1824
permissions:
1925
packages: write
2026
contents: read
21-
2227
steps:
2328
- uses: actions/checkout@v3
2429

25-
- name: Build image
30+
- name: Build image again
2631
run: docker build docker --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}"
2732

28-
- name: Log into registry
29-
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
30-
run: |
31-
TOKEN="$GHCR_PAT"
32-
if [ -z "$TOKEN" ]; then
33-
echo "GHCR_PAT is not available"
34-
exit 1
35-
fi
36-
echo "$TOKEN" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
33+
- name: Log in to GHCR
3734
env:
3835
GHCR_PAT: ${{ secrets.GHCR_PAT }}
36+
run: |
37+
echo "$GHCR_PAT" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
3938
4039
- name: Push image
41-
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
4240
run: |
4341
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
44-
45-
# Change all uppercase to lowercase
46-
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
47-
# Strip git ref prefix from version
48-
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
49-
# Strip "v" prefix from tag name
50-
#[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
51-
# Use Docker `latest` tag convention
52-
[ "$VERSION" == "main" ] && VERSION=latest
53-
echo IMAGE_ID=$IMAGE_ID
54-
echo VERSION=$VERSION
42+
IMAGE_ID=$(echo "$IMAGE_ID" | tr '[A-Z]' '[a-z]')
43+
VERSION=latest
5544
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
5645
docker push $IMAGE_ID:$VERSION

0 commit comments

Comments
 (0)