From fcb97c5e348e82c2d74c9447e2af2c5cd518997b Mon Sep 17 00:00:00 2001 From: Ivan Ilves Date: Thu, 3 Nov 2022 07:44:55 +0100 Subject: [PATCH] chore: offload release work to GoReleaser bot :robot: --- .github/workflows/release.yml | 45 ++++++++++---------- .gitignore | 6 +-- .goreleaser.yml | 49 ++++++++++++---------- Makefile | 70 ++++++-------------------------- README.md | 14 ++++--- release/.gitkeep | 0 scripts/github-create-release.sh | 30 -------------- scripts/github-upload-assets.sh | 34 ---------------- scripts/install-latest.sh | 2 +- 9 files changed, 75 insertions(+), 175 deletions(-) delete mode 100644 release/.gitkeep delete mode 100755 scripts/github-create-release.sh delete mode 100755 scripts/github-upload-assets.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ecc6dd0..affd89c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,30 +1,33 @@ -name: goreleaser +name: release on: push: tags: - - '*' + - '*' jobs: goreleaser: runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - name: Set up Go - uses: actions/setup-go@v3 - with: - go-version: 1.19 - - name: Set RELEASE_VERSION env - run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV - - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v3 - with: - distribution: goreleaser - version: latest - args: release --rm-dist - env: - GITHUB_TOKEN: ${{ secrets.TAP_GITHUB_TOKEN }} - TAP_GITHUB_TOKEN: ${{ secrets.TAP_GITHUB_TOKEN }} + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: 1.19 + + - name: Set RELEASE_VERSION env + run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV + + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v3 + with: + distribution: goreleaser + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.TAP_GITHUB_TOKEN }} + TAP_GITHUB_TOKEN: ${{ secrets.TAP_GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index 6855d23..c2ccd1f 100644 --- a/.gitignore +++ b/.gitignore @@ -14,11 +14,7 @@ # Dependency directories vendor/ -# secret Makefile -secrets.mk - # Compiled binaries and assets /cmd/travelgrunt/* !/cmd/travelgrunt/*.go -/release/* -!/release/.gitkeep +/dist/* diff --git a/.goreleaser.yml b/.goreleaser.yml index 33714ce..2416f05 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -1,34 +1,41 @@ before: hooks: - - go mod download + - go mod download + builds: - - goos: - - linux - - darwin - goarch: - - amd64 - - arm64 - main: ./cmd/travelgrunt/main.go - ldflags: - - -X main.appVersion={{.Env.RELEASE_VERSION}} +- goos: + - linux + - darwin + goarch: + - amd64 + - arm64 + main: ./cmd/travelgrunt/main.go + ldflags: + - -X main.appVersion={{.Env.RELEASE_VERSION}} + brews: - - name: travelgrunt - homepage: 'https://github.com/ivanilves/travelgrunt' - description: 'Travel Terragrunt directory tree as a first class passenger!' - folder: Formula - tap: - owner: ivanilves - name: homebrew-travelgrunt +- name: travelgrunt + homepage: 'https://github.com/ivanilves/travelgrunt' + description: 'Travel Terragrunt directory tree as a first class passenger!' + folder: Formula + tap: + owner: ivanilves + name: homebrew-tap + archives: - - name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}" - format: tar.gz +- name_template: "{{ .ProjectName }}_{{ .Tag }}_{{ .Os }}_{{ .Arch }}" + format: tar.gz + checksum: name_template: 'checksums.txt' + snapshot: name_template: "{{ .Tag }}-next" + changelog: sort: asc filters: exclude: - - '^docs:' - - '^test:' + - '^docs:' + - '^test:' + - '^skip:' diff --git a/Makefile b/Makefile index 9670052..c35ddec 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,10 @@ APP_NAME := travelgrunt -GITHUB_REPO := ivanilves/travelgrunt API_VERSION := 0.2 +BUILD_PATH := ./cmd/${APP_NAME} -APP_VERSION := $(shell (git fetch --tags && git tag --sort=creatordate | grep -F "v${API_VERSION}." || echo UNDEFINED) | tail -n1) -CURRENT_PATCH := $(shell (git fetch --tags && git tag --sort=creatordate | grep -F "v${API_VERSION}." || echo -1) | tail -n1 | sed -r "s/^v([0-9]+\.){2}//") -NEXT_PATCH := $(shell expr ${CURRENT_PATCH} + 1) -NEXT_VERSION := v${API_VERSION}.${NEXT_PATCH} - -BUILD_PATH := ./cmd/${APP_NAME} -RELEASE_PATH := ./release - --include secrets.mk +CURRENT_PATCH = $(shell (git fetch --tags && git tag --sort=creatordate | grep -F "v${API_VERSION}." || echo -1) | tail -n1 | sed -r "s/^v([0-9]+\.){2}//") +NEXT_PATCH = $(shell expr ${CURRENT_PATCH} + 1) +NEXT_VERSION = v${API_VERSION}.${NEXT_PATCH} default: dep build @@ -26,57 +20,19 @@ build: cd ${BUILD_PATH} && go build clean: - git clean -fdx -e secrets.mk + git clean -fdx -install: PREFIX := /usr/local +install: PREFIX ?= /usr/local install: install ${BUILD_PATH}/travelgrunt ${PREFIX}/bin/ -changelog: LAST_RELEASED_TAG:=$(shell git tag --sort=creatordate | tail -n1) -changelog: GITHUB_COMMIT_URL:=https://github.com/${GITHUB_REPO}/commit -changelog: - @echo "## Changelog" \ - && git log --oneline --reverse ${LAST_RELEASED_TAG}..HEAD | egrep -iv "^[0-9a-f]{7,} (Merge pull request |Merge branch |.*NORELEASE)" | \ - sed -r "s|^([0-9a-f]{7,}) (.*)|* [\`\1\`](${GITHUB_COMMIT_URL}/\1) \2|" - -release-binary: GOOS ?= $(shell uname -s | tr '[A-Z]' '[a-z]') -release-binary: GOARCH ?= $(shell uname -m | sed 's/x86_64/amd64/') -release-binary: LDFLAGS := "-X 'main.appVersion=${NEXT_VERSION}'" -release-binary: - mkdir -p ${RELEASE_PATH}/${APP_NAME}-${GOOS}-${GOARCH} && cd ${BUILD_PATH} && \ - GOOS=${GOOS} GOARCH=${GOARCH} go build -mod=vendor -ldflags ${LDFLAGS} -o ../../${RELEASE_PATH}/${APP_NAME}-${GOOS}-${GOARCH}/${APP_NAME} - -release-binaries: - ${MAKE} --no-print-directory release-binary GOOS=linux GOARCH=amd64 - ${MAKE} --no-print-directory release-binary GOOS=darwin GOARCH=amd64 - ${MAKE} --no-print-directory release-binary GOOS=darwin GOARCH=arm64 - -release-artifacts: - cd ${RELEASE_PATH} && find . -mindepth 1 -maxdepth 1 -type d | xargs -i tar -C {} -zc ${APP_NAME} -f {}.tar.gz - -release-metadata: - echo ${NEXT_VERSION} >${RELEASE_PATH}/TAG - echo ${NEXT_VERSION} >${RELEASE_PATH}/NAME - ${MAKE} --no-print-directory changelog >${RELEASE_PATH}/CHANGELOG.md - cp -f README.md ${RELEASE_PATH}/ - -release: release-binaries release-artifacts release-metadata +check-git-branch: GIT_BRANCH ?= main +check-git-branch: + @if [ `git rev-parse --abbrev-ref HEAD` != ${GIT_BRANCH} ]; \ + then echo "ERR: Need to be on the \"${GIT_BRANCH}\" branch" >>/dev/stderr; \ + exit 1; fi next-version-tag: - git tag ${NEXT_VERSION} - -push-tags: - git push --tags - -github-release: - scripts/github-create-release.sh ${GITHUB_REPO} ./release - -github-assets: - scripts/github-upload-assets.sh ${GITHUB_REPO} ./release - -github: github-release github-assets - -github-token: - @test -n "${GITHUB_TOKEN}" || (echo "GITHUB_TOKEN not set!" >>/dev/stderr; exit 1) + git tag ${NEXT_VERSION} && git push --tags -full-release: github-token clean dep release next-version-tag push-tags github +release: check-git-branch next-version-tag diff --git a/README.md b/README.md index b50c37f..35d4304 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,14 @@ the shell with aliases `travelgrunt` will not work! ## How to install? +### Install with homebrew + +``` +brew tap ivanilves/tap +brew install ivanilves/tap/travelgrunt +``` + +### Install latest binary with cURL Install latest release binary into `/usr/local/bin` (default): ``` @@ -39,12 +47,6 @@ curl -s -f \ | PREFIX=/somewhere/else sh ``` -Install with homebrew: -``` -brew tap ivanilves/travelgrunt -brew install ivanilves/travelgrunt -``` - ## How to build? * `make dep` - install/ensure dependencies; diff --git a/release/.gitkeep b/release/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/scripts/github-create-release.sh b/scripts/github-create-release.sh deleted file mode 100755 index 9f3d6e7..0000000 --- a/scripts/github-create-release.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env bash -# -if [[ ${#} -ne 2 ]]; then - echo "Create release on GitHub" - echo "Usage: ${0} GITHUB_REPO RELEASE_PATH" >>/dev/stderr - exit 1 -fi - -if [[ -z "${GITHUB_TOKEN}" ]]; then - echo "GITHUB_TOKEN not set" >>/dev/stderr - exit 1 -fi - -set -euo pipefail - -declare -r GITHUB_REPO="${1}" -declare -r RELEASE_PATH="${2}" - -declare -r API_URL=https://api.github.com/repos/${GITHUB_REPO}/releases - -pushd "${RELEASE_PATH}" - declare -r TAG="$(cat TAG)" - declare -r NAME="$(cat NAME)" - declare -r BODY="$(sed 's/$/\\n/' CHANGELOG.md | tr -d '\n' | sed 's/\"/\\"/g')" - declare -r DATA="{\"tag_name\":\"${TAG}\", \"target_commitish\": \"main\",\"name\": \"${NAME}\", \"body\": \"${BODY}\", \"draft\": false, \"prerelease\": false}" - - curl -f -X POST -H "Content-Type:application/json" \ - -H "Authorization: Token ${GITHUB_TOKEN}" "${API_URL}" \ - -d "${DATA}" -popd diff --git a/scripts/github-upload-assets.sh b/scripts/github-upload-assets.sh deleted file mode 100755 index 3560d5c..0000000 --- a/scripts/github-upload-assets.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env bash -# -if [[ ${#} -ne 2 ]]; then - echo "Upload assets to GitHub release" - echo "Usage: ${0} GITHUB_REPO ASSETS_PATH" >>/dev/stderr - exit 1 -fi - -if [[ -z "${GITHUB_TOKEN}" ]]; then - echo "GITHUB_TOKEN not set" >>/dev/stderr - exit 1 -fi - -set -euo pipefail - -declare -r GITHUB_REPO="${1}" -declare -r ASSETS_PATH="${2}" - -declare -r API_URL=https://api.github.com/repos/${GITHUB_REPO}/releases -declare -r UPLOAD_URL=https://uploads.github.com/repos/${GITHUB_REPO}/releases - -pushd "${ASSETS_PATH}" - declare -r TAG="$(cat TAG)" - - ID=$(curl -s -H "Authorization: Token ${GITHUB_TOKEN}" "${API_URL}/tags/${TAG}" | jq ".id") - - for FILE in $(find ./ -mindepth 1 -maxdepth 1 -type f -name "*.tar.gz"); do - curl -f -H "Content-Type: $(file -b --mime-type ${FILE})" \ - -H "Authorization: Token ${GITHUB_TOKEN}" \ - --data-binary @${FILE} \ - "${UPLOAD_URL}/${ID}/assets?name=$(basename ${FILE})" - echo - done -popd diff --git a/scripts/install-latest.sh b/scripts/install-latest.sh index 49dcc67..791c5df 100755 --- a/scripts/install-latest.sh +++ b/scripts/install-latest.sh @@ -11,4 +11,4 @@ LATEST_TAG=$(curl -s -f https://api.github.com/repos/ivanilves/travelgrunt/relea OS=$(uname -s | tr '[A-Z]' '[a-z]') ARCH=$(uname -m | sed 's/x86_64/amd64/') -curl -s -f -L -o - https://github.com/ivanilves/travelgrunt/releases/download/${LATEST_TAG}/travelgrunt-${OS}-${ARCH}.tar.gz | tar -xz -C ${PREFIX}/bin +curl -s -f -L -o - https://github.com/ivanilves/travelgrunt/releases/download/${LATEST_TAG}/travelgrunt_${LATEST_TAG}_${OS}_${ARCH}.tar.gz | tar -xz -C ${PREFIX}/bin