Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: release on windows #22

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/validations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,16 @@ jobs:
run: make pr-validations

WindowsValidations:
name: "Windows units"
name: "Windows validations"
runs-on: windows-2022
steps:
- uses: actions/checkout@v3

- name: install make
run: "choco install make"

- name: run units
- name: run tests
run: "make unit"

- name: run cli tests
run: "make cli"
28 changes: 13 additions & 15 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,15 @@ builds:
env:
- QUILL_LOG_FILE=/tmp/quill-{{ .Target }}.log

# not supported yet
# - id: windows-build
# dir: ./cmd/binny
# binary: binny
# goos:
# - windows
# goarch:
# - amd64
# mod_timestamp: *build-timestamp
# ldflags: *build-ldflags
- id: windows-build
dir: ./cmd/binny
binary: binny
goos:
- windows
goarch:
- amd64
mod_timestamp: *build-timestamp
ldflags: *build-ldflags

archives:
- id: linux-archives
Expand All @@ -61,11 +60,10 @@ archives:
builds:
- darwin-build

# not supported yet
# - id: windows-archives
# format: zip
# builds:
# - windows-build
- id: windows-archives
format: zip
builds:
- windows-build

sboms:
- artifacts: binary
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ make-default: $(TASK)
@$(TASK)

# for those of us that can't seem to kick the habit of typing `make ...` lets wrap the superior `task` tool
TASKS := $(shell bash -c "$(TASK) -l | grep '^\* ' | cut -d' ' -f2 | tr -d ':' | tr '\n' ' '" ) $(shell bash -c "$(TASK) -l | grep 'aliases:' | cut -d ':' -f 3 | tr '\n' ' ' | tr -d ','")
TASKS := $(shell $(TASK) -l -j | jq -r '[.tasks[] | .name, (.aliases // empty)[]] | unique | join(" ")')

.PHONY: $(TASKS)
$(TASKS): $(TASK)
Expand Down
17 changes: 13 additions & 4 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ vars:
CHANGELOG: CHANGELOG.md
NEXT_VERSION: VERSION
MAKEDIR_P: 'python -c "import sys; import os; os.makedirs(sys.argv[1], exist_ok=True)"'
TEST_F: 'python -c "import sys; import os; sys.exit(0) if os.path.isfile(sys.argv[1]) else sys.exit(1)"'
CAT: '{{ if eq OS "windows" }}type{{ else }}cat{{ end }}'
DOT_EXE: '{{ if eq OS "windows" }}.exe{{ else }}{{ end}}'
BINNY_FILENAME: '{{ .PROJECT }}{{ .DOT_EXE }}'
BINNY_PATH: '{{ .TOOL_DIR }}/{{ .BINNY_FILENAME }}'

tasks:

Expand All @@ -37,6 +42,7 @@ tasks:

test:
desc: Run all levels of test
deps: [tools]
cmds:
- task: unit
- task: cli
Expand All @@ -47,13 +53,16 @@ tasks:
internal: true
desc: Get the binny tool
generates:
- "{{ .TOOL_DIR }}/binny"
- "{{ .BINNY_PATH }}"
status:
- "test -f {{ .TOOL_DIR }}/binny"
- '{{ .TEST_F }} {{ .BINNY_PATH }}'
# we just need a release of binny, doesn't matter which one (binny will update itself, this is just a bootstrap step)
# note: on the first release of binny, switch to the curl approach
# cmd: "curl -sSfL https://raw.githubusercontent.com/{{ .OWNER }}/{{ .PROJECT }}/main/install.sh | sh -s -- -b {{ .TOOL_DIR }}"
cmd: "go build -o {{ .TOOL_DIR }}/binny ./cmd/binny"
cmds:
- cmd: '{{ .MAKEDIR_P }} {{ .TOOL_DIR }}'
- cmd: "go build -o {{ .BINNY_PATH }} ./cmd/binny"
- cmd: 'echo "Built binny a {{ .BINNY_PATH }}"' # TODO: just added for debugging
silent: true

tools:
Expand Down Expand Up @@ -175,7 +184,7 @@ tasks:
- silent: true
cmd: |
echo "dist: {{ .SNAPSHOT_DIR }}" > {{ .TMP_DIR }}/goreleaser.yaml
cat .goreleaser.yaml >> {{ .TMP_DIR }}/goreleaser.yaml
{{ .CAT }} .goreleaser.yaml >> {{ .TMP_DIR }}/goreleaser.yaml

- "{{ .TOOL_DIR }}/goreleaser release --clean --skip=publish --skip=sign --snapshot --config {{ .TMP_DIR }}/goreleaser.yaml"

Expand Down
4 changes: 2 additions & 2 deletions store.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ func (s *Store) AddTool(toolName string, resolvedVersion, pathOutsideRoot string
}

// move the file into the store at root/basename
targetName := toolName
targetPath := filepath.Join(s.root, toolName)
targetName := filepath.Base(pathOutsideRoot) // preserve the filename given to the tool, e.g. syft.exe
targetPath := filepath.Join(s.root, targetName)

if err := os.Rename(pathOutsideRoot, targetPath); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion test/cli/trait_assertions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cli

import (
"encoding/json"
"github.com/google/go-cmp/cmp"
"os"
"os/exec"
"path/filepath"
Expand All @@ -11,6 +10,7 @@ import (
"testing"

"github.com/acarl005/stripansi"
"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/require"
)

Expand Down
5 changes: 5 additions & 0 deletions tool/goinstall/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"text/template"

Expand Down Expand Up @@ -43,6 +44,10 @@ func (i Installer) InstallTo(version, destDir string) (string, error) {
fields := strings.Split(path, "/")
binName := fields[len(fields)-1]
binPath := filepath.Join(destDir, binName)
// TODO: probably refactor this somewhere
if runtime.GOOS == "windows" {
binPath = fmt.Sprintf("%s.exe", binPath)
}

spec := fmt.Sprintf("%s@%s", path, version)
if strings.HasPrefix(i.config.Module, ".") || strings.HasPrefix(i.config.Module, "/") {
Expand Down
7 changes: 6 additions & 1 deletion tool/goinstall/installer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package goinstall
import (
"fmt"
"os"
"runtime"
"strings"
"testing"

Expand Down Expand Up @@ -114,7 +115,11 @@ func TestInstaller_InstallTo(t *testing.T) {
if !tt.wantErr(t, err, fmt.Sprintf("InstallTo(%v, %v)", tt.args.version, tt.args.destDir)) {
return
}
assert.Equalf(t, tt.want, got, "InstallTo(%v, %v)", tt.args.version, tt.args.destDir)
wantPath := tt.want
if runtime.GOOS == "windows" {
wantPath = fmt.Sprintf("%s.exe", wantPath)
}
assert.Equalf(t, wantPath, got, "InstallTo(%v, %v)", tt.args.version, tt.args.destDir)
})
}
}
Loading