Skip to content

Commit

Permalink
scripts/validate: Fix git rev-parse when doing local builds
Browse files Browse the repository at this point in the history
When doing local builds (i.e. without $DRONE_REPO and $DRONE_PULL_REQUEST,
or $DRONE_COMMIT_REF set), the build fails with "fatal: Needed a single
revision" in `scripts/validate`:

```
> make REPO=tserong
[...]
Running validation
Running: go vet
refs/heads/wip-add-virtualSize
fatal: Needed a single revision
FATA[0032] exit status 128
make: *** [Makefile:11: ci] Error 1
```

If I run the commands in `scripts/validate` by hand, I see this:

```
> git symbolic-ref -q HEAD && REV="origin/HEAD" || REV="HEAD^"
refs/heads/wip-add-virtualSize
> echo $REV
origin/HEAD
> headSHA=$(git rev-parse --short=12 ${REV})
fatal: Needed a single revision
```

I don't know if this is just something weird about my environment, but
if I change "origin/HEAD" to "HEAD", it works fine:

```
> headSHA=$(git rev-parse --short=12 HEAD)
> echo $headSHA
eb27fbf6e678
```

Signed-off-by: Tim Serong <tserong@suse.com>
(cherry picked from commit 9707ff0)

# Conflicts:
#	scripts/validate
  • Loading branch information
tserong authored and mergify[bot] committed Apr 4, 2024
1 parent 142c851 commit 98dae36
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions scripts/validate
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,31 @@ PACKAGES="$(find . -name '*.go' | grep -Ev '.pb.go' | xargs -I{} dirname {} | \
echo Packages: ${PACKAGES}
echo Running: go vet
go vet ${PACKAGES}
<<<<<<< HEAD
echo Running: golint
for i in ${PACKAGES}; do
if [ -n "$(golint $i | grep -v 'should have comment.*or be unexported' | grep -v 'just return error instead.' | tee /dev/stderr)" ]; then
failed=true
fi
done
test -z "$failed"
=======

if [ ! -z "${DRONE_REPO}" ] && [ ! -z "${DRONE_PULL_REQUEST}" ]; then
wget https://github.com/$DRONE_REPO/pull/$DRONE_PULL_REQUEST.patch
echo "Running: golangci-lint run --new-from-patch=${DRONE_PULL_REQUEST}.patch"
golangci-lint run --new-from-patch="${DRONE_PULL_REQUEST}.patch"
rm "${DRONE_PULL_REQUEST}.patch"
elif [ ! -z "${DRONE_COMMIT_REF}" ]; then
echo "Running: golangci-lint run --new-from-rev=${DRONE_COMMIT_REF}"
golangci-lint run --new-from-rev=${DRONE_COMMIT_REF}
else
git symbolic-ref -q HEAD && REV="HEAD" || REV="HEAD^"
headSHA=$(git rev-parse --short=12 ${REV})
echo "Running: golangci-lint run --new-from-rev=${headSHA}"
golangci-lint run --new-from-rev=${headSHA}
fi

>>>>>>> 9707ff03 (scripts/validate: Fix `git rev-parse` when doing local builds)
echo Running: go fmt
test -z "$(go fmt ${PACKAGES} | tee /dev/stderr)"

0 comments on commit 98dae36

Please sign in to comment.