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 75d8d19
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 5 deletions.
12 changes: 12 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 @@ -26,6 +32,8 @@ jobs:
- name: Build linux binary
run: |
make linux
env:
RELEASE: ${{ inputs.release }}

# upload artifacts
- name: "Upload artifact: explorer_linux_amd64"
Expand Down Expand Up @@ -55,6 +63,8 @@ jobs:
- name: Build windows binary
run: |
make windows
env:
RELEASE: ${{ inputs.release }}

# upload artifacts
- name: "Upload artifact: explorer_windows_amd64.exe"
Expand Down Expand Up @@ -84,6 +94,8 @@ jobs:
- name: Build macos binary
run: |
make darwin
env:
RELEASE: ${{ inputs.release }}

# upload artifacts
- name: "Upload artifact: explorer_darwin_amd64"
Expand Down
4 changes: 3 additions & 1 deletion .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 Expand Up @@ -141,6 +143,6 @@ jobs:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build unstable docker image
run: docker build . --file Dockerfile --tag pk910/light-beaconchain-explorer:unstable
run: docker build . --build-arg release=snapshot --file Dockerfile --tag pk910/light-beaconchain-explorer:unstable
- name: Push unstable docker image
run: docker push pk910/light-beaconchain-explorer:unstable
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 75d8d19

Please sign in to comment.