Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions .github/workflows/build-and-push-ghcr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Build and Push Docker Image to GHCR

on:
push:
tags:
- "v*.*.*"
workflow_dispatch:

jobs:
build-go:
Copy link
Contributor

@sathirak sathirak Jul 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ShehanChamudith can you modify the github actions scripts so that we use two seperate scripts for build-go and docker build (example: build.yml, docker.yml). Docker build needs be be referenced like below from the build.yml and should only be run on tag releases. But build should run on PR to main and Push to main and also on tag releases

   trigger-docker-build:
     needs: [build-go]
     if: github.ref == 'refs/heads/main'
     uses: ./.github/workflows/docker.yml
     secrets: inherit

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.24'

- name: Build
run: go build -v ./...

- name: Test
run: go test -v ./...

build-and-push:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ShehanChamudith Make a build workflow that runs before Build and Push to Docker. after the go build is complete, run Build and Push to Docker.

needs: build-go
runs-on: ubuntu-latest
if: ${{ github.ref_type == 'tag' }}

permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to GitHub Container Registry (GHCR)
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract semver version
id: extract_version
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT

- name: Build and push Docker image with GHA cache
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ghcr.io/${{ github.repository_owner }}/pulsebridge:${{ steps.extract_version.outputs.VERSION }}
cache-from: type=gha
cache-to: type=gha,mode=max