Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use GITHUB_SERVER_URL to change GitHub API host for dependency graph submission #1547

Merged
merged 4 commits into from
Dec 6, 2024

Conversation

luncliff
Copy link
Contributor

@luncliff luncliff commented Dec 3, 2024

Description

I was trying to use dependencygraph feature in my company, and found the following GitHub Action step was not updating the dependency of the repository.

# example GitHub Actions step
- name: "Run vcpkg(install)"
  run: vcpkg install --triplet "x64-windows"
  env:
    GITHUB_TOKEN: ${{ secrets.GHE_ACCESS_TOKEN }}
    VCPKG_FEATURE_FLAGS: "...,dependencygraph"

With --debug, I found the curl has failed with bad credential.

[DEBUG] 1032: CreateProcessW(curl -w "\nfcfad8a3-bb68-4a54-ad00-dab1ff671ed2%{http_code}" -X POST -H "Accept: application/vnd.github+json" -H "Authorization: ***" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/luncliff/experiment-repo/dependency-graph/snapshots -d @-)
[DEBUG] 1032: Unexpected WriteFileEx partial success: 7A
[DEBUG]   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
[DEBUG]                                  Dload  Upload   Total   Spent    Left  Speed
[DEBUG] 
[DEBUG]   0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
[DEBUG] 100 21560  100   109  100 21451    179  35337 --:--:-- --:--:-- --:--:-- 35933
[DEBUG] {
[DEBUG]   "message": "Bad credentials",
[DEBUG]   "documentation_url": "https://docs.github.com/rest",
[DEBUG]   "status": "401"
[DEBUG] }
[DEBUG] 
[DEBUG] 1032: cmd_execute_and_stream_data() returned 0 after   649546 us

Simply because the repository was in the GitHub Enterprise, not in the github.com.

Changes

  • Add another version of send_snapshot_to_api function and use it if args.github_server_url is detected

I suggest using GITHUB_SERVER_URL environment variable for changing the GitHub API host

# example GitHub Actions step
- name: "Run vcpkg(install)"
  run: vcpkg install --triplet "x64-windows"
  env:
    GITHUB_SERVER_URL: "https://git.example.com" # API to "https://git.example.com/api/v3/..."
    GITHUB_TOKEN: ${{ secrets.GHE_ACCESS_TOKEN }}
    VCPKG_FEATURE_FLAGS: "...,dependencygraph"

After change, the debug message would be like this in the GitHub Enterprise server (3.12)

[DEBUG] 1011: CreateProcessW(curl -w "\nfcfad8a3-bb68-4a54-ad00-dab1ff671ed2%{http_code}" -X POST -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ghp_..." -H "X-GitHub-Api-Version: 2022-11-28" https://git.example.com/api/v3/repos/luncliff/experiment-repo/dependency-graph/snapshots -d @-)
[DEBUG]   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
[DEBUG]                                  Dload  Upload   Total   Spent    Left  Speed
[DEBUG] 
[DEBUG]   0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
[DEBUG]   0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
[DEBUG] 100   860    0     0  100   860      0    738  0:00:01  0:00:01 --:--:--   742
[DEBUG] 100  1024  100   164  100   860     77    405  0:00:02  0:00:02 --:--:--   484
[DEBUG] {
[DEBUG]   "id": 5238,
[DEBUG]   "created_at": "2024-12-03T09:28:55.815Z",
[DEBUG]   "result": "SUCCESS",
[DEBUG]   "message": "Dependency results for the repo have been successfully updated."
[DEBUG] }
[DEBUG] 
[DEBUG] 1011: cmd_execute_and_stream_data() returned 0 after  2153075 us

References

Copy link
Member

@BillyONeal BillyONeal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed some changes, can you confirm you're OK with them? Otherwise just chop off the commit adding them and point out my mistakes 😅

@luncliff
Copy link
Contributor Author

luncliff commented Dec 6, 2024

Looks good to me. 👍

@BillyONeal BillyONeal merged commit e5ed2e7 into microsoft:main Dec 6, 2024
6 checks passed
@BillyONeal
Copy link
Member

Thanks!

@luncliff luncliff deleted the support/github-enterprise branch December 6, 2024 23:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants