Skip to content

Commit cfea157

Browse files
author
mmahipal
committed
changed Github actions to use branch name as tag
1 parent c983165 commit cfea157

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

.github/workflows/github-actions.yml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ env:
1010
# Use docker.io for Docker Hub if empty
1111
REGISTRY: ghcr.io
1212
# github.repository as <account>/<repo>
13-
IMAGE_NAME: ${{ github.repository }}
13+
IMAGE: ${{ github.repository }}
1414

1515

1616
jobs:
@@ -35,13 +35,26 @@ jobs:
3535
username: ${{ github.actor }}
3636
password: ${{ secrets.GITHUB_TOKEN }}
3737

38+
# extract branch name
39+
- name: Extract branch name
40+
if: github.event_name != 'pull_request'
41+
shell: bash
42+
run: echo "::set-env name=BRANCH_NAME::$(echo ${GITHUB_REF#refs/heads/})"
43+
id: extract_branch
44+
45+
# extract branch name on pull request
46+
- name: Extract branch name
47+
if: github.event_name == 'pull_request'
48+
run: echo "::set-env name=BRANCH_NAME::$(echo ${GITHUB_HEAD_REF})"
49+
3850
# Build and push Operator image (don't push on PR)
3951
- name: Build and push Docker image
4052
run: |
4153
make generate
4254
make manifests
43-
IMAGE=${${{ env.IMAGE_NAME }},,}
44-
make docker-build IMG="${{ env.REGISTRY }}/${IMAGE}:${GITHUB_REF##*/}"
45-
docker push "${{ env.REGISTRY }}/${IMAGE}:${GITHUB_REF##*/}"
46-
docker rmi "${{ env.REGISTRY }}/${IMAGE}:${GITHUB_REF##*/}" && docker system prune -f
55+
IMAGE_NAME=${{ env.IMAGE }}
56+
IMAGE_NAME=${IMAGE,,}
57+
make docker-build IMG="${{ env.REGISTRY }}/${IMAGE_NAME}:${BRANCH_NAME}"
58+
docker push "${{ env.REGISTRY }}/${IMAGE_NAME}:${BRANCH_NAME}"
59+
docker rmi "${{ env.REGISTRY }}/${IMAGE_NAME}:${BRANCH_NAME}" && docker system prune -f
4760
rm -rf bin/

0 commit comments

Comments
 (0)