Skip to content

Commit

Permalink
build(release): publish the archives so they can be downloaded
Browse files Browse the repository at this point in the history
  • Loading branch information
aybabtme committed Oct 19, 2024
1 parent d6ad70f commit e7ade33
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 45 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/release-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,21 @@ jobs:
with:
go-version: ">=1.23"
cache: true
- run: echo "${HOME}/.humanlog/bin" >> $GITHUB_PATH
- run: curl https://humanlog.dev/install_apictl.sh | bash
- uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: latest
args: release --clean --draft --snapshot --config .goreleaser-dev.yaml
args: release --clean --draft --skip validate --config .goreleaser-dev.yaml
env:
GITHUB_TOKEN: ${{ secrets.GORELEASER_GITHUB_TOKEN }}
- run: echo "${HOME}/.humanlog/bin" >> $GITHUB_PATH
- run: curl https://humanlog.dev/install_apictl.sh | bash
AWS_ACCESS_KEY_ID: ${{ secrets.S3_BINARIES_BUCKET_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.S3_BINARIES_BUCKET_ACCESS_KEY }}
- run: ./script/create_version_artifacts.sh
env:
CHANNEL: "dev"
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
API_URL: "https://api.humanlog.dev"
HMAC_KEY_ID: ${{ secrets.DEV_HMAC_KEY_ID }}
HMAC_PRIVATE_KEY: ${{ secrets.DEV_HMAC_PRIVATE_KEY }}
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Create a release

on:
workflow_dispatch:
push:
tags:
- "*"
Expand Down Expand Up @@ -34,5 +35,6 @@ jobs:
env:
CHANNEL: "main"
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
API_URL: "https://api.humanlog.io"
HMAC_KEY_ID: ${{ secrets.PROD_HMAC_KEY_ID }}
HMAC_PRIVATE_KEY: ${{ secrets.PROD_HMAC_PRIVATE_KEY }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
dist
debug.log
logdump.json
dist-extra
34 changes: 17 additions & 17 deletions .goreleaser-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ before:
hooks:
- go mod tidy
- go generate ./...
- mkdir -p dist-extra
- script/write_version_info.sh "{{.Major}}" "{{.Minor}}" "{{.Patch}}" "next.{{ .CommitTimestamp }}" "{{.ShortCommit}}" "https://humanlog-binaries.sfo3.cdn.digitaloceanspaces.com/humanlog-binaries/{{ .ProjectName }}/dev/{{ .CommitTimestamp }}/{{ .ShortCommit }}"
builds:
- main: ./cmd/humanlog/
binary: humanlog
env:
- CGO_ENABLED=0
ldflags:
- -s -w -X main.versionMajor={{.Major}} -X main.versionMinor={{.Minor}} -X main.versionPatch={{.Patch}} -X main.versionPrerelease={{.Prerelease}} -X main.versionBuild={{.ShortCommit}} -X main.defaultApiAddr="https://api.humanlog.dev"
- -s -w -X main.versionMajor={{.Major}} -X main.versionMinor={{.Minor}} -X main.versionPatch={{.Patch}} -X main.versionPrerelease=next.{{ .CommitTimestamp }} -X main.versionBuild={{.ShortCommit}} -X main.defaultApiAddr="https://api.humanlog.dev"
goos:
# - windows
- darwin
Expand All @@ -19,26 +21,24 @@ builds:
- amd64
- arm64
release:
github:
owner: humanlogio
name: humanlog
target_commitish: "{{ .Commit }}"
prerelease: true
disable: true
blobs:
- provider: s3
endpoint: https://humanlog-binaries.sfo3.digitaloceanspaces.com
region: sfo3
bucket: humanlog-binaries
directory: "{{ .ProjectName }}/dev/{{ .CommitTimestamp }}/{{ .ShortCommit }}"
include_meta: true
acl: public-read
cache_control:
- max-age=9999
- public
archives:
- name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
- name_template: "{{ .ProjectName }}_{{ incpatch .Version }}-next.{{ .CommitTimestamp }}+{{ .ShortCommit }}_{{ .Os }}_{{ .Arch }}"
format_overrides:
- goos: windows
format: zip
checksum:
name_template: "checksums.txt"
snapshot:
version_template: "{{ incpatch .Version }}-next.{{ .Timestamp }}.{{ .ShortCommit }}"
changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"

# modelines, feel free to remove those if you don't want/use them:
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
15 changes: 14 additions & 1 deletion cmd/humanlog/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/99designs/keyring"
"github.com/aybabtme/rgbterm"
"github.com/blang/semver"
"github.com/charmbracelet/huh"
types "github.com/humanlogio/api/go/types/v1"
"github.com/humanlogio/humanlog"
"github.com/humanlogio/humanlog/internal/pkg/config"
Expand All @@ -40,7 +41,11 @@ var (
version = func() *types.Version {
var prerelease []string
if versionPrerelease != "" {
prerelease = append(prerelease, versionPrerelease)
for _, pre := range strings.Split(versionPrerelease, ".") {
if pre != "" {
prerelease = append(prerelease, pre)
}
}
}
return &types.Version{
Major: int32(mustatoi(versionMajor)),
Expand Down Expand Up @@ -228,6 +233,14 @@ func newApp() *cli.App {
ServiceName: keyringName,
KeychainSynchronizable: true,
FileDir: stateDir,
FilePasswordFunc: func(s string) (pwd string, err error) {
err = huh.NewInput().
EchoMode(huh.EchoModePassword).
Title("Saving humanlog.io credentials...").
Description("Choose a password to encrypt your credentials").
Value(&pwd).Run()
return pwd, err
},
})

}
Expand Down
89 changes: 65 additions & 24 deletions script/create_version_artifacts.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

set -euo pipefail
set -euox pipefail

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

Expand All @@ -11,10 +11,20 @@ function list_archives() {
function handle_archive() {
while read -r filename; read -r path; read -r goos; read -r goarch; do
local url=$(get_archive_url ${filename})
if [ -z "${url}" ]; then echo "no archive for ${filename}"; continue; fi
local sig=$(get_signature ${path})
if [ -z "${url}" ]; then
echo "no archive for ${filename}";
exit 1;
fi

apictl create version-artifact \
local sig=$(get_signature ${root}/${path})

local extra_flags=""

if [ -f dist-extra/version.json ]; then
extra_flags="--pre $(get_prerelease) --build $(get_build)"
fi

apictl --api.url ${api_url} create version-artifact \
--project ${project} \
--major $(get_version_major) \
--minor $(get_version_minor) \
Expand All @@ -23,24 +33,28 @@ function handle_archive() {
--url ${url} \
--os ${goos} \
--arch ${goarch} \
--sig ${sig}
--sig ${sig} ${extra_flags}
done
}

function get_archive_url() {
local filename=${1}
gh api graphql -F owner=${owner} -F name=${project} -F tag="v${tag}" -F filename=${filename} -f query='
query($name: String!, $owner: String!, $tag: String!, $filename: String!) {
repository(name: $name, owner: $owner) {
release(tagName: $tag) {
releaseAssets(first: 1, name: $filename) {
nodes {
downloadUrl
if [ -f dist-extra/version.json ]; then
echo $(jq < dist-extra/version.json -r '.archive_base_url')/${filename}
else
gh api graphql -F owner=${owner} -F name=${project} -F tag="v${tag}" -F filename=${filename} -f query='
query($name: String!, $owner: String!, $tag: String!, $filename: String!) {
repository(name: $name, owner: $owner) {
release(tagName: $tag) {
releaseAssets(first: 1, name: $filename) {
nodes {
downloadUrl
}
}
}
}
}
}' --jq '.data.repository.release.releaseAssets.nodes[0].downloadUrl'
}' --jq '.data.repository.release.releaseAssets.nodes[0].downloadUrl'
fi
}

function get_sha256sum() {
Expand All @@ -49,47 +63,74 @@ function get_sha256sum() {
}

function get_signature() {
local filename=${1}
cat ${filename}.sig
local filename=${1}.sig
if [ -f "${filename}" ]; then cat < ${filename};
else echo "no-signature"; fi
}

function get_version_major() {
major=`echo ${tag} | cut -d. -f1`
echo "${major}"
if [ -f dist-extra/version.json ]; then
jq < dist-extra/version.json -r '.major'
else
major=`echo ${tag} | cut -d. -f1`
echo "${major}"
fi
}

function get_version_minor() {
minor=`echo ${tag} | cut -d. -f2`
echo "${minor}"
if [ -f dist-extra/version.json ]; then
jq < dist-extra/version.json -r '.minor'
else
minor=`echo ${tag} | cut -d. -f2`
echo "${minor}"
fi
}

function get_version_patch() {
patch=`echo ${tag} | cut -d. -f3`
echo "${patch}"
if [ -f dist-extra/version.json ]; then
jq < dist-extra/version.json -r '.patch'
else
patch=`echo ${tag} | cut -d. -f3`
echo "${patch}"
fi

}

function get_version() {
jq < dist/metadata.json -r '.version'
if [ -f dist-extra/version.json ]; then
jq < dist-extra/version.json -r '.version'
else
jq < dist/metadata.json -r '.version'
fi
}

function get_project_name() {
jq < dist/metadata.json -r '.project_name'
}

function get_prerelease() {
jq < dist-extra/version.json -r '.pre'
}

function get_build() {
jq < dist-extra/version.json -r '.build'
}

function get_channel() {
local channel=${CHANNEL:-main}
echo ${channel}
}

function main() {
owner=humanlogio
api_url=${API_URL:-"https://api.humanlog.io"}
project=$(get_project_name)
tag=$(get_version)
channel=$(get_channel)

list_archives | handle_archive

apictl create published-version \
apictl --api.url ${api_url} create published-version \
--project ${project} \
--channel ${channel} \
--version $(get_version)
Expand Down
18 changes: 18 additions & 0 deletions script/write_version_info.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

set -euox pipefail

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

function main() {
major=${1}
minor=${2}
patch=${3}
pre=${4}
build=${5}
archive_base_url=${6}
mkdir -p ${root}/dist-extra
echo > ${root}/dist-extra/version.json "{\"version\":\"${major}.${minor}.${patch}-${pre}+${build}\",\"major\": \"${major}\",\"minor\": \"${minor}\",\"patch\": \"${patch}\",\"pre\": \"${pre}\",\"build\": \"${build}\",\"archive_base_url\": \"${archive_base_url}\"}"
}

main ${1} ${2} ${3} ${4} ${5} ${6}

0 comments on commit e7ade33

Please sign in to comment.