-
Notifications
You must be signed in to change notification settings - Fork 75
chore: Rewrite verify-commits script #3086
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1,51 +1,56 @@ | ||
| #!/bin/bash | ||
|
|
||
| # git for-each-ref refs/tags # see which tags are annotated and which are lightweight. Annotated tags are "tag" objects. | ||
| # # Set these so your commits and tags are always signed | ||
| # git config commit.gpgsign true | ||
| # git config tag.gpgsign true | ||
| # Annotated tags have object type "tag"; lightweight tags have type "commit". | ||
| # To inspect tags: git for-each-ref refs/tags | ||
| # | ||
| # To always sign commits and tags, configure: | ||
| # git config --global commit.gpgsign true | ||
| # git config --global tag.gpgsign true | ||
|
|
||
| verify_commit_signed() { | ||
| if git verify-commit HEAD &>/dev/null; then | ||
| : | ||
| # echo "HEAD commit seems signed..." | ||
| echo "HEAD commit is signed." | ||
| else | ||
| echo "HEAD commit isn't signed!" | ||
| echo "HEAD commit is not signed!" | ||
| exit 1 | ||
| fi | ||
| } | ||
|
|
||
| verify_tag() { | ||
| if git describe --exact-match --tags HEAD &>/dev/null; then | ||
| : # You might be ok to push | ||
| # echo "Tag is annotated." | ||
| return 0 | ||
| verify_tag_annotated() { | ||
| local version="$1" | ||
| # git cat-file -t returns "tag" for annotated tags, "commit" for lightweight. | ||
| if [[ "$(git cat-file -t "$version")" == "tag" ]]; then | ||
| echo "Tag '$version' is annotated." | ||
| else | ||
| echo "Tag for [$version] not an annotated tag." | ||
| echo "Tag '$version' is not annotated!" | ||
| echo "Re-create it with: git tag -a -s -m \"$version\" \"$version\"" | ||
| exit 1 | ||
| fi | ||
| } | ||
|
|
||
| verify_tag_signed() { | ||
| local version="$1" | ||
| if git verify-tag "$version" &>/dev/null; then | ||
| : # ok, I guess we'll let you push | ||
| # echo "Tag appears signed" | ||
| return 0 | ||
| echo "Tag '$version' is signed." | ||
| else | ||
| echo "$version tag isn't signed" | ||
| echo "Sign it with [git tag -ams\"$version\" $version]" | ||
| echo "Tag '$version' is not signed!" | ||
| echo "Sign it with: git tag -a -s -m \"$version\" \"$version\"" | ||
|
mathbunnyru marked this conversation as resolved.
|
||
| exit 1 | ||
| fi | ||
| } | ||
|
|
||
| # Check some things if we're pushing a branch called "release/" | ||
| if echo "$PRE_COMMIT_REMOTE_BRANCH" | grep ^refs\/heads\/release\/ &>/dev/null; then | ||
| version=$(git tag --points-at HEAD) | ||
| echo "Looks like you're trying to push a $version release..." | ||
| echo "Making sure you've signed and tagged it." | ||
| if verify_commit_signed && verify_tag && verify_tag_signed; then | ||
| : # Ok, I guess you can push | ||
| else | ||
| # Enforce signing and annotated tags when pushing to a release branch. | ||
| if echo "$PRE_COMMIT_REMOTE_BRANCH" | grep -q "^refs/heads/release/"; then | ||
| # git describe --exact-match guarantees a single tag; git tag --points-at HEAD | ||
| # can return multiple newline-separated values, which breaks downstream commands. | ||
| version=$(git describe --exact-match --tags HEAD 2>/dev/null) | ||
| if [[ -z "$version" ]]; then | ||
| echo "No tag found at HEAD — cannot push an untagged release commit!" | ||
| exit 1 | ||
| fi | ||
|
mathbunnyru marked this conversation as resolved.
|
||
| echo "Looks like you're trying to push a '$version' release..." | ||
| echo "Verifying the commit is signed and the tag is annotated and signed." | ||
| verify_commit_signed | ||
| verify_tag_annotated "$version" | ||
| verify_tag_signed "$version" | ||
| fi | ||
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.
Uh oh!
There was an error while loading. Please reload this page.