From 1e8465df8ea2cf61ff0397aeabf20a1713811a62 Mon Sep 17 00:00:00 2001 From: ItsNotGoodName Date: Sun, 17 Dec 2023 17:58:21 -0800 Subject: [PATCH] feat: fix build version and update build --- Makefile | 3 +++ Taskfile.yml | 43 +++++++++++++++++++++------------------ cmd/radiomux-demo/main.go | 2 +- cmd/radiomux/main.go | 2 +- internal/build/build.go | 32 ++++++++++++++++++++--------- 5 files changed, 50 insertions(+), 32 deletions(-) diff --git a/Makefile b/Makefile index 3102fec..2cf54c4 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,9 @@ gen: gen-proto gen-openapi gen-webrpc tooling: tooling-air tooling-goreleaser tooling-protoc-gen-go tooling-oapi-codegen tooling-webrpc tooling-java tooling-taskfile +build: + task build + # Docker docker-build-demo: diff --git a/Taskfile.yml b/Taskfile.yml index c9fdb6c..ee45a30 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -3,11 +3,16 @@ version: "3" +vars: + CMD_NAME: radiomux + PACKAGE_NAME: "github.com/ItsNotGoodName/radiomux" + APK_NAME: radiomuxplayer + tasks: clean: cmds: - rm -rf dist - - mkdir -p dist/artifacts + - mkdir dist dist/artifacts dist/files dist/files-windows build-apk: internal: true @@ -20,7 +25,7 @@ tasks: - echo $ANDROID_KEYSTORE | base64 --decode > my-release-key.jks - apksigner sign --ks my-release-key.jks --ks-pass env:ANDROID_KEYSTORE_PASSWORD --out {{.RELEASE_DIR}}/app-release.apk {{.RELEASE_DIR}}/app-release-unsigned-aligned.apk - apksigner verify {{.RELEASE_DIR}}/app-release.apk - - cp {{.RELEASE_DIR}}/app-release.apk ../dist/radiomuxplayer-release.apk + - cp {{.RELEASE_DIR}}/app-release.apk ../dist/{{.APK_NAME}}-release.apk vars: RELEASE_DIR: app/build/outputs/apk/release env: @@ -33,7 +38,7 @@ tasks: cmds: - chmod +x gradlew - ./gradlew :app:assembleDebug -x test - - cp {{.DEBUG_DIR}}/app-debug.apk ../dist/radiomuxplayer-debug.apk + - cp {{.DEBUG_DIR}}/app-debug.apk ../dist/{{.APK_NAME}}-debug.apk vars: DEBUG_DIR: app/build/outputs/apk/debug @@ -42,25 +47,23 @@ tasks: cmds: - go mod tidy - go generate ./... - - GOOS=linux GOARCH=amd64 go build -ldflags="{{.LDFLAGS}}" -o ./dist/radiomux_Linux_x86_64 {{.MAIN_PACKAGE}} - - GOOS=linux GOARCH=arm GOARM=7 go build -ldflags="{{.LDFLAGS}}" -o ./dist/radiomux_Linux_armv7 {{.MAIN_PACKAGE}} - - GOOS=linux GOARCH=arm64 go build -ldflags="{{.LDFLAGS}}" -o ./dist/radiomux_Linux_arm64 {{.MAIN_PACKAGE}} - - GOOS=darwin GOARCH=arm64 go build -ldflags="{{.LDFLAGS}}" -o ./dist/radiomux_Darwin_arm64 {{.MAIN_PACKAGE}} - - GOOS=windows GOARCH=amd64 go build -ldflags="{{.LDFLAGS}}" -o ./dist/radiomux_Windows_x86_64.exe {{.MAIN_PACKAGE}} + - GOOS=linux GOARCH=amd64 go build -ldflags="{{.MAIN_LDFLAGS}}" -o ./dist/{{.CMD_NAME}}_Linux_x86_64/{{.CMD_NAME}} {{.MAIN_PACKAGE}} + - GOOS=linux GOARCH=arm GOARM=7 go build -ldflags="{{.MAIN_LDFLAGS}}" -o ./dist/{{.CMD_NAME}}_Linux_armv7/{{.CMD_NAME}} {{.MAIN_PACKAGE}} + - GOOS=linux GOARCH=arm64 go build -ldflags="{{.MAIN_LDFLAGS}}" -o ./dist/{{.CMD_NAME}}_Linux_arm64/{{.CMD_NAME}} {{.MAIN_PACKAGE}} + - GOOS=darwin GOARCH=arm64 go build -ldflags="{{.MAIN_LDFLAGS}}" -o ./dist/{{.CMD_NAME}}_Darwin_arm64/{{.CMD_NAME}} {{.MAIN_PACKAGE}} + - GOOS=windows GOARCH=amd64 go build -ldflags="{{.MAIN_LDFLAGS}}" -o ./dist/{{.CMD_NAME}}_Windows_x86_64/{{.CMD_NAME}}.exe {{.MAIN_PACKAGE}} env: CGO_ENABLED: 0 vars: - PACKAGE_NAME: "github.com/ItsNotGoodName/radiomux" - - BUILD_PACKAGE_NAME: "{{.PACKAGE_NAME}}/internal/build/build" + BUILD_PACKAGE_NAME: "{{.PACKAGE_NAME}}/internal/build" BUILD_VERSION: "nightly" BUILD_DATE: '{{now | date "2006-01-02T15:04:05Z07:00"}}' BUILD_COMMIT: sh: git rev-parse HEAD BUILD_REPO_URL: "https://{{.PACKAGE_NAME}}" - LDFLAGS: -s -w -X {{.BUILD_PACKAGE_NAME}}.Version={{.BUILD_VERSION}} -X {{.BUILD_PACKAGE_NAME}}.Commit={{.BUILD_COMMIT}} -X {{.BUILD_PACKAGE_NAME}}.Date={{.BUILD_DATE}} -X {{.BUILD_PACKAGE_NAME}}.RepoURL={{.BUILD_REPO_URL}} - MAIN_PACKAGE: "{{.PACKAGE_NAME}}/cmd/radiomux" + MAIN_LDFLAGS: -s -w -X {{.BUILD_PACKAGE_NAME}}.version={{.BUILD_VERSION}} -X {{.BUILD_PACKAGE_NAME}}.commit={{.BUILD_COMMIT}} -X {{.BUILD_PACKAGE_NAME}}.date={{.BUILD_DATE}} -X {{.BUILD_PACKAGE_NAME}}.repoURL={{.BUILD_REPO_URL}} + MAIN_PACKAGE: "{{.PACKAGE_NAME}}/cmd/{{.CMD_NAME}}" compile-artifacts: internal: true @@ -68,14 +71,14 @@ tasks: cmds: - cp *.apk artifacts/ - for: { var: FILES } - cmd: cp ../{{.ITEM}} . + cmd: cp ../{{.ITEM}} "./files/$(basename {{.ITEM}})" - for: { var: WINDOWS_FILES } - cmd: cp ../{{.ITEM}} . - - tar -czf artifacts/radiomux_Linux_x86_64.tar.gz radiomux_Linux_x86_64 {{.FILES}} - - tar -czf artifacts/radiomux_Linux_armv7.tar.gz radiomux_Linux_armv7 {{.FILES}} - - tar -czf artifacts/radiomux_Linux_arm64.tar.gz radiomux_Linux_arm64 {{.FILES}} - - tar -czf artifacts/radiomux_Darwin_arm64.tar.gz radiomux_Darwin_arm64 {{.FILES}} - - zip -q artifacts/radiomux_Windows_x86_64.zip radiomux_Windows_x86_64.exe {{.FILES}} {{.WINDOWS_FILES}} + cmd: cp ../{{.ITEM}} "./files-windows/$(basename {{.ITEM}})" + - cd {{.CMD_NAME}}_Linux_x86_64 && cp ../files/* . && tar -czf ../artifacts/{{.CMD_NAME}}_Linux_x86_64.tar.gz * + - cd {{.CMD_NAME}}_Linux_armv7 && cp ../files/* . && tar -czf ../artifacts/{{.CMD_NAME}}_Linux_armv7.tar.gz * + - cd {{.CMD_NAME}}_Linux_arm64 && cp ../files/* . && tar -czf ../artifacts/{{.CMD_NAME}}_Linux_arm64.tar.gz * + - cd {{.CMD_NAME}}_Darwin_arm64 && cp ../files/* . && tar -czf ../artifacts/{{.CMD_NAME}}_Darwin_arm64.tar.gz * + - cd {{.CMD_NAME}}_Windows_x86_64 && cp ../files/* . && cp ../files-windows/* . && zip -q ../artifacts/{{.CMD_NAME}}_Windows_x86_64.zip * - cd artifacts && sha256sum *.tar.gz *.zip *.apk > checksum.txt vars: FILES: README.md LICENSE diff --git a/cmd/radiomux-demo/main.go b/cmd/radiomux-demo/main.go index e211c43..52c7775 100644 --- a/cmd/radiomux-demo/main.go +++ b/cmd/radiomux-demo/main.go @@ -34,7 +34,7 @@ func main() { app := lieut.NewSingleCommandApp( lieut.AppInfo{ Name: "radiomux", - Version: build.Version, + Version: build.Current.Version, }, run(cfg), flags, diff --git a/cmd/radiomux/main.go b/cmd/radiomux/main.go index 6a810ef..c1b6c45 100644 --- a/cmd/radiomux/main.go +++ b/cmd/radiomux/main.go @@ -36,7 +36,7 @@ func main() { app := lieut.NewSingleCommandApp( lieut.AppInfo{ Name: "radiomux", - Version: build.Version, + Version: build.Current.Version, }, run(cfg), flags, diff --git a/internal/build/build.go b/internal/build/build.go index 7c6b9d9..75ff304 100644 --- a/internal/build/build.go +++ b/internal/build/build.go @@ -1,18 +1,30 @@ package build var ( - Version string - Commit string - Date string - RepoURL string + commit = "" + date = "" + version = "dev" + repoURL = "" ) -var ( +func init() { + Current = Build{ + Commit: commit, + Date: date, + Version: version, + RepoURL: repoURL, + CommitURL: repoURL + "/tree/" + commit, + LicenseURL: repoURL + "/blob/master/LICENSE", + } +} + +var Current Build + +type Build struct { + Commit string + Version string + Date string + RepoURL string CommitURL string LicenseURL string -) - -func init() { - CommitURL = RepoURL + "/tree/" + Commit - LicenseURL = RepoURL + "/blob/master/LICENSE" }