Skip to content

Commit

Permalink
Refactor; auto-check a tag after it was pushed
Browse files Browse the repository at this point in the history
  • Loading branch information
MihaiBojin committed Jul 22, 2020
1 parent 399fd6a commit 588ba31
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 16 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/release-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
on:
push:
tags:
- v0.*.*
- v1.*.*

jobs:
tests:
name: Continuous Integration Tests
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2

- name: Checking the code
run: make tools lint test

- name: Checking the version
run: make check-version
12 changes: 11 additions & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,36 @@ link-git-hooks:
find .git/hooks -type l -exec rm {} \;
find githooks -type f -exec ln -sf ../../{} .git/hooks/ \;

.PHONY: build
build:
go install ./$(PKG_NAME)

.PHONY: test
test:
go test $(SOURCE_FILES) -coverprofile $(COVERAGE) -timeout=30s -parallel=4 -cover -race

.PHONY: fmt
fmt:
@echo "==> Fixing source code with gofmt..."
gofmt -s -w ./$(PKG_NAME)
goimports -w ./$(PKG_NAME)

.PHONY: lint-fix
lint-fix:
golangci-lint run --fix

.PHONY: lint
lint:
golangci-lint run $(SOURCE_FILES)

.PHONY: check
check: test lint-fix

.PHONY: tools
tools:
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s $(GOLANGCI_VERSION)

.PHONY: build test fmt lint lint-fix check tools
TAG=$(shell git describe --tags --dirty --always)
.PHONY: check-version
check-version:
scripts/check-version.sh "$(TAG)"
17 changes: 2 additions & 15 deletions githooks/pre-push
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#!/usr/bin/env bash
#
# A simple pre-push hook which ensures that the tag being pushed to GitHub
# matches the version defined in the VERSION_FILE.
# matches the version defined in code.
#
declare -r VERSION_FILE="mongodbatlas/mongodbatlas.go"

# Determine if a tag is being pushed
tag=
input=$(</dev/stdin)
Expand All @@ -20,16 +18,5 @@ done

# Releasing a tag
if [[ -n "$tag" ]]; then
echo ""
echo "Releasing '$tag'..."
if ! grep -q "Version = \"$tag\"" "$VERSION_FILE"; then
echo ""
echo "ERROR: Mismatch between the release version ('$tag') and '$VERSION_FILE'"
echo "$VERSION_FILE:"
echo "---------"
grep "Version = " "$VERSION_FILE"
echo "---------"
echo
exit 1
fi
make check-version TAG="$tag"
fi
29 changes: 29 additions & 0 deletions scripts/check-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
#
# A simple script which ensures that the specified tag
# matches the version defined in the VERSION_FILE.
#
set -ueo pipefail
declare -r VERSION_FILE="mongodbatlas/mongodbatlas.go"

if [[ $# -lt 1 ]]; then
echo ""
echo "Error: TAG not specified"
echo "Usage: check-version.sh TAG"
echo ""
exit 1
fi
tag="$1"

echo ""
echo "Checking '$tag'..."
if ! grep -q "Version = \"$tag\"" "$VERSION_FILE"; then
echo ""
echo "ERROR: Mismatch between the release version ('$tag') and '$VERSION_FILE'"
echo "$VERSION_FILE:"
echo "---------"
grep "Version = " "$VERSION_FILE"
echo "---------"
echo
exit 1
fi

0 comments on commit 588ba31

Please sign in to comment.