diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3b0b001d..e9dfe2e2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,25 +1,25 @@ name: ECM Distro Tools Release on: - push: - tags: - - "v*" + push: + tags: + - "v*" jobs: release: permissions: contents: write runs-on: ubuntu-latest steps: - - name: Checkout + - name: Checkout uses: actions/checkout@v4 - name: Build ECM Distro Tools run: | - make all make test + make package-binaries - name: Publish Binaries uses: SierraSoftworks/gh-releases@v1.0.7 with: token: ${{ secrets.GITHUB_TOKEN }} - overwrite: 'true' + overwrite: "true" files: | ${{ github.workspace }}/bin/bootstrap_hash ${{ github.workspace }}/bin/check_for_k8s_release @@ -54,7 +54,7 @@ jobs: ${{ github.workspace }}/cmd/gen_release_report/bin/gen_release_report-freebsd-arm64 ${{ github.workspace }}/cmd/gen_release_report/bin/gen_release_report-linux-amd64 ${{ github.workspace }}/cmd/gen_release_report/bin/gen_release_report-linux-arm64 - ${{ github.workspace }}/cmd/gen_release_report/bin/sha256sums-gen_release_report. + ${{ github.workspace }}/cmd/gen_release_report/bin/sha256sums-gen_release_report.txt ${{ github.workspace }}/cmd/k3s_release/bin/k3s_release-darwin-amd64 ${{ github.workspace }}/cmd/k3s_release/bin/k3s_release-darwin-arm64 ${{ github.workspace }}/cmd/k3s_release/bin/k3s_release-freebsd-amd64 @@ -97,8 +97,12 @@ jobs: ${{ github.workspace }}/cmd/upstream_go_version/bin/upstream_go_version-linux-amd64 ${{ github.workspace }}/cmd/upstream_go_version/bin/upstream_go_version-linux-arm64 ${{ github.workspace }}/cmd/upstream_go_version/bin/sha256sums-upstream_go_version.txt - ${{ github.workspace }}/cmd/standup/bin/standup - ${{ github.workspace }}/ecm-distro-tools.tgz + ${{ github.workspace }}/ecm-distro-tools.darwin-amd64.tar.gz + ${{ github.workspace }}/ecm-distro-tools.darwin-arm64.tar.gz + ${{ github.workspace }}/ecm-distro-tools.linux-amd64.tar.gz + ${{ github.workspace }}/ecm-distro-tools.linux-arm64.tar.gz + ${{ github.workspace }}/ecm-distro-tools.freebsd-amd64.tar.gz + ${{ github.workspace }}/ecm-distro-tools.freebsd-arm64.tar.gz - name: Docker Hub Login uses: docker/login-action@v2 with: diff --git a/.gitignore b/.gitignore index 0d3728ae..1262ca67 100644 --- a/.gitignore +++ b/.gitignore @@ -41,3 +41,7 @@ data/* .DS_Store .vscode + +# build artifacts +*.tar +*.tar.gz diff --git a/Makefile b/Makefile index 02126f60..5bb6a2ff 100644 --- a/Makefile +++ b/Makefile @@ -55,15 +55,18 @@ build-image: package-binaries: $(BINARIES) @$(eval export BIN_FILES = $(shell ls bin/)) - cd bin && \ - tar cvf ../ecm-distro-tools.tar $(BIN_FILES) && \ - cd ../ - - for binary in $<; do \ - cd cmd/$${binary}/bin && \ - tar rvf ../../../ecm-distro-tools.tar * && \ - cd ../../../; \ + for arch in $(ARCHS); do \ + for os in $(OSs); do \ + SUFFIX=$${os}-$${arch}; \ + cd bin && \ + tar cvf ../ecm-distro-tools.$${SUFFIX}.tar $(BIN_FILES) && \ + cd ../; \ + for binary in $(BINARIES); do \ + cd cmd/$${binary}/bin && \ + tar rvf ../../../ecm-distro-tools.$${SUFFIX}.tar $${binary}-$${SUFFIX} && \ + cd ../../../; \ + done; \ + gzip < ecm-distro-tools.$${SUFFIX}.tar > ecm-distro-tools.$${SUFFIX}.tar.gz && \ + rm -f ecm-distro-tools.$${SUFFIX}.tar; \ + done; \ done - - gzip < ecm-distro-tools.tar > ecm-distro-tools.tgz && \ - rm -f ecm-distro-tools.tar diff --git a/cmd/Makefile b/cmd/Makefile index 5de2f5e2..9918b6c8 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -1,7 +1,7 @@ -BINARIES = gen_release_notes gen_release_report backport semv standup k3s_release rancher_release test_coverage upstream_go_version rke2_release +BINARIES = gen_release_notes gen_release_report backport semv k3s_release rancher_release test_coverage upstream_go_version rke2_release ARCHS = amd64 arm64 OSs = linux darwin freebsd -GO_COMPILE = CGO_ENABLED=1 $(GO) build -tags $(TAGS) -v -ldflags "$(LDFLAGS)" -o $@-$${os}-$${arch} +GO_COMPILE = GOOS=$${os} GOARCH=$${arch} CGO_ENABLED=1 $(GO) build -tags $(TAGS) -v -ldflags "$(LDFLAGS)" -o $@-$${os}-$${arch} OS := $(shell uname) ifeq ($(OS),Darwin) @@ -9,4 +9,3 @@ GEN_HASH = shasum -a 256 $@-$${os}-$${arch} >> $(BINDIR)/sha256sums-$(BINARY).tx else GEN_HASH = sha256sum $@-$${os}-$${arch} >> $(BINDIR)/sha256sums-$(BINARY).txt endif - diff --git a/cmd/backport/Makefile b/cmd/backport/Makefile index ea568f8d..2c6b3a34 100644 --- a/cmd/backport/Makefile +++ b/cmd/backport/Makefile @@ -13,6 +13,7 @@ $(BINDIR)/$(BINARY): clean for arch in $(ARCHS); do \ for os in $(OSs); do \ $(GO_COMPILE) ; \ + $(GEN_HASH); \ done; \ done diff --git a/install.sh b/install.sh index 1730fffb..ff0fe841 100755 --- a/install.sh +++ b/install.sh @@ -6,7 +6,7 @@ TMP_DIR="" REPO_NAME="ecm-distro-tools" REPO_URL="https://github.com/rancher/${REPO_NAME}" REPO_RELEASE_URL="${REPO_URL}/releases" -INSTALL_DIR="/usr/local/bin/ecm-distro-tools" +INSTALL_DIR="$HOME/.local/bin/ecm-distro-tools" SUFFIX="" DOWNLOADER="" @@ -31,14 +31,12 @@ setup_arch() { # setup_tmp creates a temporary directory and cleans up when done. setup_tmp() { TMP_DIR=$(mktemp -d -t ecm-distro-tools-install.XXXXXXXXXX) - TMP_HASH=${TMP_DIR}/ecm-distro-tools.hash - TMP_BIN=${TMP_DIR}/ecm-distro-tools.bin cleanup() { code=$? set +e trap - EXIT - rm -rf ${TMP_DIR} - exit $code + rm -rf "${TMP_DIR}" + exit "$code" } trap cleanup INT EXIT } @@ -61,7 +59,7 @@ verify_downloader() { download() { case "${DOWNLOADER}" in *curl) - curl -o "$1" -fsSL "$2" + cd "$1" && { curl -fsSLO "$2" ; cd -; } ;; *wget) wget -qO "$1" "$2" @@ -80,15 +78,23 @@ download_tarball() { echo "downloading tarball from ${TARBALL_URL}" - download "${TMP_DIR}" "$1" + download "${TMP_DIR}" "${TARBALL_URL}" } # install_binaries installs the binaries from the downloaded tar. install_binaries() { cd "${TMP_DIR}" - tar zxvf "${TMP_DIR}/$1" - - find . -type f -name "*.${SUFFIX} -exec cp {} ${INSTALL_DIR}" \; + tar -xf "${TMP_DIR}/ecm-distro-tools.${SUFFIX}.tar.gz" + rm "${TMP_DIR}/ecm-distro-tools.${SUFFIX}.tar.gz" + mkdir -p "${INSTALL_DIR}" + + for f in * ; do + file_name="${f}" + if echo "${f}" | grep -q "${SUFFIX}"; then + file_name=${file_name%"-${SUFFIX}"} + fi + cp "${TMP_DIR}/${f}" "${INSTALL_DIR}/${file_name}" + done } { # main @@ -104,13 +110,10 @@ install_binaries() { setup_arch verify_downloader curl || verify_downloader wget || fatal "error: cannot find curl or wget" - download_tarball "${RELEASE_TARBALL}" - install_binaries "${RELEASE_TARBALL}" + download_tarball + install_binaries - printf "Run command to access tools:\n\nPATH=%s:%s" "${PATH}" "${INSTALL_DIR}" + printf "Run command to access tools:\n\nPATH=%s:%s\n\n" "${PATH}" "${INSTALL_DIR}" exit 0 } - - -