Skip to content

Commit

Permalink
Allow the caller to specify a GHES version to build for
Browse files Browse the repository at this point in the history
  • Loading branch information
thorrsson committed Apr 3, 2024
1 parent 8c39fda commit 4bdfbc8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
7 changes: 5 additions & 2 deletions schemas/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"flag"
"fmt"
"io"
"log"
"net/http"
Expand All @@ -10,12 +11,14 @@ import (

var useSchemaNext bool
var ghes bool
var ghesVersion string

// Normally I hate using init() but the docs [here](https://pkg.go.dev/flag)
// recommend it so this usage is safe.
func init() {
flag.BoolVar(&useSchemaNext, "schema-next", false, "Set to true using --schema-next=true to use the descriptions-next directory for schema downloads")
flag.BoolVar(&ghes, "ghes", false, "Set to true using --ghes=true to pull down the descriptions in ghes-3.13")
flag.StringVar(&ghesVersion, "ghes-version", "3.12", "The version of GHES to generate for. (default 3.12)")
}

func main() {
Expand All @@ -40,8 +43,8 @@ func realMain() error {
logMsg = "Downloading latest schema from descriptions-next directory"
url = "https://raw.githubusercontent.com/github/rest-api-description/main/descriptions-next/api.github.com/api.github.com.json"
} else if ghes {
logMsg = "Downloading the GHES 3.12 schema"
url = "https://raw.githubusercontent.com/github/rest-api-description/main/descriptions/ghes-3.12/ghes-3.12.json"
logMsg = fmt.Sprintf("Downloading the GHES %v schema", ghesVersion)
url = fmt.Sprintf("https://raw.githubusercontent.com/github/rest-api-description/main/descriptions/ghes-%v/ghes-%v.json", ghesVersion, ghesVersion)
}

log.Printf(logMsg)
Expand Down
14 changes: 11 additions & 3 deletions scripts/generate-go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,21 @@
set -ex

if [ -z "$1" ]; then
gen_path="../go-sdk"
go run schemas/main.go --schema-next=false
elif [ "$1" = "ghes" ]; then
go run schemas/main.go --schema-next=false --ghes=true
if [ -z "$2" ]; then
echo "generating for GHES requires that you specify a version as the second argument. ex $0 ghes 3.12"
exit 1
else
ghes_version=$2
gen_path="../go-sdk-ghes"
go run schemas/main.go --schema-next=false --ghes=true --ghes-version=3.12
fi
fi

kiota generate -l go --ll trace -o $(pwd)/../go-sdk/pkg/github -n github.com/octokit/go-sdk/pkg/github -d schemas/downloaded.json --ebc
kiota generate -l go --ll trace -o $(pwd)/${gen_path}/pkg/github -n github.com/octokit/go-sdk/pkg/github -d schemas/downloaded.json --ebc
go build -o post-processors/go/post-processor post-processors/go/main.go
cd $(pwd)/../go-sdk
cd $(pwd)/${gen_path}
$(pwd)/../source-generator/post-processors/go/post-processor $(pwd)
go build ./...

0 comments on commit 4bdfbc8

Please sign in to comment.