From 7c2ddcff9f41c5ff82bb00ee9d77540168eca89d Mon Sep 17 00:00:00 2001 From: Scott Brown Date: Sun, 4 May 2025 18:41:57 -0600 Subject: [PATCH 1/2] Closes #14 by refactoring the taskfile --- Taskfile.yml | 194 ++++++++++++++++++++++++++++----------------------- 1 file changed, 107 insertions(+), 87 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index b6a9174..cb29db2 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -1,4 +1,4 @@ -version: '3' +version: 3 vars: REPO: github.com/scottbrown/pulse @@ -6,8 +6,6 @@ vars: DIST_DIR: .dist TEST_DIR: .test BINARY_NAME: pulse - COVERAGE_FILE: "{{.TEST_DIR}}/coverage.out" - COVERAGE_HTML: "{{.TEST_DIR}}/coverage.html" VERSION: sh: git rev-parse --abbrev-ref HEAD || echo "main" BUILD: @@ -22,11 +20,13 @@ tasks: clean: desc: Clean build artifacts + run: once cmds: - rm -rf {{.BUILD_DIR}} {{.DIST_DIR}} {{.TEST_DIR}} setup: desc: Create necessary directories + run: once cmds: - mkdir -p {{.BUILD_DIR}} - mkdir -p {{.DIST_DIR}} @@ -34,6 +34,7 @@ tasks: fmt: desc: Format Go code + run: once cmds: - go fmt ./... @@ -80,99 +81,118 @@ tasks: - go tool cover -html={{.COVERAGE_FILE}} -o {{.COVERAGE_HTML}} - go tool cover -func={{.COVERAGE_FILE}} - echo "Coverage report generated at {{.COVERAGE_HTML}}" - - install: - desc: Install the CLI application - deps: [build] - cmds: - - cp {{.BUILD_DIR}}/{{.BINARY_NAME}} $GOPATH/bin/ - - init-config: - desc: Initialize default configuration files - deps: [build] - cmds: - - mkdir -p ~/.pulse/config ~/.pulse/data - - cp config/metrics.yaml ~/.pulse/config/ - - cp config/levers.yaml ~/.pulse/config/ - - cp data/metrics.yaml ~/.pulse/data/ - - run: - desc: Run the CLI application - deps: [build] - cmds: - - ./{{.BUILD_DIR}}/{{.BINARY_NAME}} {{.CLI_ARGS}} - - run-report: - desc: Generate a security posture report - deps: [build] - cmds: - - ./{{.BUILD_DIR}}/{{.BINARY_NAME}} report {{.CLI_ARGS}} - - run-report-json: - desc: Generate a security posture report in JSON format - deps: [build] - cmds: - - ./{{.BUILD_DIR}}/{{.BINARY_NAME}} report --format json {{.CLI_ARGS}} - - run-category-report: - desc: Generate a report for a specific category - deps: [build] - cmds: - - ./{{.BUILD_DIR}}/{{.BINARY_NAME}} report --category {{.CATEGORY}} {{.CLI_ARGS}} - requires: - vars: [CATEGORY] - - run-list-metrics: - desc: List all available metrics - deps: [build] - cmds: - - ./{{.BUILD_DIR}}/{{.BINARY_NAME}} list metrics {{.CLI_ARGS}} - - run-list-categories: - desc: List all available categories - deps: [build] - cmds: - - ./{{.BUILD_DIR}}/{{.BINARY_NAME}} list categories {{.CLI_ARGS}} - - run-update-metric: - desc: Update a metric value - deps: [build] - cmds: - - ./{{.BUILD_DIR}}/{{.BINARY_NAME}} update --metric {{.METRIC}} --value {{.VALUE}} {{.CLI_ARGS}} - requires: - vars: [METRIC, VALUE] + vars: + COVERAGE_FILE: "{{.TEST_DIR}}/coverage.out" + COVERAGE_HTML: "{{.TEST_DIR}}/coverage.html" release: desc: Build release artifacts for multiple platforms - deps: [clean, setup] cmds: - # Ensure directories exist - - mkdir -p {{.BUILD_DIR}} - - mkdir -p {{.DIST_DIR}} - - # Build for Linux (amd64) - - GOOS=linux GOARCH=amd64 go build -ldflags "{{.BUILD_FLAGS}}" -o {{.BUILD_DIR}}/{{.BINARY_NAME}}-linux-amd64 {{.REPO}}/cmd - - tar -czf {{.DIST_DIR}}/{{.BINARY_NAME}}-linux-amd64.tar.gz -C {{.BUILD_DIR}} {{.BINARY_NAME}}-linux-amd64 + - task: clean + - task: setup + - task: release-darwin + - task: release-linux + - task: release-windows + + release-darwin: + cmds: [task: release-darwin-amd64, task: release-darwin-arm64] + release-linux: + cmds: [task: release-linux-amd64, task: release-linux-arm64] + release-windows: + cmds: [task: release-windows-amd64, task: release-windows-arm64] + + build-core: + internal: true + vars: + FLAGS: "-ldflags '{{.BUILD_FLAGS}}'" + env: + GOOS: "{{.GOOS}}" + GOARCH: "{{.GOARCH}}" + cmds: + - go build {{.FLAGS}} -o {{.BUILD_DIR}}/{{.GOOS}}-{{.GOARCH}}/{{.BINARY_NAME}}{{.FILE_EXT}} {{.REPO}}/cmd + + build-darwin-amd64: + deps: + - task: build-core + vars: { GOOS: darwin, GOARCH: amd64 } + + build-darwin-arm64: + deps: + - task: build-core + vars: { GOOS: darwin, GOARCH: arm64 } + + build-linux-amd64: + deps: + - task: build-core + vars: { GOOS: linux, GOARCH: amd64 } + + build-linux-arm64: + deps: + - task: build-core + vars: { GOOS: linux, GOARCH: arm64 } + + build-windows-amd64: + deps: + - task: build-core + vars: { GOOS: windows, GOARCH: amd64, FILE_EXT: ".exe" } + + build-windows-arm64: + deps: + - task: build-core + vars: { GOOS: windows, GOARCH: arm64, FILE_EXT: ".exe" } + + build-all: + deps: + - build-darwin-amd64 + - build-darwin-arm64 + - build-linux-amd64 + - build-linux-arm64 + - build-windows-amd64 + - build-windows-arm64 + + release-core: + internal: true + env: + GOOS: linux + GOARCH: amd64 + cmds: + - tar -czf {{.DIST_DIR}}/{{.BINARY_NAME}}-{{.GOOS}}-{{.GOARCH}}.tar.gz -C {{.BUILD_DIR}}/{{.GOOS}}-{{.GOARCH}} {{.BINARY_NAME}}{{.FILE_EXT}} + + release-linux-amd64: + cmds: + - task: build-linux-amd64 + - task: release-core + vars: { GOOS: linux, GOARCH: amd64 } - # Build for Linux (arm64) - - GOOS=linux GOARCH=arm64 go build -ldflags "{{.BUILD_FLAGS}}" -o {{.BUILD_DIR}}/{{.BINARY_NAME}}-linux-arm64 {{.REPO}}/cmd - - tar -czf {{.DIST_DIR}}/{{.BINARY_NAME}}-linux-arm64.tar.gz -C {{.BUILD_DIR}} {{.BINARY_NAME}}-linux-arm64 + release-linux-arm64: + cmds: + - task: build-linux-arm64 + - task: release-core + vars: { GOOS: linux, GOARCH: arm64 } - # Build for Windows (amd64) - - GOOS=windows GOARCH=amd64 go build -ldflags "{{.BUILD_FLAGS}}" -o {{.BUILD_DIR}}/{{.BINARY_NAME}}-windows-amd64.exe {{.REPO}}/cmd - - tar -czf {{.DIST_DIR}}/{{.BINARY_NAME}}-windows-amd64.tar.gz -C {{.BUILD_DIR}} {{.BINARY_NAME}}-windows-amd64.exe + release-windows-amd64: + cmds: + - task: build-windows-amd64 + - task: release-core + vars: { GOOS: windows, GOARCH: amd64, FILE_EXT: ".exe" } - # Build for Windows (arm64) - - GOOS=windows GOARCH=arm64 go build -ldflags "{{.BUILD_FLAGS}}" -o {{.BUILD_DIR}}/{{.BINARY_NAME}}-windows-arm64.exe {{.REPO}}/cmd - - tar -czf {{.DIST_DIR}}/{{.BINARY_NAME}}-windows-arm64.tar.gz -C {{.BUILD_DIR}} {{.BINARY_NAME}}-windows-arm64.exe + release-windows-arm64: + cmds: + - task: build-windows-arm64 + - task: release-core + vars: { GOOS: windows, GOARCH: arm64, FILE_EXT: ".exe" } - # Build for macOS (amd64) - - GOOS=darwin GOARCH=amd64 go build -ldflags "{{.BUILD_FLAGS}}" -o {{.BUILD_DIR}}/{{.BINARY_NAME}}-darwin-amd64 {{.REPO}}/cmd - - tar -czf {{.DIST_DIR}}/{{.BINARY_NAME}}-darwin-amd64.tar.gz -C {{.BUILD_DIR}} {{.BINARY_NAME}}-darwin-amd64 + release-darwin-amd64: + cmds: + - task: build-darwin-amd64 + - task: release-core + vars: { GOOS: darwin, GOARCH: amd64 } - # Build for macOS (arm64) - - GOOS=darwin GOARCH=arm64 go build -ldflags "{{.BUILD_FLAGS}}" -o {{.BUILD_DIR}}/{{.BINARY_NAME}}-darwin-arm64 {{.REPO}}/cmd - - tar -czf {{.DIST_DIR}}/{{.BINARY_NAME}}-darwin-arm64.tar.gz -C {{.BUILD_DIR}} {{.BINARY_NAME}}-darwin-arm64 + release-darwin-arm64: + cmds: + - task: build-darwin-arm64 + - task: release-core + vars: { GOOS: darwin, GOARCH: arm64 } all: desc: Run all tasks (clean, build, test, coverage) From fe50f2bfa4e580c0fa80fe9daaaa132053efac7b Mon Sep 17 00:00:00 2001 From: Scott Brown Date: Sun, 4 May 2025 22:41:42 -0600 Subject: [PATCH 2/2] Closes #15 by adding support for GH Actions --- Taskfile.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Taskfile.yml b/Taskfile.yml index cb29db2..4b5b9a7 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -7,7 +7,12 @@ vars: TEST_DIR: .test BINARY_NAME: pulse VERSION: - sh: git rev-parse --abbrev-ref HEAD || echo "main" + sh: | + if [ -n "$GITHUB_REF" ] && [[ "$GITHUB_REF" == refs/tags/* ]]; then + echo "${GITHUB_REF#refs/tags/}" + else + git rev-parse --abbrev-ref HEAD || echo "main" + fi BUILD: sh: git rev-parse --short HEAD || echo "unknown" BUILD_FLAGS: "-X {{.REPO}}.Version={{.VERSION}} -X {{.REPO}}.Build={{.BUILD}}"