Przeglądaj źródła

ci: reject stale generated sources

Co-authored-by: Cursor <cursoragent@cursor.com>
jamesread 21 godzin temu
rodzic
commit
1458394bb5
5 zmienionych plików z 91 dodań i 1 usunięć
  1. 54 0
      .github/workflows/generated.yml
  2. 7 1
      Makefile
  3. 1 0
      lang/main.go
  4. 1 0
      proto/Makefile
  5. 28 0
      proto/normalize_generated.py

+ 54 - 0
.github/workflows/generated.yml

@@ -0,0 +1,54 @@
+name: Generated source checks
+
+on:
+  push:
+    branches:
+      - main
+      - next
+    paths:
+      - '.github/workflows/generated.yml'
+      - 'Makefile'
+      - 'frontend/resources/scripts/gen/**'
+      - 'lang/**'
+      - 'proto/**'
+      - 'service/gen/**'
+      - 'service/go.mod'
+      - 'service/go.sum'
+      - 'service/Makefile'
+      - 'service/tools.go'
+  pull_request:
+    branches:
+      - next
+    paths:
+      - '.github/workflows/generated.yml'
+      - 'Makefile'
+      - 'frontend/resources/scripts/gen/**'
+      - 'lang/**'
+      - 'proto/**'
+      - 'service/gen/**'
+      - 'service/go.mod'
+      - 'service/go.sum'
+      - 'service/Makefile'
+      - 'service/tools.go'
+
+permissions:
+  contents: read
+
+jobs:
+  generated:
+    runs-on: ubuntu-latest
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v4
+
+      - name: Setup Go
+        uses: actions/setup-go@v5
+        with:
+          go-version-file: 'service/go.mod'
+          cache: true
+          cache-dependency-path: |
+            service/go.sum
+            lang/go.sum
+
+      - name: Check generated sources
+        run: make generated-check

+ 7 - 1
Makefile

@@ -40,6 +40,12 @@ proto-tools:
 proto: proto-tools
 	$(MAKE) -wC proto
 
+lang-generate:
+	$(MAKE) -wC lang
+
+generated-check: proto lang-generate
+	git diff --exit-code -- service/gen frontend/resources/scripts/gen lang/combined_output.json
+
 dist:
 	echo "dist noop"
 
@@ -84,4 +90,4 @@ config-tool:
 devcheck:
 	python3 scripts/devcheck.py $(ARGS)
 
-.PHONY: proto proto-tools default service windows-resources windows-msi frontend-unittests it devcheck
+.PHONY: proto proto-tools lang-generate generated-check default service windows-resources windows-msi frontend-unittests it devcheck

+ 1 - 0
lang/main.go

@@ -34,6 +34,7 @@ func main() {
 		log.Fatalf("Error marshalling combined language content: %v", err)
 	}
 
+	jsonData = append(jsonData, '\n')
 	err = os.WriteFile("combined_output.json", jsonData, 0644)
 
 	if err != nil {

+ 1 - 0
proto/Makefile

@@ -1,4 +1,5 @@
 buf:
 	buf generate
+	python3 normalize_generated.py
 
 .PHONY: buf

+ 28 - 0
proto/normalize_generated.py

@@ -0,0 +1,28 @@
+#!/usr/bin/env python3
+
+from pathlib import Path
+
+ROOT = Path(__file__).resolve().parent.parent
+GENERATED_DIRS = (
+    ROOT / "service/gen",
+    ROOT / "frontend/resources/scripts/gen",
+)
+
+
+def normalize_file(path: Path) -> None:
+    content = path.read_bytes()
+    normalized = content.rstrip(b"\r\n") + b"\n"
+
+    if normalized != content:
+        path.write_bytes(normalized)
+
+
+def main() -> None:
+    for directory in GENERATED_DIRS:
+        for path in directory.rglob("*"):
+            if path.is_file():
+                normalize_file(path)
+
+
+if __name__ == "__main__":
+    main()