Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

feat: tag action image & print commit hash (#16080)

p0ny6b2ad2e58c9d
diff --git a/.github/workflows/build-push-action-image.yml b/.github/workflows/build-push-action-image.yml
index 3e847b60e7..84bccebfa6 100644
--- a/.github/workflows/build-push-action-image.yml
+++ b/.github/workflows/build-push-action-image.yml
@@ -2,12 +2,29 @@ name: Build push action image
on:
workflow_dispatch:
+ push:
+ branches:
+ - 'release/*.*.*'
+
+concurrency:
+ group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
+ cancel-in-progress: true
jobs:
docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
+ - name: Extract build args
+ id: extract_build_args
+ run: |
+ if [[ "${{ github.ref_name }}" =~ ^release/[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
+ VERSION=$(echo "${{ github.ref_name }}" | sed 's/release\///')
+ else
+ VERSION="latest"
+ fi
+ echo "IMAGE_TAG=${VERSION}" >> $GITHUB_ENV
+ echo "GIT_COMMIT=$(git rev-parse HEAD)" >> $GITHUB_ENV
- name: Login to DockerHub
uses: docker/login-action@v3
with:
@@ -19,4 +36,7 @@ jobs:
context: .
file: scripts/Dockerfile.action
push: true
- tags: bytebase/bytebase-action:latest
+ tags: |
+ bytebase/bytebase-action:${{ env.IMAGE_TAG }}
+ build-args: |
+ GIT_COMMIT=${{ env.GIT_COMMIT }}
diff --git a/action/args/version.go b/action/args/version.go
new file mode 100644
index 0000000000..16597d61bd
--- /dev/null
+++ b/action/args/version.go
@@ -0,0 +1,3 @@
+package args
+
+var Gitcommit = "unknown"
diff --git a/action/main.go b/action/main.go
index 27b74b96ae..94d15de638 100644
--- a/action/main.go
+++ b/action/main.go
@@ -18,6 +18,7 @@ import (
"github.com/spf13/cobra"
"go.uber.org/multierr"
+ "github.com/bytebase/bytebase/action/args"
"github.com/bytebase/bytebase/action/github"
"github.com/bytebase/bytebase/backend/common/log"
v1pb "github.com/bytebase/bytebase/proto/generated-go/v1"
@@ -526,6 +527,7 @@ func waitForRollout(ctx context.Context, client *Client, rolloutPreview *v1pb.Ro
}
func main() {
+ slog.Info("bytebase-action built at commit " + args.Gitcommit)
ctx, cancel := context.WithCancel(context.Background())
c := make(chan os.Signal, 1)
// Trigger graceful shutdown on SIGINT or SIGTERM.
diff --git a/scripts/Dockerfile.action b/scripts/Dockerfile.action
index 284250c4ea..b96eab132d 100644
--- a/scripts/Dockerfile.action
+++ b/scripts/Dockerfile.action
@@ -1,8 +1,11 @@
FROM golang:1.24.2-alpine3.21 AS builder
+ARG GIT_COMMIT
WORKDIR /action-build
COPY action/ action/
COPY . .
-RUN go build -o bytebase-action action/*.go
+RUN go build \
+--ldflags="-X 'github.com/bytebase/bytebase/action/args.Gitcommit=${GIT_COMMIT}'" \
+-o bytebase-action action/*.go
FROM alpine:3.21
RUN apk update