Skip to content

feat(build): Add ability to generate image tag based on github tag #27

feat(build): Add ability to generate image tag based on github tag

feat(build): Add ability to generate image tag based on github tag #27

Workflow file for this run

name: Build and Push Docker Image
on:
push:
branches:
- master
tags:
- v*
pull_request:
branches:
- master
env:
VERSION: latest
jobs:
build:
name: Build Go Application
runs-on: ubuntu-latest
steps:
# Checkout the repository
- name: Checkout Code
uses: actions/checkout@v3
# Set up Go environment
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.23
# Build the application
- name: Build Go Application
run: |
go mod tidy
go build -o app .
docker-build:
name: Build Docker Image
runs-on: ubuntu-latest
needs: build # Ensure this job runs after "build"
steps:
# Checkout the repository
- name: Checkout Code
uses: actions/checkout@v3
# Build the Docker image
- name: Build Docker Image
run: make image VERSION=$VERSION
push:
name: Push Docker Image to Docker Hub
runs-on: ubuntu-latest
needs: [build, docker-build] # Ensure this job runs after "build" and "docker-build"
# Only run for "push" events and on the owner repository, not for "pull_request"
if: github.event_name == 'push' && github.repository_owner == 'r3kzi'
steps:
# Checkout the repository
- name: Checkout Code
uses: actions/checkout@v3
# Build the Docker image
- name: Build Docker Image
run: |
[[ "${{ github.ref_type }}" == "tag" ]] && VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,;s/^v//')
echo "VERSION=$VERSION" >> $GITHUB_ENV
make image VERSION=$VERSION IMAGE_EXTRA_ARGS='--label "runnumber=${GITHUB_RUN_ID}"'
# Log in to Docker Hub
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
# Push the Docker image
- name: Push Docker Image
run: make push VERSION=$VERSION"