From 811e38c0f26e0867abce582aa85490182112be18 Mon Sep 17 00:00:00 2001 From: Lucas Manuel Rodriguez Date: Thu, 7 Sep 2023 13:23:38 -0300 Subject: [PATCH] Add build info to orbit macos build action (#13796) --- .github/workflows/build-orbit.yaml | 7 ++++++- orbit/tools/build/build.go | 12 +++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build-orbit.yaml b/.github/workflows/build-orbit.yaml index 39d93341ad..e34676cdd0 100644 --- a/.github/workflows/build-orbit.yaml +++ b/.github/workflows/build-orbit.yaml @@ -1,4 +1,4 @@ -name: Build, Sign and Notarize Orbit +name: Build, Sign and Notarize Orbit for macOS on: workflow_dispatch: # allow manual action @@ -6,6 +6,9 @@ on: paths: - 'orbit/**.go' +env: + ORBIT_VERSION: 1.16.0 + # This allows a subsequently queued workflow run to interrupt previous runs concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id}} @@ -54,6 +57,8 @@ jobs: AC_PASSWORD: ${{ secrets.APPLE_PASSWORD }} AC_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }} CODESIGN_IDENTITY: 51049B247B25B3119FAE7E9C0CC4375A43E47237 + ORBIT_VERSION: ${{ env.ORBIT_VERSION }} + ORBIT_COMMIT: ${{ github.sha }} - name: Upload orbit uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v2 diff --git a/orbit/tools/build/build.go b/orbit/tools/build/build.go index 4332cd38a0..ef8b8c1750 100644 --- a/orbit/tools/build/build.go +++ b/orbit/tools/build/build.go @@ -12,6 +12,7 @@ import ( "os" "os/exec" "path/filepath" + "time" "github.com/fleetdm/fleet/v4/orbit/pkg/packaging" "github.com/fleetdm/fleet/v4/pkg/buildpkg" @@ -28,6 +29,10 @@ func main() { acPassword := os.Getenv("AC_PASSWORD") acTeamID := os.Getenv("AC_TEAM_ID") + version := os.Getenv("ORBIT_VERSION") + commit := os.Getenv("ORBIT_COMMIT") + date := time.Now().UTC().Format("2006-01-02T15:04:05Z") + codesign := false if codesignIdentity != "" { codesign = true @@ -48,10 +53,10 @@ func main() { binaryPath = "orbit-darwin" bundleIdentifier = "com.fleetdm.orbit" ) - if err := buildOrbit(amdBinaryPath, "amd64"); err != nil { + if err := buildOrbit(amdBinaryPath, "amd64", version, commit, date); err != nil { panic(err) } - if err := buildOrbit(armBinaryPath, "arm64"); err != nil { + if err := buildOrbit(armBinaryPath, "arm64", version, commit, date); err != nil { panic(err) } @@ -93,10 +98,11 @@ func main() { } } -func buildOrbit(binaryPath, arch string) error { +func buildOrbit(binaryPath, arch, version, commit, date string) error { /* #nosec G204 -- arguments are actually well defined */ buildExec := exec.Command("go", "build", "-o", binaryPath, + "-ldflags", fmt.Sprintf("-X github.com/fleetdm/fleet/v4/orbit/pkg/build.Version=%s -X github.com/fleetdm/fleet/v4/orbit/pkg/build.Commit=%s -X github.com/fleetdm/fleet/v4/orbit/pkg/build.Date=%s", version, commit, date), "./"+filepath.Join("orbit", "cmd", "orbit"), ) buildExec.Env = append(os.Environ(), "GOOS=darwin", "GOARCH="+arch)