Skip to content

Commit c67c068

Browse files
authored
Merge branch 'master' into dolmen/codegen-modernize
2 parents 0389302 + a463c8c commit c67c068

6 files changed

Lines changed: 158 additions & 27 deletions

File tree

.ci.ghactions.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env bash
2+
3+
# MIT License
4+
#
5+
# Copyright (c) 2026 Olivier Mengué and contributors.
6+
#
7+
# Permission is hereby granted, free of charge, to any person obtaining a copy
8+
# of this software and associated documentation files (the "Software"), to deal
9+
# in the Software without restriction, including without limitation the rights
10+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
# copies of the Software, and to permit persons to whom the Software is
12+
# furnished to do so, subject to the following conditions:
13+
#
14+
# The above copyright notice and this permission notice shall be included in all
15+
# copies or substantial portions of the Software.
16+
#
17+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
# SOFTWARE.
24+
25+
#
26+
# Verify that hashes of GitHub actions match the declared tag in attached comment.
27+
#
28+
29+
set -euo pipefail
30+
31+
declare -A seen
32+
status=0
33+
34+
for w in .github/workflows/*.yml
35+
do
36+
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
37+
do
38+
if (( ${seen["$action-$hash-$tag"]:-0} )); then
39+
printf "\e[1;32m%s: %s@%s == %s\e[m\n" "$w" "$action" "$tag" "$hash"
40+
continue
41+
fi
42+
seen["$action-$hash-$tag"]=1
43+
44+
if eval "$( curl -s -H "Accept: application/vnd.github+json" \
45+
"https://api.github.com/repos/$action/commits/$tag" | jq -r '.sha == "'"$hash"'"' )"
46+
then
47+
printf "\e[1;32m%s: %s@%s == %s\e[m\n" "$w" "$action" "$tag" "$hash"
48+
else
49+
printf "\e[1;31m%s: %s@%s != %s\e[m\n" "$w" "$action" "$tag" "$hash"
50+
status=1
51+
fi
52+
done
53+
done
54+
55+
exit $status

.ci.gofmt.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
#!/usr/bin/env bash
22

3+
set -euo pipefail
4+
35
if [ -n "$(gofmt -l .)" ]; then
46
echo "Go code is not formatted:"
57
gofmt -d .
68
exit 1
79
fi
810

11+
go run ./_readme-gofmt/main.go
12+
913
go generate ./...
1014
if [ -n "$(git status -s -uno)" ]; then
1115
echo "Go generate output does not match commit."

.ci.readme.fmt.sh

Lines changed: 0 additions & 12 deletions
This file was deleted.

.github/workflows/main.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@ jobs:
1515
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
1616
with:
1717
go-version: ${{ matrix.go_version }}
18-
- run: npm install -g mdsf-cli
1918
- run: ./.ci.gogenerate.sh
2019
- run: ./.ci.gofmt.sh
21-
- run: ./.ci.readme.fmt.sh
2220
- run: ./.ci.govet.sh
2321
- run: go test -v -race ./...
24-
test:
22+
23+
test-old-go:
2524
runs-on: ubuntu-latest
2625
strategy:
2726
matrix:
@@ -41,3 +40,9 @@ jobs:
4140
with:
4241
go-version: ${{ matrix.go_version }}
4342
- run: go test -v -race ./...
43+
44+
check-actions-hashes:
45+
runs-on: ubuntu-latest
46+
steps:
47+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
48+
- run: ./.ci.ghactions.sh

.mdsf.json

Lines changed: 0 additions & 12 deletions
This file was deleted.

_readme-gofmt/main.go

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
//go:build go1.21
2+
3+
/*
4+
MIT License
5+
6+
Copyright (c) 2026 Olivier Mengué and contributors.
7+
8+
Permission is hereby granted, free of charge, to any person obtaining a copy
9+
of this software and associated documentation files (the "Software"), to deal
10+
in the Software without restriction, including without limitation the rights
11+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
copies of the Software, and to permit persons to whom the Software is
13+
furnished to do so, subject to the following conditions:
14+
15+
The above copyright notice and this permission notice shall be included in all
16+
copies or substantial portions of the Software.
17+
18+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24+
SOFTWARE.
25+
*/
26+
27+
// Command readme-gofmt applies 'gofmt -s' to all Go block in README.md.
28+
package main
29+
30+
import (
31+
"bytes"
32+
"log"
33+
"os"
34+
"os/exec"
35+
"regexp"
36+
"slices"
37+
)
38+
39+
func main() {
40+
log.SetFlags(0)
41+
log.SetPrefix("readme-gofmt: ")
42+
43+
buf, err := os.ReadFile("README.md")
44+
if err != nil {
45+
log.Fatal(err)
46+
}
47+
48+
gofmt, err := exec.LookPath("gofmt")
49+
if err != nil {
50+
log.Fatal(err)
51+
}
52+
53+
buf = bytes.ReplaceAll(buf, []byte("\r"), nil) // CRLF -> LF
54+
55+
reBlock := regexp.MustCompile("(?s)\n```go\n(.*?\n)```")
56+
57+
matches := reBlock.FindAllSubmatchIndex(buf, -1)
58+
59+
changes := 0
60+
61+
for i := len(matches) - 1; i >= 0; i-- {
62+
match := matches[i]
63+
block := buf[match[2]:match[3]]
64+
65+
cmd := exec.Command(gofmt, "-s")
66+
cmd.Stdin = bytes.NewReader(block)
67+
var output bytes.Buffer
68+
cmd.Stdout = &output
69+
cmd.Stderr = os.Stderr
70+
err := cmd.Run()
71+
if err != nil {
72+
log.Fatal(err)
73+
}
74+
75+
outputBytes := bytes.ReplaceAll(output.Bytes(), []byte("\r"), []byte("")) // CRLF -> LF
76+
if !bytes.Equal(outputBytes, block) {
77+
changes++
78+
buf = slices.Replace(buf, match[2], match[3], outputBytes...)
79+
}
80+
}
81+
82+
if changes > 0 {
83+
cmd := exec.Command("diff", "-a", "-u", "README.md", "-")
84+
cmd.Stdin = bytes.NewReader(buf)
85+
cmd.Stdout = os.Stdout
86+
cmd.Stderr = os.Stderr
87+
cmd.Run()
88+
89+
os.Exit(2)
90+
}
91+
}

0 commit comments

Comments
 (0)