Skip to content

Commit

Permalink
chore: add Taskfile.yml as alternative to make (bomctl#144)
Browse files Browse the repository at this point in the history
* chore: add Taskfile.yml to remove make dev dependency

Signed-off-by: Jonathan Howard <[email protected]>

* docs: update README

Signed-off-by: Jonathan Howard <[email protected]>

* chore: add lint:fix and lint:shell:fix tasks

Signed-off-by: Jonathan Howard <[email protected]>

* chore: windows fixes

Signed-off-by: Jonathan Howard <[email protected]>

* chore: windows fixes

Signed-off-by: Jonathan Howard <[email protected]>

* chore: more windows fixes

Signed-off-by: Jonathan Howard <[email protected]>

* chore: more windows fixes

Signed-off-by: Jonathan Howard <[email protected]>

* chore: windows zip file extraction fixes

Signed-off-by: Jonathan Howard <[email protected]>

* chore: windows path quoting fix

Signed-off-by: Jonathan Howard <[email protected]>

* chore: split into multiple taskfiles

Signed-off-by: Jonathan Howard <[email protected]>

---------

Signed-off-by: Jonathan Howard <[email protected]>
  • Loading branch information
jhoward-lm authored Aug 29, 2024
1 parent dc319c6 commit e1ba1f7
Show file tree
Hide file tree
Showing 8 changed files with 476 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
!/.markdownlint.yml
!/.markdownlintignore
!/.pre-commit-config.yaml
!/.taskfiles/*.yml
!/.vscode/adr.code-snippets
!/.vscode/extensions.json
!/.vscode/header.code-snippets
Expand All @@ -27,6 +28,7 @@
!/docs/**/*.md
!/docs/images/*.png
!/docs/images/*.svg
!/Taskfile.yml

# Whitelist patterns found anywhere in project
!.gitignore
Expand Down
108 changes: 108 additions & 0 deletions .taskfiles/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# ------------------------------------------------------------------------
# SPDX-FileCopyrightText: Copyright © 2024 bomctl a Series of LF Projects, LLC
# SPDX-FileName: .taskfiles/build.yml
# SPDX-FileType: SOURCE
# SPDX-License-Identifier: Apache-2.0
# ------------------------------------------------------------------------
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ------------------------------------------------------------------------
---
# yaml-language-server: $schema=https://taskfile.dev/schema.json

version: "3"

env:
GO111MODULE: "on"
GOPATH:
sh: go env GOPATH
GOPROXY: https://proxy.golang.org,direct
LDFLAGS: -s -w
-X=github.com/bomctl/bomctl/cmd.VersionMajor={{.VERSION_MAJOR}}
-X=github.com/bomctl/bomctl/cmd.VersionMinor={{.VERSION_MINOR}}
-X=github.com/bomctl/bomctl/cmd.VersionPatch={{.VERSION_PATCH}}
-X=github.com/bomctl/bomctl/cmd.VersionPre={{.VERSION_PRE}}
-X=github.com/bomctl/bomctl/cmd.BuildDate={{.BUILD_DATE}}

vars:
BUILD_DATE: '{{dateInZone "2006-01-02T15:04:05Z" (now) "UTC"}}'
GIT_SHA:
sh: git rev-parse HEAD
VERSION:
sh: '{{default "Undefined" "git describe --tags --abbrev=0"}}'
VERSION_REGEX: v(\d+)\.(\d+)\.(\d+)
VERSION_MAJOR: '{{regexReplaceAll .VERSION_REGEX .VERSION "${1}"}}'
VERSION_MINOR: '{{regexReplaceAll .VERSION_REGEX .VERSION "${2}"}}'
VERSION_PATCH: '{{regexReplaceAll .VERSION_REGEX .VERSION "${3}"}}'

tasks:
gobuild:
internal: true
generates:
- "{{.OUTPUT}}"
env:
CGO_ENABLED: 0
GOOS: "{{.GOOS}}"
GOARCH: "{{.GOARCH}}"
vars:
OUTPUT: '{{joinPath "dist" (list .GOOS .GOARCH | join "-") "bomctl"}}{{.EXT}}'
cmd: go build -trimpath -o {{.OUTPUT}} -ldflags="${LDFLAGS}"

linux:amd:
desc: Build for Linux on AMD64
cmd:
task: gobuild
vars:
GOOS: linux
GOARCH: amd64

linux:arm:
desc: Build for Linux on ARM
cmd:
task: gobuild
vars:
GOOS: linux
GOARCH: arm64

macos:intel:
desc: Build for macOS on AMD64
cmd:
task: gobuild
vars:
GOOS: darwin
GOARCH: amd64

macos:apple:
desc: Build for macOS on ARM
cmd:
task: gobuild
vars:
GOOS: darwin
GOARCH: arm64

windows:amd:
desc: Build for Windows on AMD64
cmd:
task: gobuild
vars:
EXT: .exe
GOOS: windows
GOARCH: amd64

windows:arm:
desc: Build for Windows on ARM
cmd:
task: gobuild
vars:
EXT: .exe
GOOS: windows
GOARCH: arm64
52 changes: 52 additions & 0 deletions .taskfiles/fix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# ------------------------------------------------------------------------
# SPDX-FileCopyrightText: Copyright © 2024 bomctl a Series of LF Projects, LLC
# SPDX-FileName: .taskfiles/fix.yml
# SPDX-FileType: SOURCE
# SPDX-License-Identifier: Apache-2.0
# ------------------------------------------------------------------------
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ------------------------------------------------------------------------
---
# yaml-language-server: $schema=https://taskfile.dev/schema.json

version: "3"

includes:
lint:
internal: true
taskfile: lint.yml

tasks:
go:
desc: Fix golangci-lint findings
cmd:
task: lint:run
vars:
CLI_NAME: golangci-lint{{exeExt}}
CLI_ARGS: [run, --fix, --verbose]

markdown:
desc: Fix markdown lint findings
cmd:
task: lint:run
vars:
CLI_NAME: markdownlint-cli2
CLI_ARGS: [--fix, "{{catLines .MARKDOWN_FILES}}"]

shell:
desc: Fix shell script lint findings
cmd:
task: lint:run
vars:
CLI_NAME: shfmt{{exeExt}}
CLI_ARGS: [--write, --simplify, "{{catLines .SHELL_FILES}}"]
106 changes: 106 additions & 0 deletions .taskfiles/install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# ------------------------------------------------------------------------
# SPDX-FileCopyrightText: Copyright © 2024 bomctl a Series of LF Projects, LLC
# SPDX-FileName: .taskfiles/install.yml
# SPDX-FileType: SOURCE
# SPDX-License-Identifier: Apache-2.0
# ------------------------------------------------------------------------
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ------------------------------------------------------------------------
---
# yaml-language-server: $schema=https://taskfile.dev/schema.json

version: "3"

vars:
GOLANGCI_LINT_VERSION: v1.60.3
GOLANGCI_LINT_RELEASE_URL: https://github.com/golangci/golangci-lint/releases/download/{{.GOLANGCI_LINT_VERSION}}
SHELLCHECK_ARCH: '{{eq ARCH "amd64" | ternary "x86_64" "aarch64"}}'
SHELLCHECK_VERSION: v0.10.0
SHELLCHECK_RELEASE_URL: https://github.com/koalaman/shellcheck/releases/download/{{.SHELLCHECK_VERSION}}
SHFMT_VERSION: v3.9.0

tasks:
make-tools-dir:
silent: true
status:
- test -d {{.TOOLS_DIR}}
cmds:
- cmd: mkdir {{.TOOLS_DIR}}
platforms: [darwin, linux]

- cmd: powershell -Command '$null = New-Item -ItemType directory -Path {{shellQuote .TOOLS_DIR}}'
platforms: [windows]

unzip-windows:
internal: true
platforms: [windows]
cmd: powershell -Command 'Add-Type -Assembly System.IO.Compression.FileSystem;
$zip = [IO.Compression.ZipFile]::OpenRead("{{.ZIP_FILENAME}}");
$entry = $zip.Entries | Where-Object -Property Name -EQ "{{.EXE_FILENAME}}";
$target = {{shellQuote (joinPath .TOOLS_DIR .EXE_FILENAME)}};
[IO.Compression.ZipFileExtensions]::ExtractToFile($entry, $target)'

golangci-lint:
desc: Install golangci-lint
vars:
GOLANGCI_LINT_PREFIX: golangci-lint-{{trimPrefix "v" .GOLANGCI_LINT_VERSION}}-{{OS}}-{{ARCH}}
GOLANGCI_LINT_FILENAME: '{{.GOLANGCI_LINT_PREFIX}}{{if eq OS "windows"}}.zip{{else}}.tar.gz{{end}}'
GOLANGCI_LINT_DOWNLOAD_URL: "{{.GOLANGCI_LINT_RELEASE_URL}}/{{.GOLANGCI_LINT_FILENAME}}"
status:
- test -x "{{shellQuote .TOOLS_DIR}}/golangci-lint{{exeExt}}"
cmds:
- task: make-tools-dir
- cmd: curl --fail --silent --show-error --location --url {{.GOLANGCI_LINT_DOWNLOAD_URL}} --remote-name
- defer: "{{.RM}} {{.GOLANGCI_LINT_FILENAME}}"
- cmd: tar --extract --gzip --file {{.GOLANGCI_LINT_FILENAME}} --directory {{.TOOLS_DIR}}
--strip-components=1 {{.GOLANGCI_LINT_PREFIX}}/golangci-lint
platforms: [darwin, linux]
- task: unzip-windows
vars:
ZIP_FILENAME: "{{.GOLANGCI_LINT_FILENAME}}"
EXE_FILENAME: golangci-lint.exe

shellcheck:
desc: Install shellcheck
vars:
SHELLCHECK_PREFIX: shellcheck-{{.SHELLCHECK_VERSION}}
SHELLCHECK_EXTENSION: '{{if eq OS "windows"}}.zip{{else}}.{{OS}}.{{.SHELLCHECK_ARCH}}.tar.xz{{end}}'
SHELLCHECK_FILENAME: "{{.SHELLCHECK_PREFIX}}{{.SHELLCHECK_EXTENSION}}"
SHELLCHECK_DOWNLOAD_URL: "{{.SHELLCHECK_RELEASE_URL}}/{{.SHELLCHECK_FILENAME}}"
status:
- test -x "{{shellQuote .TOOLS_DIR}}/shellcheck{{exeExt}}"
cmds:
- task: make-tools-dir
- cmd: curl --fail --silent --show-error --location --url {{.SHELLCHECK_DOWNLOAD_URL}} --remote-name
- defer: "{{.RM}} {{.SHELLCHECK_FILENAME}}"
- cmd: tar --extract --xz --file {{.SHELLCHECK_FILENAME}} --directory {{.TOOLS_DIR}}
--strip-components=1 {{.SHELLCHECK_PREFIX}}/shellcheck
platforms: [darwin, linux]
- task: unzip-windows
vars:
ZIP_FILENAME: "{{.SHELLCHECK_FILENAME}}"
EXE_FILENAME: shellcheck.exe

shfmt:
desc: Install shfmt
vars:
SHFMT_FILENAME: shfmt_{{.SHFMT_VERSION}}_{{OS}}_{{ARCH}}{{exeExt}}
SHFMT_DOWNLOAD_URL: https://github.com/mvdan/sh/releases/download/{{.SHFMT_VERSION}}/{{.SHFMT_FILENAME}}
status:
- test -x "{{shellQuote .TOOLS_DIR}}/shfmt{{exeExt}}"
cmds:
- task: make-tools-dir
- cmd: curl --fail --silent --show-error --location
--url {{.SHFMT_DOWNLOAD_URL}}
--output {{.TOOLS_DIR}}/shfmt{{exeExt}}
- cmd: '{{if ne OS "windows"}}chmod +x {{.TOOLS_DIR}}/shfmt{{end}}'
80 changes: 80 additions & 0 deletions .taskfiles/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# ------------------------------------------------------------------------
# SPDX-FileCopyrightText: Copyright © 2024 bomctl a Series of LF Projects, LLC
# SPDX-FileName: .taskfiles/lint.yml
# SPDX-FileType: SOURCE
# SPDX-License-Identifier: Apache-2.0
# ------------------------------------------------------------------------
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ------------------------------------------------------------------------
---
# yaml-language-server: $schema=https://taskfile.dev/schema.json

version: "3"

env:
BOLD: \033[1m
CYAN: \033[36m
YELLOW: \033[33m
RESET: \033[0m

tasks:
run:
silent: true
dir: "{{.ROOT_DIR}}"
vars:
CLI_ARGS: '{{.CLI_ARGS | join " "}}'
cmd: >
export PATH="{{shellQuote .TOOLS_DIR}}{{eq OS "windows" | ternary ";" ":"}}{{env "PATH"}}";
if command -v {{.CLI_NAME}} > /dev/null; then
printf "Running ${CYAN}{{.CLI_NAME}} {{.CLI_ARGS}}${RESET}\n";
{{.CLI_NAME}} {{.CLI_ARGS}};
else
printf "${YELLOW}{{.CLI_NAME}} not found, please install and run the command again.${RESET}\n";
fi
go:
desc: Lint Golang code files
cmd:
task: run
vars:
CLI_NAME: golangci-lint{{exeExt}}
CLI_ARGS: [run, --verbose]

markdown:
desc: Lint markdown files
cmd:
task: run
vars:
CLI_NAME: markdownlint-cli2
CLI_ARGS: "{{catLines .MARKDOWN_FILES}}"

shell:
desc: Lint shell scripts
cmds:
- task: run
vars:
CLI_NAME: shellcheck{{exeExt}}
CLI_ARGS: ["{{catLines .SHELL_FILES}}"]

- task: run
vars:
CLI_NAME: shfmt{{exeExt}}
CLI_ARGS: [--diff, --simplify, "{{catLines .SHELL_FILES}}"]

yaml:
desc: Lint YAML files
cmd:
task: run
vars:
CLI_NAME: yamllint
CLI_ARGS: ["{{catLines .YAML_FILES}}"]
1 change: 1 addition & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"mtxr.sqltools",
"redhat.vscode-xml",
"redhat.vscode-yaml",
"task.vscode-task",
"timonwong.shellcheck",
"usernamehw.errorlens",
"VisualStudioExptTeam.vscodeintellicode",
Expand Down
Loading

0 comments on commit e1ba1f7

Please sign in to comment.