From a7bf2bd2f017107c83f7626ae5a6fe4870c4f69c Mon Sep 17 00:00:00 2001 From: Layla Manley Date: Thu, 7 Dec 2023 20:25:11 +0100 Subject: [PATCH] CI Work --- .drone.yaml | 34 ++++++++++++++++++++++++++++++++++ .gitignore | 18 ++++++++++++++++++ Taskfile.yml | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ magefile.go | 22 ---------------------- main.go | 7 +++++-- 5 files changed, 109 insertions(+), 24 deletions(-) create mode 100644 .drone.yaml create mode 100644 .gitignore create mode 100644 Taskfile.yml delete mode 100644 magefile.go diff --git a/.drone.yaml b/.drone.yaml new file mode 100644 index 0000000..d5a9018 --- /dev/null +++ b/.drone.yaml @@ -0,0 +1,34 @@ + +kind: pipeline +type: docker +name: Build and Release +when: + # branch: + # - main + event: + - tag + +steps: + - name: install-taskfile + image: golang:1.21 + commands: + - sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d + - name: build + image: golang:1.21 + commands: + - task package + - name: release + image: plugins/gitea-release + settings: + base_url: https://gitea.layla.gg + api_key: + from_secret: gitea_api_key + repo: layla/gsquash + files: + - ./dist/gsquash.tar.gz +--- +kind: secret +name: gitea_api_key +get: + path: secret/synology/gitea + name: token \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3b29eef --- /dev/null +++ b/.gitignore @@ -0,0 +1,18 @@ + +# Go binaries and executables +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Go test and coverage files +*.test +*.out +*.cover + +# Go build and dependency directories +/bin/ +/pkg/ +/vendor/ +/dist/ \ No newline at end of file diff --git a/Taskfile.yml b/Taskfile.yml new file mode 100644 index 0000000..518c415 --- /dev/null +++ b/Taskfile.yml @@ -0,0 +1,52 @@ +# https://taskfile.dev + +version: '3' + +tasks: + test: + cmds: + - go test -v ./... + silent: true + desc: Run unit tests + clean: + cmds: + - go clean + - rm -rf ./bin + silent: true + desc: Remove build artifacts and clean up + build: + env: + VERSION: '{{.VERSION | default "0.0.0"}}' + cmds: + - go build -ldflags "-X main.Version=${VERSION}" -o ./bin/gsquash ./main.go + silent: true + package: + deps: + - build + cmds: + - mkdir -p ./dist + - tar -czvf ./dist/gsquash.tar.gz ./bin/gsquash + silent: true + desc: Package the binary into a tarball + install: + deps: + - build + cmds: + - cmd: sudo cp ./bin/gsquash /usr/local/bin/gsquash + platforms: + - darwin + - linux + - cmd: | + cp ./bin/gsquash.exe /Program Files(x86)/gsquash/gsquash.exe + setx PATH "%PATH%;C:\Program Files(x86)\gsquash" + platforms: + - windows + silent: true + desc: Install the binary into /usr/local/bin + default: + deps: + - test + - clean + - build + silent: true + desc: Run tests, clean up and build \ No newline at end of file diff --git a/magefile.go b/magefile.go deleted file mode 100644 index 18a8b13..0000000 --- a/magefile.go +++ /dev/null @@ -1,22 +0,0 @@ -//go:build mage - -package main - -import ( - "github.com/magefile/mage/sh" -) - -// Build builds the binary -func Build() error { - return sh.RunV("go", "build", "-o", "gsquash", "main.go") -} - -// Install installs the binary -func Install() error { - return sh.RunV("go", "install") -} - -// Test runs the tests -func Test() error { - return sh.RunV("go", "test", "./...") -} diff --git a/main.go b/main.go index 3663308..9b8c45c 100644 --- a/main.go +++ b/main.go @@ -2,17 +2,20 @@ package main import ( "flag" + "fmt" "os" "gitea.layla.gg/layla/gsquash/git" ) +var Version string = "0.0.1" + func main() { // Set flags flagset := flag.NewFlagSet("git", flag.ExitOnError) pull := flagset.Bool("pull", false, "Pull the latest changes from the remote") message := flagset.String("m", "", "The commit message") - version := flagset.Bool("version", false, "Print the version") + version := flagset.Bool("v", false, "Print the version") help := flagset.Bool("h", false, "Print the help") // Parse flags @@ -20,7 +23,7 @@ func main() { // Print version if *version { - println("gsquash v0.0.1") + fmt.Printf("gsquash version %s\n", Version) return }