Skip to content

Merge pull request #321 from 7navyasa/main #190

Merge pull request #321 from 7navyasa/main

Merge pull request #321 from 7navyasa/main #190

name: Build and Publish
on:
push:
branches: [ main ]
tags: [ 'v*' ]
pull_request:
branches: [ main ]
env:
KO_DOCKER_REPO: ghcr.io/${{ github.repository }}/controller
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.24'
- name: Install Dependencies
run: |
go mod download
go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.16.2
go install sigs.k8s.io/kustomize/kustomize/v5@v5.2.1
go install github.com/google/ko@latest
- name: Run tests
run: make test WHAT=unit
- name: Log in to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set Release Version
run: |
if [[ $GITHUB_REF == refs/tags/v* ]]; then
# Trim the 'v' prefix from the tag
echo "RELEASE_VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
else
echo "RELEASE_VERSION=dev-$(git rev-parse --short HEAD)" >> $GITHUB_ENV
fi
# Build and push image on push to main
- name: Build and Push Image
if: github.event_name != 'pull_request'
run: |
make publish-image
# Build image only on PR
- name: Build Image (PR)
if: github.event_name == 'pull_request'
run: |
make build-image
# Push helm chart only on tag
- name: Package and Push Helm Chart
if: github.ref_type == 'tag'
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | helm registry login ghcr.io -u ${{ github.actor }} --password-stdin
# Use sed compatible with Linux (GitHub Actions runners)
cp ./config/crd/bases/* helm/crds/
sed -i "s/tag: .*/tag: \"${RELEASE_VERSION}\"/" helm/values.yaml
sed -i "s/version: .*/version: ${RELEASE_VERSION}/" helm/Chart.yaml
sed -i "s/appVersion: .*/appVersion: \"${RELEASE_VERSION}\"/" helm/Chart.yaml
helm package helm
HELM_IMAGE=ghcr.io/${{ github.repository }} make publish-helm