Skip to content

Commit

Permalink
Merge pull request #20 from ivanilves/improve-goreleaser
Browse files Browse the repository at this point in the history
chore: offload release work to GoReleaser bot
  • Loading branch information
ivanilves authored Nov 3, 2022
2 parents c065291 + fcb97c5 commit 9be7e69
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 175 deletions.
45 changes: 24 additions & 21 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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 }}
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@
# Dependency directories
vendor/

# secret Makefile
secrets.mk

# Compiled binaries and assets
/cmd/travelgrunt/*
!/cmd/travelgrunt/*.go
/release/*
!/release/.gitkeep
/dist/*
49 changes: 28 additions & 21 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -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:'
70 changes: 13 additions & 57 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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):

```
Expand All @@ -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;
Expand Down
Empty file removed release/.gitkeep
Empty file.
30 changes: 0 additions & 30 deletions scripts/github-create-release.sh

This file was deleted.

34 changes: 0 additions & 34 deletions scripts/github-upload-assets.sh

This file was deleted.

2 changes: 1 addition & 1 deletion scripts/install-latest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 9be7e69

Please sign in to comment.