Skip to content

Refactors log statement positioning in cleanupSingleDPDKInterface #116

Refactors log statement positioning in cleanupSingleDPDKInterface

Refactors log statement positioning in cleanupSingleDPDKInterface #116

name: Build and Push Beta Docker Image
on:
push:
branches:
- 'sandbox-*'
- 'beta-*'
- 'feature-*'
- 'dev-*'
- 'fix/*'
# Allow manual triggering with branch input
workflow_dispatch:
inputs:
branch:
description: 'Branch name to build from'
required: true
default: 'sandbox-testv0.1'
beta_version:
description: 'Beta version tag (e.g., beta.1)'
required: true
default: 'beta.1'
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
GOTOOLCHAIN: auto
jobs:
build-and-push-beta:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
actions: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.branch || github.ref }}
fetch-depth: 0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23'
check-latest: true
# Add Go module caching
- name: Go Module Cache
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Prepare go.mod for CI
run: |
# Remove toolchain directive for CI compatibility
sed -i '/^toolchain/d' go.mod
# Run tests in parallel
- name: Run unit tests
run: go test -v -parallel 4 ./pkg/... -coverprofile=coverage.txt -covermode=atomic
- name: Display test coverage
run: go tool cover -func=coverage.txt
- name: Upload coverage report
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: coverage.txt
retention-days: 7
- name: Extract branch name
shell: bash
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
# For manual workflow, use the provided branch name
BRANCH_NAME="${{ github.event.inputs.branch }}"
else
# For push events, extract from GITHUB_REF
BRANCH_NAME=${GITHUB_REF#refs/heads/}
fi
echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_ENV
# Also set as output for the step
echo "branch_name=${BRANCH_NAME}" >> $GITHUB_OUTPUT
id: extract_branch
- name: Generate beta version
id: beta_version
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
# Use the manually provided beta version
BETA_VERSION="${{ github.event.inputs.beta_version }}"
else
# Generate a beta version based on branch name and short SHA
SHORT_SHA=$(git rev-parse --short HEAD)
BRANCH_SUFFIX=$(echo "${{ steps.extract_branch.outputs.branch_name }}" | sed 's/[^a-zA-Z0-9]/-/g')
BETA_VERSION="beta.${BRANCH_SUFFIX}.${SHORT_SHA}"
fi
echo "BETA_VERSION=${BETA_VERSION}" >> $GITHUB_ENV
# Also set as output for the step
echo "beta_version=${BETA_VERSION}" >> $GITHUB_OUTPUT
echo "Generated beta version: ${BETA_VERSION}"
- name: Check Go version in Dockerfile and go.mod
run: |
echo "Checking Go version in Dockerfile..."
GO_VERSION_DOCKERFILE=$(grep "FROM golang:" Dockerfile | head -1 | cut -d':' -f2 | cut -d'-' -f1)
echo "Go version in Dockerfile: $GO_VERSION_DOCKERFILE"
echo "Checking Go version in go.mod..."
GO_VERSION_GOMOD=$(grep "^go " go.mod | awk '{print $2}')
echo "Go version in go.mod: $GO_VERSION_GOMOD"
# Check for toolchain directive
if grep -q "^toolchain " go.mod; then
TOOLCHAIN_DIRECTIVE=$(grep "^toolchain " go.mod | awk '{print $2}')
echo "Toolchain directive found in go.mod: $TOOLCHAIN_DIRECTIVE"
else
echo "No toolchain directive found in go.mod"
fi
if [[ "$GO_VERSION_DOCKERFILE" != "$GO_VERSION_GOMOD" ]]; then
echo "Warning: Go version mismatch between Dockerfile ($GO_VERSION_DOCKERFILE) and go.mod ($GO_VERSION_GOMOD)"
echo "This is expected and will be handled by the GOTOOLCHAIN=auto setting"
fi
echo "GOTOOLCHAIN environment variable is set to: $GOTOOLCHAIN"
env:
GOTOOLCHAIN: auto
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ github.token }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=${{ steps.beta_version.outputs.beta_version }}
type=raw,value=beta-${{ steps.extract_branch.outputs.branch_name }}
type=raw,value=beta-latest
type=sha,prefix=beta-
- name: Build and push Docker image
uses: docker/build-push-action@v5
env:
DOCKER_BUILDKIT: 1
GOTOOLCHAIN: auto
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
GOTOOLCHAIN=auto
SKIP_TESTS=true
SKIP_UPX=false
cache-from: type=gha,scope=${{ github.workflow }}
cache-to: type=gha,mode=max,scope=${{ github.workflow }}
platforms: linux/amd64
provenance: false
outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=false
build-contexts: |
golang:1.23-alpine=docker-image://golang:1.23-alpine
- name: Display image information
run: |
echo "::notice::Beta image built and pushed successfully!"
echo "::notice::Image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.beta_version.outputs.beta_version }}"
echo "::notice::Branch: ${{ steps.extract_branch.outputs.branch_name }}"
echo "::notice::Commit: ${{ github.sha }}"
echo "::notice::You can pull this image with: docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.beta_version.outputs.beta_version }}"
echo "::notice::All tags pushed:"
echo "${{ steps.meta.outputs.tags }}" | tr '\n' ' '