Skip to content

Commit 5287039

Browse files
authored
chore(tabler): update tabler to use go (#61)
* rm scripts update tools * update * ci * rm toolchain * update workflow * workflow * workflow * reset workflow
1 parent ab3edb9 commit 5287039

File tree

10 files changed

+180
-72
lines changed

10 files changed

+180
-72
lines changed

Makefile

+11-6
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@ ROWS=15
22
FILE="README.md"
33

44
build:
5-
./scripts/del-existing-rows.sh $(ROWS) $(FILE)
5+
# Delete existing table if it exists
6+
go run ./scripts format --rmtable --readme README.md
67

7-
go run scripts/generate-table.go -path ./presentations -out scripts/data.csv -rows $(ROWS)
8-
cat scripts/data.csv | go run moul.io/mdtable csv > scripts/table.md
8+
# Generate new table
9+
go run ./scripts -path ./presentations -out ./scripts/data.csv
10+
cat ./scripts/data.csv | go run moul.io/mdtable csv > ./scripts/table.md
911
go run github.com/campoy/embedmd -w README.md
12+
13+
# Remove codeblocks from embedmd
14+
go run ./scripts format --readme README.md
15+
1016
# Clean up
11-
rm scripts/data.csv scripts/table.md
17+
rm ./scripts/data.csv ./scripts/table.md
1218

13-
./scripts/del-codeblock.sh $(FILE)
1419

1520
lint:
16-
cd ./scripts && go run lint.go
21+
go run ./scripts lint --readme README.md --path ./presentations

README.md

+36-17
Large diffs are not rendered by default.

go.mod

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
module github.com/gnolang/workshops
22

3-
go 1.22.0
4-
5-
toolchain go1.22.3
3+
go 1.22
64

75
require (
86
github.com/campoy/embedmd v1.0.0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Date of the workshop
2+
date: "2023-03-13"
3+
# Title of the workshop
4+
title: "GopherCon Submission"
5+
# GitHub usernames of the speakers
6+
speakers:
7+
- "jaekwon"
8+
# Location of the workshop
9+
location: ""
10+
# At which event the workshop took place, if any
11+
event: ""
12+
# Workshop slides link. If the link is local, only put the file name, without any other path parts.
13+
slides: "README.md"
14+
# Workshop recording
15+
recording: ""

presentations/2024-09-23--distributed-communities-morgan/metadata.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ location: "Turin, Italy"
1010
# At which event the workshop took place, if any
1111
event: ""
1212
# Workshop slides link. If the link is local, only put the file name, without any other path parts.
13-
slides: "slides.reveal.pdf"
13+
slides: "https://gnolang.github.io/workshops/presentations/2024-09-23--distributed-communities/slides.html"
1414
# Workshop recording
1515
recording: ""

scripts/del-codeblock.sh

-11
This file was deleted.

scripts/del-existing-rows.sh

-13
This file was deleted.

scripts/format.go

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"os"
7+
"strings"
8+
9+
"github.com/gnolang/gno/tm2/pkg/commands"
10+
)
11+
12+
func newFormatCmd(cfg *cfg) *commands.Command {
13+
cmd := commands.NewCommand(
14+
commands.Metadata{
15+
Name: "format",
16+
ShortHelp: "remove codeblocks from the README table",
17+
},
18+
commands.NewEmptyConfig(),
19+
func(_ context.Context, args []string) error {
20+
return execFormat(cfg)
21+
},
22+
)
23+
return cmd
24+
}
25+
26+
// execFormat removes an existing table if rmTable is set, and removes the codeblock after table generation happened
27+
func execFormat(cfg *cfg) error {
28+
read, err := os.ReadFile(cfg.readmePath)
29+
if err != nil {
30+
panic(err)
31+
}
32+
33+
cts := string(read)
34+
newContents := ""
35+
36+
// Called to remove the old table
37+
if cfg.rmTable {
38+
lines := strings.Split(cts, "\n")
39+
newLines := make([]string, 0, len(lines))
40+
for _, line := range lines {
41+
if strings.Index(line, "|") != 0 {
42+
newLines = append(newLines, line)
43+
}
44+
}
45+
46+
newContents = strings.Join(newLines, "\n")
47+
48+
} else {
49+
// called to remove the codeblock
50+
newContents = strings.Replace(cts, "```md", "", 1)
51+
newContents = strings.Replace(newContents, "```", "", 1)
52+
}
53+
54+
if cts == newContents {
55+
fmt.Println("Nothing to format.")
56+
return nil
57+
}
58+
59+
err = os.WriteFile(cfg.readmePath, []byte(newContents), 0)
60+
if err != nil {
61+
panic(err)
62+
}
63+
64+
fmt.Println("Formatted README.md")
65+
return nil
66+
}

scripts/lint.go

+23-9
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
11
package main
22

33
import (
4+
"context"
45
"fmt"
56
"os"
67
"slices"
78
"strings"
8-
)
99

10-
const (
11-
presFolder = "../presentations"
12-
readme = "../README.md"
10+
"github.com/gnolang/gno/tm2/pkg/commands"
1311
)
1412

15-
func main() {
16-
dirs, err := os.ReadDir(presFolder)
13+
func newLintCmd(cfg *cfg) *commands.Command {
14+
cmd := commands.NewCommand(
15+
commands.Metadata{
16+
Name: "lint",
17+
ShortHelp: "lint the README table",
18+
},
19+
commands.NewEmptyConfig(),
20+
func(_ context.Context, args []string) error {
21+
return execLint(cfg)
22+
},
23+
)
24+
return cmd
25+
}
26+
27+
func execLint(cfg *cfg) error {
28+
dirs, err := os.ReadDir(cfg.presentationsPath)
1729
if err != nil {
1830
panic(err)
1931
}
@@ -31,18 +43,20 @@ func main() {
3143
slices.Sort(dates)
3244
slices.Reverse(dates)
3345

34-
rawContents, err := os.ReadFile(readme)
46+
rawContents, err := os.ReadFile(cfg.readmePath)
3547
if err != nil {
3648
panic(err)
3749
}
3850

3951
cts := string(rawContents)
4052

41-
for _, date := range dates[:15] {
53+
for _, date := range dates {
4254
if !strings.Contains(cts, date) {
43-
panic("could not find latest item in README table - did you run `make build`?")
55+
panic("could not find some items in README table - did you run `make build`?")
4456
}
4557
}
4658

4759
fmt.Println("All good!")
60+
61+
return nil
4862
}

scripts/generate-table.go scripts/table-tool.go

+27-12
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ import (
1616

1717
type cfg struct {
1818
presentationsPath string
19-
outputPath string
20-
rows int
19+
csvOutPath string
20+
readmePath string
21+
rmTable bool
2122
}
2223

2324
type Metadata struct {
@@ -32,6 +33,8 @@ var (
3233
csvHeader = []string{"Date", "Title", "Speakers", "Presentation", "Recording"}
3334
)
3435

36+
const ghLink = "https://github.com/"
37+
3538
func main() {
3639
cfg := &cfg{}
3740

@@ -45,6 +48,11 @@ func main() {
4548
return execGen(cfg)
4649
})
4750

51+
cmd.AddSubCommands(
52+
newLintCmd(cfg),
53+
newFormatCmd(cfg),
54+
)
55+
4856
cmd.Execute(context.Background(), os.Args[1:])
4957
}
5058

@@ -56,22 +64,29 @@ func (c *cfg) RegisterFlags(fs *flag.FlagSet) {
5664
"path to dir to walk for presentations files",
5765
)
5866
fs.StringVar(
59-
&c.outputPath,
67+
&c.csvOutPath,
6068
"out",
6169
"./data.csv",
6270
"output csv path, including .csv",
6371
)
64-
fs.IntVar(
65-
&c.rows,
66-
"rows",
67-
15,
68-
"number of rows to generate",
72+
fs.StringVar(
73+
&c.readmePath,
74+
"readme",
75+
"",
76+
"path to the main README",
77+
)
78+
79+
fs.BoolVar(
80+
&c.rmTable,
81+
"rmtable",
82+
false,
83+
"rm the table",
6984
)
7085
}
7186

7287
func execGen(cfg *cfg) error {
7388
searchDir := cfg.presentationsPath
74-
outputCSV := cfg.outputPath // todo check for err
89+
outputCSV := cfg.csvOutPath // todo check for err
7590

7691
// Create the CSV file
7792
csvFile, err := os.Create(outputCSV)
@@ -137,8 +152,7 @@ func execGen(cfg *cfg) error {
137152
})
138153

139154
// Write sorted rows to the CSV file
140-
// Generate only the last N rows of data
141-
for _, r := range rows[:cfg.rows] {
155+
for _, r := range rows {
142156
err = writer.Write(r.Format())
143157
if err != nil {
144158
return err
@@ -173,7 +187,8 @@ func (m Metadata) Format() []string {
173187
func (m Metadata) parseSpeakers() string {
174188
var speakers []string
175189
for _, speaker := range m.Speakers {
176-
speakers = append(speakers, "@"+speaker)
190+
speaker = fmt.Sprintf("[@%s](%s%s)", speaker, ghLink, speaker)
191+
speakers = append(speakers, speaker)
177192
}
178193

179194
return strings.Join(speakers, ", ")

0 commit comments

Comments
 (0)