-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a hook to ensure the client's version is updated before pushing a tag/release #115
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a6d4204
Add pre-push hook
MihaiBojin 399fd6a
Code Review
MihaiBojin c30f464
Refactor; auto-check a tag after it was pushed
MihaiBojin 06fb4ef
updated action title
MihaiBojin ed14165
fix link
MihaiBojin 4ce6a51
fix nl
MihaiBojin File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
on: | ||
push: | ||
tags: | ||
- v0.*.* | ||
- v1.*.* | ||
|
||
jobs: | ||
tests: | ||
name: Release sanity tests | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Checking code health | ||
run: make tools lint test | ||
|
||
- name: Checking the version | ||
run: make check-version | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated for consistency |
||
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=$(patsubst v%,%,$(shell git describe --tags --dirty --always)) | ||
.PHONY: check-version | ||
check-version: | ||
scripts/check-version.sh "$(TAG)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# A simple pre-push hook which ensures that the tag being pushed to GitHub | ||
# matches the version defined in code. | ||
# | ||
# Determine if a tag is being pushed | ||
tag= | ||
input=$(</dev/stdin) | ||
for arg in $input; do | ||
if [[ "$arg" =~ ^refs\/tags ]]; then | ||
tag="${arg/refs\/tags\//}" | ||
if [[ "$tag" =~ ^v ]]; then | ||
# Remove the 'v' prefix | ||
tag="${tag:1}" | ||
fi | ||
fi | ||
done | ||
|
||
# Releasing a tag | ||
if [[ -n "$tag" ]]; then | ||
make check-version TAG="$tag" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/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 | ||
echo "OK." | ||
echo |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This workflow will ensure that we get notified when a tag was pushed and the version was not updated.