File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1818 with :
1919 go-version : stable
2020
21+ # Hermetic: regenerates from the committed spec, so this verifies that the committed
22+ # generated code still reproduces from it, with no network dependency. Refreshing the
23+ # spec itself is the release workflow's job.
2124 - name : Codegen drift check
25+ env :
26+ ROXYAPI_SPEC_FILE : specs/openapi.json
2227 run : |
2328 go run ./tools/roxygen generate
2429 git diff --exit-code -- specs/openapi.json roxyapi.gen.go roxy.gen.go \
Original file line number Diff line number Diff line change @@ -74,8 +74,7 @@ func check(err error, msg string) {
7474// ─── generate ────────────────────────────────────────────────────────────────
7575
7676func generate () {
77- fmt .Printf ("Fetching OpenAPI spec from %s\n " , specURL )
78- raw := fetchSpec ()
77+ raw := loadSpec ()
7978
8079 dec := json .NewDecoder (bytes .NewReader (raw ))
8180 dec .UseNumber ()
@@ -114,6 +113,20 @@ func generate() {
114113 syncDocs ()
115114}
116115
116+ // loadSpec returns the raw spec bytes, from disk when ROXYAPI_SPEC_FILE is set and from the API
117+ // otherwise. Reading from a file keeps generation offline and byte-reproducible, which is what the
118+ // codegen drift check in CI relies on.
119+ func loadSpec () []byte {
120+ if path := os .Getenv ("ROXYAPI_SPEC_FILE" ); path != "" {
121+ fmt .Printf ("Reading OpenAPI spec from %s (offline, ROXYAPI_SPEC_FILE)\n " , path )
122+ raw , err := os .ReadFile (path )
123+ check (err , "read spec file" )
124+ return raw
125+ }
126+ fmt .Printf ("Fetching OpenAPI spec from %s\n " , specURL )
127+ return fetchSpec ()
128+ }
129+
117130// fetchSpec retries with exponential backoff: a transient upstream error (e.g. a
118131// CDN 520) must not fail the daily release run.
119132func fetchSpec () []byte {
You can’t perform that action at this time.
0 commit comments