Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions .ci.ghactions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,40 @@

set -euo pipefail

declare -A seen
seen=("")
status=0

for w in .github/workflows/*.yml
do
sed -n -e '/uses: / s!^ *-\{0,1\} uses: \([^@]*\)@\([0-9a-f][0-9a-f]*\) *# *\(v.*\)$!\1 \2 \3!p' "$w" | while read -r action hash tag
actions="$(sed -n -e '/uses: / s!^ *-\{0,1\} uses: \([^@]*\)@\([0-9a-f][0-9a-f]*\) *# *\(v.*\)$!\1 \2 \3!p' "$w")"
while read -r action hash tag
do
if (( ${seen["$action-$hash-$tag"]:-0} )); then
printf "\e[1;32m%s: %s@%s == %s\e[m\n" "$w" "$action" "$tag" "$hash"
if [[ -z "$action" ]]; then
continue
fi
key="$action-$hash-$tag"
duplicate=0
for seen_key in "${seen[@]}"
do
if [[ "$seen_key" == "$key" ]]; then
duplicate=1
break
fi
done
if (( duplicate )); then
continue
fi
seen["$action-$hash-$tag"]=1
seen+=("$key")

if eval "$( curl -s -H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/$action/commits/$tag" | jq -r '.sha == "'"$hash"'"' )"
if curl --fail --silent --show-error -H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/$action/commits/$tag" | jq -e --arg hash "$hash" '.sha == $hash' >/dev/null
then
printf "\e[1;32m%s: %s@%s == %s\e[m\n" "$w" "$action" "$tag" "$hash"
else
printf "\e[1;31m%s: %s@%s != %s\e[m\n" "$w" "$action" "$tag" "$hash"
status=1
fi
done
done <<< "$actions"
done

exit $status
6 changes: 4 additions & 2 deletions .ci.gofmt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

set -euo pipefail

if [ -n "$(gofmt -l .)" ]; then
unformatted_files="$(gofmt -l .)"
if [ -n "$unformatted_files" ]; then
echo "Go code is not formatted:"
gofmt -d .
exit 1
Expand All @@ -11,7 +12,8 @@ fi
go run ./_readme-gofmt/main.go

go generate ./...
if [ -n "$(git status -s -uno)" ]; then
repository_status="$(git status --short)"
if [ -n "$repository_status" ]; then
echo "Go generate output does not match commit."
echo "Did you forget to run go generate ./... ?"
exit 1
Expand Down
9 changes: 7 additions & 2 deletions .ci.gogenerate.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
#!/usr/bin/env bash

set -euo pipefail

# If GOMOD is defined we are running with Go Modules enabled, either
# automatically or via the GO111MODULE=on environment variable. Codegen only
# works with modules, so skip generation if modules is not in use.
if [[ -z "$(go env GOMOD)" ]]; then
gomod="$(go env GOMOD)"
if [[ -z "$gomod" ]]; then
echo "Skipping go generate because modules not enabled and required"
exit 0
fi

go generate ./...
if [ -n "$(git diff)" ]; then
repository_status="$(git status --short)"
if [ -n "$repository_status" ]; then
echo "Go generate had not been run"
git status --short
git diff
exit 1
fi
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
go-version: ${{ matrix.go_version }}
- run: ./.ci.gogenerate.sh
- run: ./.ci.gofmt.sh
if: matrix.go_version == 'stable'
- run: ./.ci.govet.sh
- run: go test -v -race ./...

Expand All @@ -33,6 +34,7 @@ jobs:
- "1.22"
- "1.23"
- "1.24"
- "1.25"
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Setup Go
Expand Down