Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
aybabtme committed Nov 5, 2024
1 parent 6ba0cdc commit 5693672
Show file tree
Hide file tree
Showing 3 changed files with 187 additions and 12 deletions.
61 changes: 49 additions & 12 deletions .github/workflows/release-dev-pro.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,71 @@ permissions:

jobs:
build:
name: "build"
strategy:
matrix:
go: [stable]
os:
- ubuntu-latest
- macos-latest
arch:
- arm64
- amd64
runs-on: ${{ matrix.os }}
targets:
- name: linux-amd64
runner: ubuntu-latest
goos: linux
goarch: amd64
- name: linux-arm64
runner: ubuntu-latest
goos: linux
goarch: arm64
goenvs: CC=aarch64-linux-gnu-gcc CXX=x86_64-linux-gnu-g++
preinstall: sudo apt install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
- name: darwin-amd64
runner: macos-latest
goos: darwin
goarch: amd64
- name: darwin-arm64
runner: macos-latest
goos: darwin
goarch: arm64
name: ${{ matrix.targets.name }}
runs-on: ${{ matrix.targets.runner }}
env:
GOPRIVATE: "github.com/humanlogio/humanlog-pro"
GH_ACCESS_TOKEN_FOR_HUMANLOGPRO: ${{ secrets.GH_ACCESS_TOKEN_FOR_HUMANLOGPRO }}
GOARCH: ${{ matrix.arch }}
CGO_ENABLED: 1
GOBIN: /usr/local/bin/
steps:
- name: Set up Go 1
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}
go-version: stable
cache: true
- uses: actions/checkout@v3
with:
fetch-depth: 0
- if: ${{ matrix.targets.preinstall != '' }}
run: ${{ matrix.targets.preinstall }}
- run: echo "${HOME}/.humanlog/bin" >> $GITHUB_PATH
- run: curl https://humanlog.io/install_apictl.sh | bash
- run: git config --global --add safe.directory '*'
- run: git config --global url.https://[email protected]/.insteadOf https://github.com/
- run: go install github.com/goware/modvendor@latest
- run: go mod vendor
- run: modvendor -copy="**/*.a **/*.h" -v
- run: go build -tags pro -o /tmp/humanlog-${{ matrix.os }}-${{ matrix.arch }} ./cmd/humanlog
- run: mkdir -p dist/${{ matrix.targets.goos }}-${{ matrix.targets.goarch }}
- run: ${{ matrix.targets.goenvs }} ./script/build.sh
env:
GOOS: ${{ matrix.targets.goos }}
GOARCH: ${{ matrix.targets.goarch }}
- run: mv dist/humanlog dist/${{ matrix.targets.goos }}-${{ matrix.targets.goarch }}/humanlog
- uses: actions/upload-artifact@v4
with:
name: humanlog_bins
path: dist/${{ matrix.targets.goos }}-${{ matrix.targets.goarch }}/humanlog

# publish:
# name: "publish"
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# with:
# fetch-depth: 0
# - uses: actions/download-artifact@v4
# with:
# name: humanlog_bins
# - run:
40 changes: 40 additions & 0 deletions .github/workflows/release-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,49 @@ permissions:
contents: write

jobs:
build:
name: "build"
strategy:
matrix:
go: [stable]
os:
- ubuntu-latest
- macos-latest
arch:
- arm64
- amd64
runs-on: ${{ matrix.os }}
env:
GOPRIVATE: "github.com/humanlogio/humanlog-pro"
GH_ACCESS_TOKEN_FOR_HUMANLOGPRO: ${{ secrets.GH_ACCESS_TOKEN_FOR_HUMANLOGPRO }}
GOARCH: ${{ matrix.arch }}
steps:
- name: Set up Go 1
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}
cache: true
- uses: actions/checkout@v3
with:
fetch-depth: 0
- run: git config --global --add safe.directory '*'
- run: git config --global url.https://[email protected]/.insteadOf https://github.com/
- run: git fetch --force --tags
- run: echo "${HOME}/.humanlog/bin" >> $GITHUB_PATH
- run: curl https://humanlog.dev/install_apictl.sh | bash
- run: go install github.com/goware/modvendor@latest
- run: go mod vendor
- run: modvendor -copy="**/*.a **/*.h" -v
- run: go
env:



create_a_dev_release:
name: create a dev release
runs-on: ubuntu-latest
container:
image: ghcr.io/goreleaser/goreleaser-cross:v1.23.2
env:
GOPRIVATE: "github.com/humanlogio/humanlog-pro"
GH_ACCESS_TOKEN_FOR_HUMANLOGPRO: ${{ secrets.GH_ACCESS_TOKEN_FOR_HUMANLOGPRO }}
Expand Down
98 changes: 98 additions & 0 deletions script/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/usr/bin/env bash

set -euox pipefail

root=$(git rev-parse --show-toplevel)

gotags="${HUMANLOG_GOTAGS:-}"
is_prod_build="${HUMANLOG_IS_PROD_BUILD:-}"
output_dir="${HUMANLOG_OUTDIR:-${root}/dist}"
output_bin="${HUMANLOG_OUTBIN:-humanlog}"
output_path="${output_dir}/${output_bin}"

function latest_git_tag() {
git describe --tags $(git rev-list --tags --max-count=1)
}

function git_commit_timestamp() {
git show --no-patch --format=%ct
}

function git_short_commit() {
git rev-parse --short HEAD
}

function current_version() {
apictl version to-json --version $(latest_git_tag) |
apictl version math build set $(git_short_commit)
}

function next_patch_version() {
current_version |
apictl version math patch add 1 |
apictl version math pre add next |
apictl version math pre add $(git_commit_timestamp)
}

function get_major() {
jq -r '.major // 0'
}

function get_minor() {
jq -r '.minor // 0'
}

function get_patch() {
jq -r '.patch // 0'
}

function get_pre() {
jq -r '.prereleases // [] | join(".")'
}

function get_build() {
jq -r '.build // ""'
}


function main() {

local flags="-o ${output_path} -trimpath"
if [[ ! -z "${gotags}" ]]; then
flags+=" -tags ${gotags}"
fi

ldflags="-s -w"

if [[ $(go env GOOS) == "linux" ]]; then
ldflags+=" -extldflags \"-lc -lrt -lpthread --static\""
fi

if [[ "${is_prod_build}" != "true" ]]; then
echo "setting version to $(next_patch_version | apictl version from-json)"
ldflags+=" -X main.versionMajor=$(next_patch_version | get_major)"
ldflags+=" -X main.versionMinor=$(next_patch_version | get_minor)"
ldflags+=" -X main.versionPatch=$(next_patch_version | get_patch)"
ldflags+=" -X main.versionBuild=$(next_patch_version | get_build)"
ldflags+=" -X main.versionPrerelease=$(next_patch_version | get_pre)"
ldflags+=" -X main.defaultApiAddr=https://api.humanlog.dev"
ldflags+=" -X main.defaultBaseSiteAddr=https://humanlog.dev"
else
echo "setting version to $(current_version | apictl version from-json)"
ldflags+=" -X main.versionMajor=$(current_version | get_major)"
ldflags+=" -X main.versionMinor=$(current_version | get_minor)"
ldflags+=" -X main.versionPatch=$(current_version | get_patch)"
ldflags+=" -X main.versionBuild=$(current_version | get_build)"
ldflags+=" -X main.defaultApiAddr=https://api.humanlog.io"
ldflags+=" -X main.defaultBaseSiteAddr=https://humanlog.io"
fi

flags+=" -ldflags=\"${ldflags}\""

eval go build ${flags} ./cmd/humanlog

eval ${output_path} --version
}


main

0 comments on commit 5693672

Please sign in to comment.