Skip to content

Commit

Permalink
Allow authenticating to GitHub with a Personal Access Token for ease …
Browse files Browse the repository at this point in the history
…of use while testing
  • Loading branch information
finn-block committed Jan 9, 2024
1 parent 001fea0 commit 8ccac38
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
14 changes: 11 additions & 3 deletions reports/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@

This tool reads junit XML reports from different SDKs and generates an HTML report showing which SDKs support which features.

## Current Status

`./cmd/build-html` will iterate over the repos listed in `sdk.go` and download the most recent junit artifact. It will read
all junit results from it and produce a report to `_site/index.html`
all junit results from it and produce a report to `_site/index.html`. For local testing, generate a
[GitHub Personal Access Token](https://github.com/settings/tokens?type=beta) and put it in an environment variable named
`GITHUB_TOKEN`. It doesn't need any special permissions ("Public Repositories (read-only)"). Note that a GitHub app (explained below) can also be used.

`./cmd/sync-vectors` will check the `main` branch of all SDKs listed in `sdks.go` and ensure their vectors match the ones in this repo.
For local testing, a [GitHub App](https://github.com/settings/apps) must be created. Put it's credentials in the following environment variables:

* `CICD_ROBOT_GITHUB_APP_ID` - shown on the edit page of the app, where you are sent right after app creation.
* `CICD_ROBOT_GITHUB_APP_PRIVATE_KEY` - this should be the contents of the private key, not the path to the file.
* `CICD_ROBOT_GITHUB_APP_NAME` - this is used as a display name and should match the name in the URL of the edit page for the app.
* `CICD_ROBOT_GITHUB_APP_INSTALLATION_ID` - click "Install App" on the sidebar while editing the app in GitHub to install it on your own account.
8 changes: 8 additions & 0 deletions reports/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,21 @@ var (
ghAppIDString = os.Getenv("CICD_ROBOT_GITHUB_APP_ID")
ghAppInstallationIDString = os.Getenv("CICD_ROBOT_GITHUB_APP_INSTALLATION_ID")

ghToken = os.Getenv("GITHUB_TOKEN")

gh *github.Client
ghTransport *ghinstallation.Transport

ghUserName = fmt.Sprintf("%s[bot]", ghAppName)
)

func init() {
if ghToken != "" {
slog.Info("using GITHUB_TOKEN for auth")
gh = github.NewTokenClient(context.Background(), ghToken)
return
}

ghAppID, err := strconv.ParseInt(ghAppIDString, 10, 32)
if err != nil {
slog.Error("invalid or unset app ID. Please set environment variable CICD_ROBOT_GITHUB_APP_ID to a valid integer")
Expand Down
9 changes: 6 additions & 3 deletions reports/sdks.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,12 @@ func downloadArtifact(ctx context.Context, sdk SDKMeta) ([]byte, error) {
if err != nil {
return nil, err
}
bearer, err := ghTransport.Token(ctx)
if err != nil {
return nil, fmt.Errorf("error getting github token: %v", err)
bearer := ghToken
if ghToken == "" {
bearer, err = ghTransport.Token(ctx)
if err != nil {
return nil, fmt.Errorf("error getting github token: %v", err)
}
}
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", bearer))
resp, err := http.DefaultClient.Do(req)
Expand Down
3 changes: 3 additions & 0 deletions reports/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ func ConfigureGitAuth() error {
}
gitCredentialStoreFile = f.Name()

if ghTransport == nil {
panic("syncing vecotrs with a PAT not supported. See README for instructions to create a GitHub app.")
}
authToken, err := ghTransport.Token(context.Background())
if err != nil {
slog.Error("error getting github auth token")
Expand Down

0 comments on commit 8ccac38

Please sign in to comment.