Skip to content

Add build time and commit hash to serverlet binary #26

Add build time and commit hash to serverlet binary

Add build time and commit hash to serverlet binary #26

Workflow file for this run

# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
name: Go
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.22'
- name: Build
run: cd serverlet ; go build -v
- name: Test
run: go test -v ./...
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: serverlet
path: serverlet/serverlet
release:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.22'
- name: Build
run: |
BUILD_TIME=`date -u '+%Y-%m-%d_%H:%M:%S'`
COMMIT_HASH=`git rev-parse --short HEAD`
cd serverlet ; go build -v -ldflags "-s -w -X 'main.BuildTime=$BUILD_TIME' -X 'main.GitCommitHash=$COMMIT_HASH'"
- name: Test
run: go test -v ./...
- name: Upload Release Asset
run: |
RELEASE_ID=`curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/PichuChen/hatsuaki/releases/tags/nightly | jq '.id'`
curl -X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "Content-Type: application/octet-stream" \
--data-binary @serverlet/serverlet \
https://uploads.github.com/repos/PichuChen/hatsuaki/releases/$RELEASE_ID/assets?name=serverlet