Skip to content

Commit

Permalink
add release version to build and display on page
Browse files Browse the repository at this point in the history
  • Loading branch information
pk910 committed Aug 24, 2023
1 parent 090df72 commit 4757c41
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 4 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/_shared-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
name: Reusable build workflow
on:
workflow_call:
inputs:
release:
description: 'Release version tag for this build'
default: ''
required: false
type: string

# shared build jobs
jobs:
Expand All @@ -25,6 +31,7 @@ jobs:
# build binaries
- name: Build linux binary
run: |
export RELEASE='${{ inputs.release }}'
make linux
# upload artifacts
Expand Down Expand Up @@ -54,6 +61,7 @@ jobs:
# build binaries
- name: Build windows binary
run: |
set RELEASE='${{ inputs.release }}'
make windows
# upload artifacts
Expand Down Expand Up @@ -83,6 +91,7 @@ jobs:
# build binaries
- name: Build macos binary
run: |
export RELEASE='${{ inputs.release }}'
make darwin
# upload artifacts
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/build-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ jobs:
build_binaries:
name: "Build binaries"
uses: ./.github/workflows/_shared-build.yaml
with:
release: "snapshot"

create_snapshot_release:
name: Create snapshot release
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ jobs:
build_binaries:
name: "Build binaries"
uses: ./.github/workflows/_shared-build.yaml
with:
release: "v${{ inputs.version }}"

create_release:
name: Create Release
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ jobs:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build version specific docker image
run: docker build . --file Dockerfile --tag pk910/light-beaconchain-explorer:${{ github.event.release.tag_name }}
run: docker build . --build-arg release=${{ github.event.release.tag_name }} --file Dockerfile --tag pk910/light-beaconchain-explorer:${{ github.event.release.tag_name }}
- name: Push version specific docker image
run: docker push pk910/light-beaconchain-explorer:${{ github.event.release.tag_name }}
- name: Build latest docker image
run: docker build . --file Dockerfile --tag pk910/light-beaconchain-explorer:latest
run: docker build . --build-arg release=${{ github.event.release.tag_name }} --file Dockerfile --tag pk910/light-beaconchain-explorer:latest
- name: Push latest docker image
run: docker push pk910/light-beaconchain-explorer:latest
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ WORKDIR /src
RUN go mod download
ADD . /src
ARG target=linux
ARG release=
ENV RELEASE=$release
RUN make $target

# final stage
Expand Down
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ LINUX=$(EXECUTABLE)_linux_amd64
DARWIN=$(EXECUTABLE)_darwin_amd64
VERSION := $(shell git rev-parse --short HEAD)
BUILDTIME := $(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
VERSION := $(shell git rev-parse --short HEAD)

GOLDFLAGS += -X 'github.com/pk910/light-beaconchain-explorer/utils.BuildVersion=$(VERSION)'
GOLDFLAGS += -X 'github.com/pk910/light-beaconchain-explorer/utils.Buildtime=$(BUILDTIME)'
GOLDFLAGS += -X 'github.com/pk910/light-beaconchain-explorer/utils.BuildVersion="$(VERSION)"'
GOLDFLAGS += -X 'github.com/pk910/light-beaconchain-explorer/utils.Buildtime="$(BUILDTIME)"'
GOLDFLAGS += -X 'github.com/pk910/light-beaconchain-explorer/utils.BuildRelease="$(RELEASE)"'

.PHONY: all test clean

Expand Down
1 change: 1 addition & 0 deletions cmd/explorer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func main() {
logger.WithFields(logger.Fields{
"config": *configPath,
"version": utils.BuildVersion,
"release": utils.BuildRelease,
"chainName": utils.Config.Chain.Config.ConfigName}).Printf("starting")

if utils.Config.Chain.Config.SlotsPerEpoch == 0 || utils.Config.Chain.Config.SecondsPerSlot == 0 {
Expand Down
6 changes: 6 additions & 0 deletions handlers/pageData.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ func InitPageData(w http.ResponseWriter, r *http.Request, active, path, title st
MainMenuItems: createMenuItems(active, isMainnet),
}

if utils.BuildRelease == "" {
data.Version = fmt.Sprintf("git-%v", utils.BuildVersion)
} else {
data.Version = fmt.Sprintf("%v (git-%v)", utils.BuildRelease, utils.BuildVersion)
}

acceptedLangs := strings.Split(r.Header.Get("Accept-Language"), ",")
if len(acceptedLangs) > 0 {
if strings.Contains(acceptedLangs[0], "ru") || strings.Contains(acceptedLangs[0], "RU") {
Expand Down
1 change: 1 addition & 0 deletions utils/buildinfo.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package utils

var BuildVersion string
var BuildRelease string
var Buildtime string

0 comments on commit 4757c41

Please sign in to comment.