Skip to content

Commit

Permalink
feat: improve release and version targets (#55)
Browse files Browse the repository at this point in the history
Signed-off-by: Tronje Krop <[email protected]>
  • Loading branch information
tkrop committed Feb 8, 2024
1 parent 34bc29d commit 4628577
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 35 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ jobs:
GH_TOKEN: ${{ github.token }}
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
run: |-
make --file=config/Makefile.base --trace release
make --file=config/Makefile.base --trace version-release
- name: Publish new version
env:
GH_TOKEN: ${{ github.token }}
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
run: |-
make --file=config/Makefile.base --trace publish || true
make --file=config/Makefile.base --trace version-publish || true
17 changes: 11 additions & 6 deletions MANUAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ target groups:
* [Release targets](#run-targets)
* [Install targets](#install-targets)
* [Uninstall targets](#uninstall-targets)
* [Release targets](#release-targets)
* [Version targets](#version-targets)
* [Update targets](#update-targets)
* [Cleanup targets](#cleanup-targets)
* [Init targets](#init-targets) (usually no need to call)
Expand Down Expand Up @@ -533,16 +533,21 @@ make uninstall-* # uninstalls the matched software command or service
**Note:** Please use carefully, if your project uses common command names.


### Release targets
### Version targets

Finally, the [Makefile](config/Makefile.base) supports targets for releasing the
provided packages as library.
Finally, the [Makefile](config/Makefile.base) supports targets for bumping,
releasing, and publishing the provided packages as library.

```bash
make bump <version> # bumps version to prepare a new release
make release # creates the release tags in the repository
make version-bump <version> # bumps version to prepare a new release
make version-release # creates the release tags in the repository
make version-publish #
```

The `version-bump` target supports an optional `<version>` argument that allows
to name define a version or increment the version using the semantic keywords
`major`, `minor`, and `patch` to signal the scope.


### Init targets

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export GO ?= go
export GOPATH ?= $(shell $(GO) env GOPATH)
export GOBIN ?= $(GOPATH)/bin
# Setup go-make to utilize desired build and config scripts.
GOMAKE_DEP ?= github.com/tkrop/[email protected].56
GOMAKE_DEP ?= github.com/tkrop/[email protected].58
# Request targets from go-make targets target.
TARGETS := $(shell command -v $(GOBIN)/go-make >/dev/null || \
$(GO) install $(GOMAKE_DEP) >/dev/stderr && \
Expand Down
2 changes: 1 addition & 1 deletion Makefile.ext
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ LDFLAGS := -X main.Config=$(CURDIR)/config
clean::
find -name "__debug_bin*" -exec rm -vrf {} \;;

bump bump-reset::
version-bump version-bump-reset::
@VERSION="$$(cat VERSION)"; \
sed -i -e "s#\(github.com[/:]tkrop/go-make@v\)[^ ]*#\1$${VERSION}#" \
Makefile config/Makefile config/Makefile.base; \
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.56
0.0.58
2 changes: 1 addition & 1 deletion config/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export GO ?= go
export GOPATH ?= $(shell $(GO) env GOPATH)
export GOBIN ?= $(GOPATH)/bin
# Setup go-make to utilize desired build and config scripts.
GOMAKE_DEP ?= github.com/tkrop/[email protected].56
GOMAKE_DEP ?= github.com/tkrop/[email protected].58
# Request targets from go-make targets target.
TARGETS := $(shell command -v $(GOBIN)/go-make >/dev/null || \
$(GO) install $(GOMAKE_DEP) >/dev/stderr && \
Expand Down
34 changes: 19 additions & 15 deletions config/Makefile.base
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ go-pkg = $(shell awk -v mode="$(2)" -v filter="$(3)" \
}' <<<"$(1)")

# Setup go-make to use desired build and config scripts.
GOMAKE_DEP := github.com/tkrop/[email protected].56
GOMAKE_DEP := github.com/tkrop/[email protected].58
GOMAKE_MAKEFILE := $(realpath $(firstword $(MAKEFILE_LIST)))
GOMAKE_CONFIG := $(patsubst %/,%,$(dir $(GOMAKE_MAKEFILE)))

Expand Down Expand Up @@ -316,7 +316,7 @@ COMMANDS_SH := $(sort $(call go-pkg,$(TOOLS_SH),command,$(COMMANDS_REGEX),not,))


# Setup of runtime arguments for commands that support arguments.
CMDWORDS ?= show git- test- lint run- bump release update
CMDWORDS ?= show git- test- lint run- version- update
CMDARGS ?= $(shell awk '{ split("$(CMDWORDS)",seps); \
for (i = 1; i <= NF; i++) { if (found) { \
line = ((line) ? line " " $$i : $$i); continue \
Expand Down Expand Up @@ -350,7 +350,7 @@ MOCKS := $(shell for TARGET in $(MOCK_TARGETS); \
do echo "$${TARGET%%=*}"; done | sort --unique)

# Prepare target lists used to define rules and preconditions.
TARGETS_PUBLISH := $(addprefix publish-, all $(COMMANDS))
TARGETS_PUBLISH := $(addprefix version-publish-, all $(COMMANDS))
TARGETS_TEST_INIT := test-clean init-sources init-hooks
TARGETS_INIT_MAKE := $(addprefix init/,$(INIT_MAKE))
TARGETS_INIT_ALL := $(addprefix init/,$(sort $(INIT_MAKE) $(UPDATE_MAKE)))
Expand Down Expand Up @@ -1264,7 +1264,7 @@ $(TARGETS_UNINSTALL):: uninstall-%:


## Release: targets to support release process.
bump-version = \
version-bump = \
$$(awk -v arg="$(1)" '{ \
op["major"] = 1; op["minor"] = 2; op["patch"] = 3; \
if ((pos = op[substr(arg,1,5)]) == 0) { \
Expand All @@ -1279,36 +1279,36 @@ bump-version = \
}' "$(2)")

#@ <version|major|minor|patch>[+-]{}? # update version and prepare release of the software.
bump::
version-bump::
@if [ -z "$(RUNARGS)" ]; then ARGS="patch"; else ARGS="$(RUNARGS)"; fi; \
if [ ! -e VERSION ]; then echo "0.0.0" >VERSION; fi; \
if [[ "$${ARGS}" =~ ^(major|minor|patch|)[+-]*$$ ]]; then \
VERSION="$(call bump-version,$${ARGS},VERSION)"; \
VERSION="$(call version-bump,$${ARGS},VERSION)"; \
elif ! [[ "$${ARGS}" =~ ^[0-9]+(\.[0-9]+){0,2}(-.*)?$$ ]]; then \
echo "error: invalid new version [$${ARGS}]"; exit 1; \
else VERSION="$${ARGS}"; fi; echo $${VERSION} >VERSION; \
echo -e "$(call msuccess, bumped version [$${VERSION}])"; \


#@ <version> # release a fixed version of the software as library.
release::
version-release::
@if [ -f VERSION ]; then VERSION="$$(cat VERSION)"; fi; \
if [[ "$(RUNARGS)" =~ ^[0-9]+(\.[0-9]+){0,2}(-.*)?$$ ]]; then \
VERSION="$(RUNARGS)"; \
fi; $(GIT) fetch --verbose --tags; \
if [ -n "$${VERSION}" -a -z "$$($(GIT) tag --list "v$${VERSION}")" ]; then \
( $(GIT) gh-release "v$${VERSION}" ) || ( \
$(GIT) config user.name "$$($(GIT) log -n 1 --pretty=format:%an)" && \
$(GIT) config user.email "$$($(GIT) log -n 1 --pretty=format:%ae)" && \
$(GIT) config user.name "$$($(GIT) log -n 1 --pretty=format:%an)" && \
$(GIT) config user.email "$$($(GIT) log -n 1 --pretty=format:%ae)" && \
$(GIT) tag --message "tag: new version $${VERSION}" "v$${VERSION}" && \
$(GIT) push --follow-tags --verbose origin "v$${VERSION}" \
$(GIT) push --follow-tags --verbose origin "v$${VERSION}" \
) && echo -e "$(call msuccess, release version [v$${VERSION}])" || \
echo -e "$(call mfailure, release version [v$${VERSION}])"; \
fi; \

#@ publish the current version by enforcing a registry lookup (experimental).
publish:: $(TARGETS_PUBLISH)
$(TARGETS_PUBLISH): publish-%:
version-publish:: $(TARGETS_PUBLISH)
$(TARGETS_PUBLISH): version-publish-%:
@if [ "$*" != "all" ]; then \
if [ -f "cmd/$*/main.go" ]; then CMD="/cmd/$*"; else exit 0; fi; \
fi; \
Expand All @@ -1319,13 +1319,17 @@ $(TARGETS_PUBLISH): publish-%:
TARGET="$(GITREPO)$${CMD}@v$${VERSION}"; \
if [ "$(GITHOSTNAME)" == "github.com" ]; then \
if [ -z "$${CMD}" ]; then \
echo "publish: curl $${TARGET}"; \
echo -e "$(call minfo,publish via curl [$${TARGET}])"; \
curl --silent --show-error --fail --location \
https://sum.golang.org/lookup/$${TARGET};\
https://sum.golang.org/lookup/$${TARGET} && \
echo -e "$(call success,publish via curl [$${TARGET}])" || \
echo -e "$(call failure,publish via curl [$${TARGET}])"; \
fi; \
if [ -f ".$${CMD}/main.go" ]; then \
echo "publish: go install $${TARGET}"; \
echo -e "$(call minfo,publish go install [$${TARGET}])"; \
$(GO) install $(INSTALL_FLAGS) $${TARGET}; \
echo -e "$(call success,publish go install [$${TARGET}])" || \
echo -e "$(call failure,publish go install [$${TARGET}])"; \
fi; \
fi;

Expand Down
8 changes: 4 additions & 4 deletions internal/make/fixtures/targets-trace.out
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ build
build-image
build-linux
build-native
bump
clean
clean-all
clean-build
Expand Down Expand Up @@ -114,9 +113,6 @@ lint-revive
lint-shell
lint-staticcheck
lint-vuln
publish
publish-all
release
run-aws
run-clean
run-clean-aws
Expand Down Expand Up @@ -198,3 +194,7 @@ update/go.mod?
update/revive.toml
update/revive.toml?
update?
version-bump
version-publish
version-publish-all
version-release
8 changes: 4 additions & 4 deletions internal/make/fixtures/targets.out
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ build
build-image
build-linux
build-native
bump
clean
clean-all
clean-build
Expand Down Expand Up @@ -110,9 +109,6 @@ lint-revive
lint-shell
lint-staticcheck
lint-vuln
publish
publish-all
release
run-aws
run-clean
run-clean-aws
Expand Down Expand Up @@ -194,3 +190,7 @@ update/go.mod?
update/revive.toml
update/revive.toml?
update?
version-bump
version-publish
version-publish-all
version-release

0 comments on commit 4628577

Please sign in to comment.