From 62cd5899ad1ff844150919cff95812a7c95b0d1b Mon Sep 17 00:00:00 2001 From: Will Roden Date: Tue, 8 Aug 2023 10:01:50 -0500 Subject: [PATCH 1/8] fix usage --- internal/build-bootstrapper/assets/main.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/internal/build-bootstrapper/assets/main.sh b/internal/build-bootstrapper/assets/main.sh index 69c9dd66..f1a8a5d1 100644 --- a/internal/build-bootstrapper/assets/main.sh +++ b/internal/build-bootstrapper/assets/main.sh @@ -5,8 +5,6 @@ usage() { this=$1 cat < Date: Tue, 8 Aug 2023 10:12:52 -0500 Subject: [PATCH 2/8] extract bindown_name function --- bindown.yml | 376 +++++++++--------- internal/build-bootstrapper/assets/main.sh | 18 +- internal/build-bootstrapper/testdata/want.txt | 18 +- 3 files changed, 208 insertions(+), 204 deletions(-) diff --git a/bindown.yml b/bindown.yml index 8d948bd0..bfc25279 100644 --- a/bindown.yml +++ b/bindown.yml @@ -1,10 +1,10 @@ cache: ./bin/.bindown install_dir: ./bin systems: - - darwin/amd64 - - darwin/arm64 - - linux/amd64 - - windows/amd64 +- darwin/amd64 +- darwin/arm64 +- linux/amd64 +- windows/amd64 dependencies: gh: template: origin#gh @@ -43,52 +43,50 @@ templates: url: https://github.com/WillAbides/bindown/releases/download/{{.tag}}/checksums.txt bin: checksums.txt required_vars: - - tag + - tag origin#gh: - homepage: https://github.com/cli/cli - description: GitHub’s official command line tool url: https://github.com/cli/cli/releases/download/v{{.version}}/gh_{{.version}}_{{.os}}_{{.arch}}{{.urlSuffix}} archive_path: gh_{{.version}}_{{.os}}_{{.arch}}/bin/gh{{.archivePathSuffix}} bin: gh vars: archivePathSuffix: "" urlSuffix: .zip + required_vars: + - version overrides: - - matcher: - os: - - windows - dependency: - archive_path: bin/gh{{.archivePathSuffix}} - vars: - archivePathSuffix: .exe - - matcher: - os: - - linux - dependency: - vars: - urlSuffix: .tar.gz - - matcher: - os: - - darwin - version: - - < 2.28.0 - dependency: - vars: - urlSuffix: .tar.gz + - matcher: + os: + - windows + dependency: + archive_path: bin/gh{{.archivePathSuffix}} + vars: + archivePathSuffix: .exe + - matcher: + os: + - linux + dependency: + vars: + urlSuffix: .tar.gz + - matcher: + os: + - darwin + version: + - < 2.28.0 + dependency: + vars: + urlSuffix: .tar.gz substitutions: os: darwin: macOS systems: - - darwin/amd64 - - darwin/arm64 - - linux/386 - - linux/amd64 - - linux/arm64 - - windows/386 - - windows/amd64 - - windows/arm64 - required_vars: - - version + - darwin/amd64 + - darwin/arm64 + - linux/386 + - linux/amd64 + - linux/arm64 + - windows/386 + - windows/amd64 + - windows/arm64 origin#go: url: https://dl.google.com/go/go{{.version}}.{{.os}}-{{.arch}}{{.urlSuffix}} archive_path: go/bin/go{{.archivePathSuffix}} @@ -97,29 +95,29 @@ templates: vars: archivePathSuffix: "" urlSuffix: .tar.gz + required_vars: + - version overrides: - - matcher: - os: - - windows - dependency: - vars: - archivePathSuffix: .exe - urlSuffix: .zip + - matcher: + os: + - windows + dependency: + vars: + archivePathSuffix: .exe + urlSuffix: .zip systems: - - darwin/amd64 - - darwin/arm64 - - freebsd/386 - - freebsd/amd64 - - linux/386 - - linux/amd64 - - linux/arm64 - - linux/ppc64le - - linux/s390x - - windows/386 - - windows/amd64 - - windows/arm64 - required_vars: - - version + - darwin/amd64 + - darwin/arm64 + - freebsd/386 + - freebsd/amd64 + - linux/386 + - linux/amd64 + - linux/arm64 + - linux/ppc64le + - linux/s390x + - windows/386 + - windows/amd64 + - windows/arm64 origin#gofumpt: url: https://github.com/mvdan/gofumpt/releases/download/v{{.version}}/gofumpt_v{{.version}}_{{.os}}_{{.arch}}{{.urlSuffix}} archive_path: gofumpt_v{{.version}}_{{.os}}_{{.arch}}{{.urlSuffix}} @@ -127,23 +125,23 @@ templates: vars: archivePathSuffix: "" urlSuffix: "" + required_vars: + - version overrides: - - matcher: - os: - - windows - dependency: - vars: - urlSuffix: .exe + - matcher: + os: + - windows + dependency: + vars: + urlSuffix: .exe systems: - - darwin/amd64 - - darwin/arm64 - - linux/386 - - linux/amd64 - - linux/arm64 - - windows/386 - - windows/amd64 - required_vars: - - version + - darwin/amd64 + - darwin/arm64 + - linux/386 + - linux/amd64 + - linux/arm64 + - windows/386 + - windows/amd64 origin#golangci-lint: url: https://github.com/golangci/golangci-lint/releases/download/v{{.version}}/golangci-lint-{{.version}}-{{.os}}-{{.arch}}{{.urlSuffix}} archive_path: golangci-lint-{{.version}}-{{.os}}-{{.arch}}/golangci-lint{{.archivePathSuffix}} @@ -151,35 +149,35 @@ templates: vars: archivePathSuffix: "" urlSuffix: .tar.gz + required_vars: + - version overrides: - - matcher: - os: - - windows - dependency: - vars: - archivePathSuffix: .exe - urlSuffix: .zip + - matcher: + os: + - windows + dependency: + vars: + archivePathSuffix: .exe + urlSuffix: .zip systems: - - darwin/amd64 - - darwin/arm64 - - freebsd/386 - - freebsd/amd64 - - linux/386 - - linux/amd64 - - linux/arm64 - - linux/loong64 - - linux/mips64 - - linux/mips64le - - linux/ppc64le - - linux/riscv64 - - linux/s390x - - netbsd/386 - - netbsd/amd64 - - windows/386 - - windows/amd64 - - windows/arm64 - required_vars: - - version + - darwin/amd64 + - darwin/arm64 + - freebsd/386 + - freebsd/amd64 + - linux/386 + - linux/amd64 + - linux/arm64 + - linux/loong64 + - linux/mips64 + - linux/mips64le + - linux/ppc64le + - linux/riscv64 + - linux/s390x + - netbsd/386 + - netbsd/amd64 + - windows/386 + - windows/amd64 + - windows/arm64 origin#goreleaser: url: https://github.com/goreleaser/goreleaser/releases/download/v{{.version}}/goreleaser_{{.os}}_{{.arch}}{{.urlSuffix}} archive_path: goreleaser{{.archivePathSuffix}} @@ -187,20 +185,22 @@ templates: vars: archivePathSuffix: "" urlSuffix: .tar.gz + required_vars: + - version overrides: - - matcher: + - matcher: + os: + - windows + dependency: + vars: + archivePathSuffix: .exe + urlSuffix: .zip + substitutions: + arch: + "386": i386 + amd64: x86_64 os: - - windows - dependency: - vars: - archivePathSuffix: .exe - urlSuffix: .zip - substitutions: - arch: - "386": i386 - amd64: x86_64 - os: - windows: Windows + windows: Windows substitutions: arch: "386": i386 @@ -209,17 +209,15 @@ templates: darwin: Darwin linux: Linux systems: - - darwin/amd64 - - darwin/arm64 - - linux/386 - - linux/amd64 - - linux/arm64 - - linux/ppc64 - - windows/386 - - windows/amd64 - - windows/arm64 - required_vars: - - version + - darwin/amd64 + - darwin/arm64 + - linux/386 + - linux/amd64 + - linux/arm64 + - linux/ppc64 + - windows/386 + - windows/amd64 + - windows/arm64 origin#shellcheck: url: https://github.com/koalaman/shellcheck/releases/download/v{{.version}}/shellcheck-v{{.version}}.{{.os}}.{{.arch}}{{.urlSuffix}} archive_path: shellcheck-v{{.version}}/shellcheck{{.archivePathSuffix}} @@ -227,33 +225,33 @@ templates: vars: archivePathSuffix: "" urlSuffix: .tar.xz + required_vars: + - version overrides: - - matcher: - os: - - windows - dependency: - url: https://github.com/koalaman/shellcheck/releases/download/v{{.version}}/shellcheck-v{{.version}}.zip - archive_path: shellcheck.exe - - matcher: + - matcher: + os: + - windows + dependency: + url: https://github.com/koalaman/shellcheck/releases/download/v{{.version}}/shellcheck-v{{.version}}.zip + archive_path: shellcheck.exe + - matcher: + arch: + - arm64 + os: + - darwin + dependency: + substitutions: arch: - - arm64 - os: - - darwin - dependency: - substitutions: - arch: - arm64: x86_64 + arm64: x86_64 substitutions: arch: amd64: x86_64 arm64: aarch64 systems: - - darwin/amd64 - - darwin/arm64 - - linux/amd64 - - linux/arm64 - required_vars: - - version + - darwin/amd64 + - darwin/arm64 + - linux/amd64 + - linux/arm64 origin#shfmt: url: https://github.com/mvdan/sh/releases/download/v{{.version}}/shfmt_v{{.version}}_{{.os}}_{{.arch}}{{.urlSuffix}} archive_path: shfmt_v{{.version}}_{{.os}}_{{.arch}}{{.urlSuffix}} @@ -261,23 +259,23 @@ templates: vars: archivePathSuffix: "" urlSuffix: "" + required_vars: + - version overrides: - - matcher: - os: - - windows - dependency: - vars: - urlSuffix: .exe + - matcher: + os: + - windows + dependency: + vars: + urlSuffix: .exe systems: - - darwin/amd64 - - darwin/arm64 - - linux/386 - - linux/amd64 - - linux/arm64 - - windows/386 - - windows/amd64 - required_vars: - - version + - darwin/amd64 + - darwin/arm64 + - linux/386 + - linux/amd64 + - linux/arm64 + - windows/386 + - windows/amd64 origin#yq: url: https://github.com/mikefarah/yq/releases/download/v{{.version}}/yq_{{.os}}_{{.arch}}{{.urlSuffix}} archive_path: ./yq_{{.os}}_{{.arch}}{{.archivePathSuffix}} @@ -285,38 +283,38 @@ templates: vars: archivePathSuffix: "" urlSuffix: .tar.gz + required_vars: + - version overrides: - - matcher: - os: - - windows - dependency: - archive_path: yq_{{.os}}_{{.arch}}{{.archivePathSuffix}} - vars: - archivePathSuffix: .exe - urlSuffix: .zip + - matcher: + os: + - windows + dependency: + archive_path: yq_{{.os}}_{{.arch}}{{.archivePathSuffix}} + vars: + archivePathSuffix: .exe + urlSuffix: .zip systems: - - darwin/amd64 - - darwin/arm64 - - freebsd/386 - - freebsd/amd64 - - linux/386 - - linux/amd64 - - linux/arm64 - - linux/mips - - linux/mips64 - - linux/mips64le - - linux/mipsle - - linux/ppc64 - - linux/ppc64le - - linux/s390x - - netbsd/386 - - netbsd/amd64 - - openbsd/386 - - openbsd/amd64 - - windows/386 - - windows/amd64 - required_vars: - - version + - darwin/amd64 + - darwin/arm64 + - freebsd/386 + - freebsd/amd64 + - linux/386 + - linux/amd64 + - linux/arm64 + - linux/mips + - linux/mips64 + - linux/mips64le + - linux/mipsle + - linux/ppc64 + - linux/ppc64le + - linux/s390x + - netbsd/386 + - netbsd/amd64 + - openbsd/386 + - openbsd/amd64 + - windows/386 + - windows/amd64 template_sources: origin: https://raw.githubusercontent.com/WillAbides/bindown-templates/main/bindown.yml url_checksums: diff --git a/internal/build-bootstrapper/assets/main.sh b/internal/build-bootstrapper/assets/main.sh index f1a8a5d1..a7ec9515 100644 --- a/internal/build-bootstrapper/assets/main.sh +++ b/internal/build-bootstrapper/assets/main.sh @@ -3,7 +3,7 @@ GITHUB_DOWNLOAD=https://github.com/WillAbides/bindown/releases/download usage() { this=$1 - cat < "${tmpdir}/checksums.txt" @@ -37,12 +45,8 @@ execute() { srcdir="${tmpdir}" (cd "${tmpdir}" && untar "${TARBALL}") test ! -d "${BINDIR}" && install -d "${BINDIR}" - binexe="bindown" - if [ "$OS" = "windows" ]; then - binexe="${binexe}.exe" - fi - install "${srcdir}/${binexe}" "${BINDIR}/" - log_info "installed ${BINDIR}/${binexe}" + install "${srcdir}/$(bindown_name)" "${BINDIR}/" + log_info "installed ${BINDIR}/$(bindown_name)" rm -rf "${tmpdir}" } diff --git a/internal/build-bootstrapper/testdata/want.txt b/internal/build-bootstrapper/testdata/want.txt index ac3c331f..2feaf648 100644 --- a/internal/build-bootstrapper/testdata/want.txt +++ b/internal/build-bootstrapper/testdata/want.txt @@ -242,8 +242,6 @@ usage() { this=$1 cat << EOT Usage: $this [-b bindir] [-d] - -Usage: $this [-b] bindir [-d] -b sets bindir or installation directory, Defaults to ./bin -d turns on debug logging @@ -267,6 +265,14 @@ parse_args() { shift $((OPTIND - 1)) } +bindown_name() { + if [ "$OS" = "windows" ]; then + echo bindown.exe + else + echo bindown + fi +} + execute() { tmpdir=$(mktemp -d) echo "$CHECKSUMS" > "${tmpdir}/checksums.txt" @@ -276,12 +282,8 @@ execute() { srcdir="${tmpdir}" (cd "${tmpdir}" && untar "${TARBALL}") test ! -d "${BINDIR}" && install -d "${BINDIR}" - binexe="bindown" - if [ "$OS" = "windows" ]; then - binexe="${binexe}.exe" - fi - install "${srcdir}/${binexe}" "${BINDIR}/" - log_info "installed ${BINDIR}/${binexe}" + install "${srcdir}/$(bindown_name)" "${BINDIR}/" + log_info "installed ${BINDIR}/$(bindown_name)" rm -rf "${tmpdir}" } From 9e3995d3c327ea266c071b505a016e60ca39f885 Mon Sep 17 00:00:00 2001 From: Will Roden Date: Tue, 8 Aug 2023 11:26:08 -0500 Subject: [PATCH 3/8] update bootstrap build to directly fetch checksums --- bindown.yml | 376 ++++++++++---------- internal/build-bootstrapper/assets/shlib.sh | 10 +- internal/build-bootstrapper/build.go | 67 +--- internal/build-bootstrapper/build_test.go | 28 +- script/bootstrap-bindown.sh | 302 ---------------- script/fmt | 1 + 6 files changed, 231 insertions(+), 553 deletions(-) delete mode 100755 script/bootstrap-bindown.sh diff --git a/bindown.yml b/bindown.yml index bfc25279..8d948bd0 100644 --- a/bindown.yml +++ b/bindown.yml @@ -1,10 +1,10 @@ cache: ./bin/.bindown install_dir: ./bin systems: -- darwin/amd64 -- darwin/arm64 -- linux/amd64 -- windows/amd64 + - darwin/amd64 + - darwin/arm64 + - linux/amd64 + - windows/amd64 dependencies: gh: template: origin#gh @@ -43,50 +43,52 @@ templates: url: https://github.com/WillAbides/bindown/releases/download/{{.tag}}/checksums.txt bin: checksums.txt required_vars: - - tag + - tag origin#gh: + homepage: https://github.com/cli/cli + description: GitHub’s official command line tool url: https://github.com/cli/cli/releases/download/v{{.version}}/gh_{{.version}}_{{.os}}_{{.arch}}{{.urlSuffix}} archive_path: gh_{{.version}}_{{.os}}_{{.arch}}/bin/gh{{.archivePathSuffix}} bin: gh vars: archivePathSuffix: "" urlSuffix: .zip - required_vars: - - version overrides: - - matcher: - os: - - windows - dependency: - archive_path: bin/gh{{.archivePathSuffix}} - vars: - archivePathSuffix: .exe - - matcher: - os: - - linux - dependency: - vars: - urlSuffix: .tar.gz - - matcher: - os: - - darwin - version: - - < 2.28.0 - dependency: - vars: - urlSuffix: .tar.gz + - matcher: + os: + - windows + dependency: + archive_path: bin/gh{{.archivePathSuffix}} + vars: + archivePathSuffix: .exe + - matcher: + os: + - linux + dependency: + vars: + urlSuffix: .tar.gz + - matcher: + os: + - darwin + version: + - < 2.28.0 + dependency: + vars: + urlSuffix: .tar.gz substitutions: os: darwin: macOS systems: - - darwin/amd64 - - darwin/arm64 - - linux/386 - - linux/amd64 - - linux/arm64 - - windows/386 - - windows/amd64 - - windows/arm64 + - darwin/amd64 + - darwin/arm64 + - linux/386 + - linux/amd64 + - linux/arm64 + - windows/386 + - windows/amd64 + - windows/arm64 + required_vars: + - version origin#go: url: https://dl.google.com/go/go{{.version}}.{{.os}}-{{.arch}}{{.urlSuffix}} archive_path: go/bin/go{{.archivePathSuffix}} @@ -95,29 +97,29 @@ templates: vars: archivePathSuffix: "" urlSuffix: .tar.gz - required_vars: - - version overrides: - - matcher: - os: - - windows - dependency: - vars: - archivePathSuffix: .exe - urlSuffix: .zip + - matcher: + os: + - windows + dependency: + vars: + archivePathSuffix: .exe + urlSuffix: .zip systems: - - darwin/amd64 - - darwin/arm64 - - freebsd/386 - - freebsd/amd64 - - linux/386 - - linux/amd64 - - linux/arm64 - - linux/ppc64le - - linux/s390x - - windows/386 - - windows/amd64 - - windows/arm64 + - darwin/amd64 + - darwin/arm64 + - freebsd/386 + - freebsd/amd64 + - linux/386 + - linux/amd64 + - linux/arm64 + - linux/ppc64le + - linux/s390x + - windows/386 + - windows/amd64 + - windows/arm64 + required_vars: + - version origin#gofumpt: url: https://github.com/mvdan/gofumpt/releases/download/v{{.version}}/gofumpt_v{{.version}}_{{.os}}_{{.arch}}{{.urlSuffix}} archive_path: gofumpt_v{{.version}}_{{.os}}_{{.arch}}{{.urlSuffix}} @@ -125,23 +127,23 @@ templates: vars: archivePathSuffix: "" urlSuffix: "" - required_vars: - - version overrides: - - matcher: - os: - - windows - dependency: - vars: - urlSuffix: .exe + - matcher: + os: + - windows + dependency: + vars: + urlSuffix: .exe systems: - - darwin/amd64 - - darwin/arm64 - - linux/386 - - linux/amd64 - - linux/arm64 - - windows/386 - - windows/amd64 + - darwin/amd64 + - darwin/arm64 + - linux/386 + - linux/amd64 + - linux/arm64 + - windows/386 + - windows/amd64 + required_vars: + - version origin#golangci-lint: url: https://github.com/golangci/golangci-lint/releases/download/v{{.version}}/golangci-lint-{{.version}}-{{.os}}-{{.arch}}{{.urlSuffix}} archive_path: golangci-lint-{{.version}}-{{.os}}-{{.arch}}/golangci-lint{{.archivePathSuffix}} @@ -149,35 +151,35 @@ templates: vars: archivePathSuffix: "" urlSuffix: .tar.gz - required_vars: - - version overrides: - - matcher: - os: - - windows - dependency: - vars: - archivePathSuffix: .exe - urlSuffix: .zip + - matcher: + os: + - windows + dependency: + vars: + archivePathSuffix: .exe + urlSuffix: .zip systems: - - darwin/amd64 - - darwin/arm64 - - freebsd/386 - - freebsd/amd64 - - linux/386 - - linux/amd64 - - linux/arm64 - - linux/loong64 - - linux/mips64 - - linux/mips64le - - linux/ppc64le - - linux/riscv64 - - linux/s390x - - netbsd/386 - - netbsd/amd64 - - windows/386 - - windows/amd64 - - windows/arm64 + - darwin/amd64 + - darwin/arm64 + - freebsd/386 + - freebsd/amd64 + - linux/386 + - linux/amd64 + - linux/arm64 + - linux/loong64 + - linux/mips64 + - linux/mips64le + - linux/ppc64le + - linux/riscv64 + - linux/s390x + - netbsd/386 + - netbsd/amd64 + - windows/386 + - windows/amd64 + - windows/arm64 + required_vars: + - version origin#goreleaser: url: https://github.com/goreleaser/goreleaser/releases/download/v{{.version}}/goreleaser_{{.os}}_{{.arch}}{{.urlSuffix}} archive_path: goreleaser{{.archivePathSuffix}} @@ -185,22 +187,20 @@ templates: vars: archivePathSuffix: "" urlSuffix: .tar.gz - required_vars: - - version overrides: - - matcher: - os: - - windows - dependency: - vars: - archivePathSuffix: .exe - urlSuffix: .zip - substitutions: - arch: - "386": i386 - amd64: x86_64 + - matcher: os: - windows: Windows + - windows + dependency: + vars: + archivePathSuffix: .exe + urlSuffix: .zip + substitutions: + arch: + "386": i386 + amd64: x86_64 + os: + windows: Windows substitutions: arch: "386": i386 @@ -209,15 +209,17 @@ templates: darwin: Darwin linux: Linux systems: - - darwin/amd64 - - darwin/arm64 - - linux/386 - - linux/amd64 - - linux/arm64 - - linux/ppc64 - - windows/386 - - windows/amd64 - - windows/arm64 + - darwin/amd64 + - darwin/arm64 + - linux/386 + - linux/amd64 + - linux/arm64 + - linux/ppc64 + - windows/386 + - windows/amd64 + - windows/arm64 + required_vars: + - version origin#shellcheck: url: https://github.com/koalaman/shellcheck/releases/download/v{{.version}}/shellcheck-v{{.version}}.{{.os}}.{{.arch}}{{.urlSuffix}} archive_path: shellcheck-v{{.version}}/shellcheck{{.archivePathSuffix}} @@ -225,33 +227,33 @@ templates: vars: archivePathSuffix: "" urlSuffix: .tar.xz - required_vars: - - version overrides: - - matcher: - os: - - windows - dependency: - url: https://github.com/koalaman/shellcheck/releases/download/v{{.version}}/shellcheck-v{{.version}}.zip - archive_path: shellcheck.exe - - matcher: - arch: - - arm64 - os: - - darwin - dependency: - substitutions: + - matcher: + os: + - windows + dependency: + url: https://github.com/koalaman/shellcheck/releases/download/v{{.version}}/shellcheck-v{{.version}}.zip + archive_path: shellcheck.exe + - matcher: arch: - arm64: x86_64 + - arm64 + os: + - darwin + dependency: + substitutions: + arch: + arm64: x86_64 substitutions: arch: amd64: x86_64 arm64: aarch64 systems: - - darwin/amd64 - - darwin/arm64 - - linux/amd64 - - linux/arm64 + - darwin/amd64 + - darwin/arm64 + - linux/amd64 + - linux/arm64 + required_vars: + - version origin#shfmt: url: https://github.com/mvdan/sh/releases/download/v{{.version}}/shfmt_v{{.version}}_{{.os}}_{{.arch}}{{.urlSuffix}} archive_path: shfmt_v{{.version}}_{{.os}}_{{.arch}}{{.urlSuffix}} @@ -259,23 +261,23 @@ templates: vars: archivePathSuffix: "" urlSuffix: "" - required_vars: - - version overrides: - - matcher: - os: - - windows - dependency: - vars: - urlSuffix: .exe + - matcher: + os: + - windows + dependency: + vars: + urlSuffix: .exe systems: - - darwin/amd64 - - darwin/arm64 - - linux/386 - - linux/amd64 - - linux/arm64 - - windows/386 - - windows/amd64 + - darwin/amd64 + - darwin/arm64 + - linux/386 + - linux/amd64 + - linux/arm64 + - windows/386 + - windows/amd64 + required_vars: + - version origin#yq: url: https://github.com/mikefarah/yq/releases/download/v{{.version}}/yq_{{.os}}_{{.arch}}{{.urlSuffix}} archive_path: ./yq_{{.os}}_{{.arch}}{{.archivePathSuffix}} @@ -283,38 +285,38 @@ templates: vars: archivePathSuffix: "" urlSuffix: .tar.gz - required_vars: - - version overrides: - - matcher: - os: - - windows - dependency: - archive_path: yq_{{.os}}_{{.arch}}{{.archivePathSuffix}} - vars: - archivePathSuffix: .exe - urlSuffix: .zip + - matcher: + os: + - windows + dependency: + archive_path: yq_{{.os}}_{{.arch}}{{.archivePathSuffix}} + vars: + archivePathSuffix: .exe + urlSuffix: .zip systems: - - darwin/amd64 - - darwin/arm64 - - freebsd/386 - - freebsd/amd64 - - linux/386 - - linux/amd64 - - linux/arm64 - - linux/mips - - linux/mips64 - - linux/mips64le - - linux/mipsle - - linux/ppc64 - - linux/ppc64le - - linux/s390x - - netbsd/386 - - netbsd/amd64 - - openbsd/386 - - openbsd/amd64 - - windows/386 - - windows/amd64 + - darwin/amd64 + - darwin/arm64 + - freebsd/386 + - freebsd/amd64 + - linux/386 + - linux/amd64 + - linux/arm64 + - linux/mips + - linux/mips64 + - linux/mips64le + - linux/mipsle + - linux/ppc64 + - linux/ppc64le + - linux/s390x + - netbsd/386 + - netbsd/amd64 + - openbsd/386 + - openbsd/amd64 + - windows/386 + - windows/amd64 + required_vars: + - version template_sources: origin: https://raw.githubusercontent.com/WillAbides/bindown-templates/main/bindown.yml url_checksums: diff --git a/internal/build-bootstrapper/assets/shlib.sh b/internal/build-bootstrapper/assets/shlib.sh index e1f973c8..b8979518 100644 --- a/internal/build-bootstrapper/assets/shlib.sh +++ b/internal/build-bootstrapper/assets/shlib.sh @@ -1,4 +1,4 @@ -cat /dev/null </dev/null + command -v "$1" > /dev/null } echoerr() { echo "$@" 1>&2 @@ -175,7 +175,7 @@ hash_sha256() { hash=$(sha256sum "$TARGET") || return 1 echo "$hash" | cut -d ' ' -f 1 elif is_command shasum; then - hash=$(shasum -a 256 "$TARGET" 2>/dev/null) || return 1 + hash=$(shasum -a 256 "$TARGET" 2> /dev/null) || return 1 echo "$hash" | cut -d ' ' -f 1 elif is_command openssl; then hash=$(openssl -dst openssl dgst -sha256 "$TARGET") || return 1 @@ -193,7 +193,7 @@ hash_sha256_verify() { return 1 fi BASENAME=${TARGET##*/} - want=$(grep "${BASENAME}" "${checksums}" 2>/dev/null | tr '\t' ' ' | cut -d ' ' -f 1) + want=$(grep "${BASENAME}" "${checksums}" 2> /dev/null | tr '\t' ' ' | cut -d ' ' -f 1) if [ -z "$want" ]; then log_err "hash_sha256_verify unable to find checksum for '${TARGET}' in '${checksums}'" return 1 @@ -204,7 +204,7 @@ hash_sha256_verify() { return 1 fi } -cat /dev/null </dev/null -} -echoerr() { - echo "$@" 1>&2 -} -log_prefix() { - echo "$0" -} -_logp=6 -log_set_priority() { - _logp="$1" -} -log_priority() { - if test -z "$1"; then - echo "$_logp" - return - fi - [ "$1" -le "$_logp" ] -} -log_tag() { - case $1 in - 0) echo "emerg" ;; - 1) echo "alert" ;; - 2) echo "crit" ;; - 3) echo "err" ;; - 4) echo "warning" ;; - 5) echo "notice" ;; - 6) echo "info" ;; - 7) echo "debug" ;; - *) echo "$1" ;; - esac -} -log_debug() { - log_priority 7 || return 0 - echoerr "$(log_prefix)" "$(log_tag 7)" "$@" -} -log_info() { - log_priority 6 || return 0 - echoerr "$(log_prefix)" "$(log_tag 6)" "$@" -} -log_err() { - log_priority 3 || return 0 - echoerr "$(log_prefix)" "$(log_tag 3)" "$@" -} -log_crit() { - log_priority 2 || return 0 - echoerr "$(log_prefix)" "$(log_tag 2)" "$@" -} -uname_os() { - os=$(uname -s | tr '[:upper:]' '[:lower:]') - case "$os" in - cygwin_nt*) os="windows" ;; - mingw*) os="windows" ;; - msys_nt*) os="windows" ;; - esac - echo "$os" -} -uname_arch() { - arch=$(uname -m) - case $arch in - x86_64) arch="amd64" ;; - x86) arch="386" ;; - i686) arch="386" ;; - i386) arch="386" ;; - aarch64) arch="arm64" ;; - armv5*) arch="armv5" ;; - armv6*) arch="armv6" ;; - armv7*) arch="armv7" ;; - esac - echo ${arch} -} -uname_os_check() { - os=$(uname_os) - case "$os" in - darwin) return 0 ;; - dragonfly) return 0 ;; - freebsd) return 0 ;; - linux) return 0 ;; - android) return 0 ;; - nacl) return 0 ;; - netbsd) return 0 ;; - openbsd) return 0 ;; - plan9) return 0 ;; - solaris) return 0 ;; - windows) return 0 ;; - esac - log_crit "uname_os_check '$(uname -s)' got converted to '$os' which is not a GOOS value. Please file bug at https://github.com/client9/shlib" - return 1 -} -uname_arch_check() { - arch=$(uname_arch) - case "$arch" in - 386) return 0 ;; - amd64) return 0 ;; - arm64) return 0 ;; - armv5) return 0 ;; - armv6) return 0 ;; - armv7) return 0 ;; - ppc64) return 0 ;; - ppc64le) return 0 ;; - mips) return 0 ;; - mipsle) return 0 ;; - mips64) return 0 ;; - mips64le) return 0 ;; - s390x) return 0 ;; - amd64p32) return 0 ;; - esac - log_crit "uname_arch_check '$(uname -m)' got converted to '$arch' which is not a GOARCH value. Please file bug report at https://github.com/client9/shlib" - return 1 -} -untar() { - tarball=$1 - case "${tarball}" in - *.tar.gz | *.tgz) tar --no-same-owner -xzf "${tarball}" ;; - *.tar) tar --no-same-owner -xf "${tarball}" ;; - *.zip) unzip "${tarball}" ;; - *) - log_err "untar unknown archive format for ${tarball}" - return 1 - ;; - esac -} -http_download_curl() { - local_file=$1 - source_url=$2 - header=$3 - if [ -z "$header" ]; then - code=$(curl -w '%{http_code}' -sL -o "$local_file" "$source_url") - else - code=$(curl -w '%{http_code}' -sL -H "$header" -o "$local_file" "$source_url") - fi - if [ "$code" != "200" ]; then - log_debug "http_download_curl received HTTP status $code" - return 1 - fi - return 0 -} -http_download_wget() { - local_file=$1 - source_url=$2 - header=$3 - if [ -z "$header" ]; then - wget -q -O "$local_file" "$source_url" - else - wget -q --header "$header" -O "$local_file" "$source_url" - fi -} -http_download() { - log_debug "http_download $2" - if is_command curl; then - http_download_curl "$@" - return - elif is_command wget; then - http_download_wget "$@" - return - fi - log_crit "http_download unable to find wget or curl" - return 1 -} -hash_sha256() { - TARGET=${1:-/dev/stdin} - if is_command gsha256sum; then - hash=$(gsha256sum "$TARGET") || return 1 - echo "$hash" | cut -d ' ' -f 1 - elif is_command sha256sum; then - hash=$(sha256sum "$TARGET") || return 1 - echo "$hash" | cut -d ' ' -f 1 - elif is_command shasum; then - hash=$(shasum -a 256 "$TARGET" 2>/dev/null) || return 1 - echo "$hash" | cut -d ' ' -f 1 - elif is_command openssl; then - hash=$(openssl -dst openssl dgst -sha256 "$TARGET") || return 1 - echo "$hash" | cut -d ' ' -f a - else - log_crit "hash_sha256 unable to find command to compute sha-256 hash" - return 1 - fi -} -hash_sha256_verify() { - TARGET=$1 - checksums=$2 - if [ -z "$checksums" ]; then - log_err "hash_sha256_verify checksum file not specified in arg2" - return 1 - fi - BASENAME=${TARGET##*/} - want=$(grep "${BASENAME}" "${checksums}" 2>/dev/null | tr '\t' ' ' | cut -d ' ' -f 1) - if [ -z "$want" ]; then - log_err "hash_sha256_verify unable to find checksum for '${TARGET}' in '${checksums}'" - return 1 - fi - got=$(hash_sha256 "$TARGET") - if [ "$want" != "$got" ]; then - log_err "hash_sha256_verify checksum for '$TARGET' did not verify ${want} vs $got" - return 1 - fi -} -cat /dev/null < "${tmpdir}/checksums.txt" - log_debug "downloading files into ${tmpdir}" - http_download "${tmpdir}/${TARBALL}" "${TARBALL_URL}" - hash_sha256_verify "${tmpdir}/${TARBALL}" "${tmpdir}/checksums.txt" - srcdir="${tmpdir}" - (cd "${tmpdir}" && untar "${TARBALL}") - test ! -d "${BINDIR}" && install -d "${BINDIR}" - binexe="bindown" - if [ "$OS" = "windows" ]; then - binexe="${binexe}.exe" - fi - install "${srcdir}/${binexe}" "${BINDIR}/" - log_info "installed ${BINDIR}/${binexe}" - rm -rf "${tmpdir}" -} - -OS=$(uname_os) -ARCH=$(uname_arch) - -uname_os_check "$OS" -uname_arch_check "$ARCH" - -parse_args "$@" - -VERSION=${TAG#v} -NAME=bindown_${VERSION}_${OS}_${ARCH} -TARBALL=${NAME}.${FORMAT} -TARBALL_URL=${GITHUB_DOWNLOAD}/${TAG}/${TARBALL} - -execute \ No newline at end of file diff --git a/script/fmt b/script/fmt index d452e123..0c0e9543 100755 --- a/script/fmt +++ b/script/fmt @@ -9,3 +9,4 @@ script/bindown -q install gofumpt shfmt bin/gofumpt -w internal/*/*.go cmd/*/*.go find script -type f -not -name 'bootstrap-bindown.sh' -print0 | xargs -0 bin/shfmt -w -i 2 -ci -sr +bin/shfmt -w -i 2 -ci -sr internal/build-bootstrapper/assets/*.sh From 6e54ef831e301d2f58e5a02df7e1b1314fcf63fb Mon Sep 17 00:00:00 2001 From: Will Roden Date: Tue, 8 Aug 2023 11:34:42 -0500 Subject: [PATCH 4/8] install shfmt and shellcheck for building bootstrapper --- internal/build-bootstrapper/build.go | 6 ++++++ internal/build-bootstrapper/build_test.go | 16 ---------------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/internal/build-bootstrapper/build.go b/internal/build-bootstrapper/build.go index 442564de..7e1f18ce 100644 --- a/internal/build-bootstrapper/build.go +++ b/internal/build-bootstrapper/build.go @@ -17,6 +17,12 @@ import ( var assets embed.FS func build(tag, repoRoot string) (_ string, errOut error) { + bindownCmd := exec.Command("script/bindown", "install", "shfmt", "shellcheck") + bindownCmd.Dir = repoRoot + err := bindownCmd.Run() + if err != nil { + return "", err + } checksumsURL := fmt.Sprintf( `https://github.com/WillAbides/bindown/releases/download/%s/checksums.txt`, tag, diff --git a/internal/build-bootstrapper/build_test.go b/internal/build-bootstrapper/build_test.go index 5ad62053..6bd11c02 100644 --- a/internal/build-bootstrapper/build_test.go +++ b/internal/build-bootstrapper/build_test.go @@ -1,9 +1,6 @@ package main import ( - "fmt" - "io" - "net/http" "os" "path/filepath" "runtime" @@ -12,19 +9,6 @@ import ( "github.com/stretchr/testify/require" ) -func TestFoo(t *testing.T) { - resp, err := http.Get("https://github.com/WillAbides/bindown/releases/download/v4.0.0/checksums.txt") - require.NoError(t, err) - t.Cleanup(func() { - require.NoError(t, resp.Body.Close()) - }) - require.Equal(t, http.StatusOK, resp.StatusCode) - got, err := io.ReadAll(resp.Body) - require.NoError(t, err) - fmt.Println(string(got)) - -} - func TestBuild(t *testing.T) { if testing.Short() { t.Skip("skipping test in short mode.") From 432f30e01ecbeabcd74062eb6165ee10815a57f6 Mon Sep 17 00:00:00 2001 From: Will Roden Date: Tue, 8 Aug 2023 11:37:31 -0500 Subject: [PATCH 5/8] remove commented code --- internal/build-bootstrapper/build_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/build-bootstrapper/build_test.go b/internal/build-bootstrapper/build_test.go index 6bd11c02..47be4573 100644 --- a/internal/build-bootstrapper/build_test.go +++ b/internal/build-bootstrapper/build_test.go @@ -30,5 +30,4 @@ func TestBuild(t *testing.T) { want, err := os.ReadFile(filepath.FromSlash("testdata/want.txt")) require.NoError(t, err) require.Equal(t, string(want), got) - //require.Empty(t, cmp.Diff(string(want), got)) } From c4d80e19081b057e274e7e8aec7a5b23d9787d5b Mon Sep 17 00:00:00 2001 From: Will Roden Date: Tue, 8 Aug 2023 12:03:56 -0500 Subject: [PATCH 6/8] don't re-bootstrap when bindown already installed --- internal/build-bootstrapper/assets/main.sh | 12 ++++++++++++ internal/build-bootstrapper/testdata/want.txt | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/internal/build-bootstrapper/assets/main.sh b/internal/build-bootstrapper/assets/main.sh index a7ec9515..07cb52af 100644 --- a/internal/build-bootstrapper/assets/main.sh +++ b/internal/build-bootstrapper/assets/main.sh @@ -50,6 +50,12 @@ execute() { rm -rf "${tmpdir}" } +already_installed() { + VERSION="$1" + [ -f "${BINDIR}/$(bindown_name)" ] && + "${BINDIR}/$(bindown_name)" version 2> /dev/null | grep -q "$VERSION" +} + OS=$(uname_os) ARCH=$(uname_arch) @@ -59,6 +65,12 @@ uname_arch_check "$ARCH" parse_args "$@" VERSION=${TAG#v} + +if already_installed "$VERSION"; then + log_debug "bindown ${VERSION} is already installed" + exit 0 +fi + NAME=bindown_${VERSION}_${OS}_${ARCH} TARBALL=${NAME}.${FORMAT} TARBALL_URL=${GITHUB_DOWNLOAD}/${TAG}/${TARBALL} diff --git a/internal/build-bootstrapper/testdata/want.txt b/internal/build-bootstrapper/testdata/want.txt index 2feaf648..21877563 100644 --- a/internal/build-bootstrapper/testdata/want.txt +++ b/internal/build-bootstrapper/testdata/want.txt @@ -287,6 +287,12 @@ execute() { rm -rf "${tmpdir}" } +already_installed() { + VERSION="$1" + [ -f "${BINDIR}/$(bindown_name)" ] && + "${BINDIR}/$(bindown_name)" version 2> /dev/null | grep -q "$VERSION" +} + OS=$(uname_os) ARCH=$(uname_arch) @@ -296,6 +302,12 @@ uname_arch_check "$ARCH" parse_args "$@" VERSION=${TAG#v} + +if already_installed "$VERSION"; then + log_debug "bindown ${VERSION} is already installed" + exit 0 +fi + NAME=bindown_${VERSION}_${OS}_${ARCH} TARBALL=${NAME}.${FORMAT} TARBALL_URL=${GITHUB_DOWNLOAD}/${TAG}/${TARBALL} From 1d4c17d2760f7decb797ba4e2c35752862e06299 Mon Sep 17 00:00:00 2001 From: Will Roden Date: Tue, 8 Aug 2023 12:04:34 -0500 Subject: [PATCH 7/8] rm labels.yaml --- .github/workflows/labels.yaml | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 .github/workflows/labels.yaml diff --git a/.github/workflows/labels.yaml b/.github/workflows/labels.yaml deleted file mode 100644 index c50301e9..00000000 --- a/.github/workflows/labels.yaml +++ /dev/null @@ -1,21 +0,0 @@ -name: labels -on: - pull_request: - types: - - synchronize - - opened - - reopened - - labeled - - unlabeled -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number }} - cancel-in-progress: true -jobs: - label_check: - name: check labels - runs-on: ubuntu-22.04 - if: github.event_name == 'pull_request' - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - steps: - - uses: WillAbides/release-train@v1.6.1 From 38f9f5e465bd9638e8ed2cd2e663cfc724880b8e Mon Sep 17 00:00:00 2001 From: Will Roden Date: Tue, 8 Aug 2023 12:05:22 -0500 Subject: [PATCH 8/8] Revert "rm labels.yaml" This reverts commit 1d4c17d2760f7decb797ba4e2c35752862e06299. --- .github/workflows/labels.yaml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .github/workflows/labels.yaml diff --git a/.github/workflows/labels.yaml b/.github/workflows/labels.yaml new file mode 100644 index 00000000..c50301e9 --- /dev/null +++ b/.github/workflows/labels.yaml @@ -0,0 +1,21 @@ +name: labels +on: + pull_request: + types: + - synchronize + - opened + - reopened + - labeled + - unlabeled +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number }} + cancel-in-progress: true +jobs: + label_check: + name: check labels + runs-on: ubuntu-22.04 + if: github.event_name == 'pull_request' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: WillAbides/release-train@v1.6.1