Skip to content

Commit 7d31881

Browse files
Merge pull request #98 from SumoLogic/addGithubAuthentication
Add GitHub authentication
2 parents f6e1234 + 7fb6c35 commit 7d31881

4 files changed

Lines changed: 35 additions & 8 deletions

File tree

.github/workflows/_reusable_build_package.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ on:
5353
required: false
5454
microsoft_description:
5555
required: false
56+
gh_ci_token:
57+
required: true
5658

5759
defaults:
5860
run:
@@ -81,6 +83,7 @@ jobs:
8183
if: runner.os == 'macOS'
8284
env:
8385
PRODUCTBUILD_IDENTITY_NAME: ${{ secrets.productbuild_identity_name }}
86+
GH_CI_TOKEN: ${{ secrets.GH_CI_TOKEN }}
8487
run: |
8588
if [ -n "${PRODUCTBUILD_IDENTITY_NAME}" ]; then
8689
echo "MACOS_SIGNING_ENABLED=true" >> $GITHUB_ENV

.github/workflows/build_packages.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ jobs:
147147
microsoft_certhash: ${{ secrets.MICROSOFT_CERTHASH }}
148148
microsoft_certname: ${{ secrets.MICROSOFT_CERTNAME }}
149149
microsoft_description: ${{ secrets.MICROSOFT_DESCRIPTION }}
150+
gh_ci_token: ${{ secrets.GH_CI_TOKEN }}
150151

151152
strategy:
152153
matrix:

.github/workflows/test-install-script.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ jobs:
3131
install-script/**/*
3232
.github/**
3333
34+
- name: Set up environment variables
35+
env:
36+
GITHUB_TOKEN: ${{ secrets.GH_CI_TOKEN }}
37+
3438
- name: Setup go
3539
if: steps.changed-files.outputs.any_changed == 'true'
3640
uses: WillAbides/setup-go-faster@v1
@@ -40,4 +44,4 @@ jobs:
4044
- name: Run install script tests
4145
if: steps.changed-files.outputs.any_changed == 'true'
4246
working-directory: install-script/test
43-
run: make test
47+
run: make test --token $GITHUB_TOKEN

install-script/test/consts_common.go

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package sumologic_scripts_tests
33
import (
44
"encoding/json"
55
"fmt"
6+
"log"
67
"net/http"
78
"net/url"
89
"os"
@@ -18,18 +19,36 @@ var (
1819
latestAppVersion string
1920
)
2021

22+
func authenticateGithub() string {
23+
githubToken := os.Getenv("GH_CI_TOKEN")
24+
if githubToken == "" {
25+
log.Fatal("GITHUB_TOKEN environment variable not set")
26+
27+
}
28+
return githubToken
29+
}
30+
2131
func getLatestAppReleaseVersion() (string, error) {
2232
githubApiBaseUrl, err := url.Parse(GithubApiBaseUrl)
2333
if err != nil {
2434
return "", err
2535
}
26-
githubApiLatestReleaseUrl := githubApiBaseUrl.JoinPath(
27-
"repos",
28-
GithubOrg,
29-
GithubAppRepository,
30-
"releases",
31-
"latest")
32-
response, err := http.Get(githubApiLatestReleaseUrl.String()) //nolint:noctx
36+
githubToken := authenticateGithub()
37+
38+
githubApiLatestReleaseUrl := fmt.Sprintf("%s/repos/%s/%s/releases/latest", githubApiBaseUrl, GithubOrg, GithubAppRepository)
39+
40+
req, err := http.NewRequest("GET", githubApiLatestReleaseUrl, nil)
41+
if err != nil {
42+
return "", err
43+
}
44+
45+
// Set Authorization header with GitHub token
46+
req.Header.Set("Authorization", "token "+githubToken)
47+
req.Header.Set("Accept", "application/vnd.github.v3+json")
48+
49+
// Send request
50+
client := http.Client{}
51+
response, err := client.Do(req)
3352
if err != nil {
3453
return "", err
3554
}

0 commit comments

Comments
 (0)