Repository navigation
BUILD-13211: Use production Edge for NuGet restores #3531
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
Closed
bwalsh434
wants to merge
1
commit into
master
from
feat/bwalsh/BUILD-13211-use-production-edge-for-nuget
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # NuGet reader configuration | ||
|
|
||
| Call this action immediately before a NuGet restore or another phase that can download NuGet packages. It delegates source configuration and fresh Vault authentication to [the shared config-nuget action](https://github.com/SonarSource/ci-github-actions/tree/b4eede988476ebb13a242fbc3ae4e8e374d78ad0/config-nuget), pinned to that revision, with an explicit `private-reader` role and selected Repox URL. | ||
|
|
||
| Internal Windows and Linux runners use `https://repox.sonar.build/artifactory/api/nuget/v3/nuget/index.json` with the production native reader at `development/artifactory-edge-prod/token/{REPO_OWNER_NAME_DASH}-private-reader`. GitHub-hosted and macOS runners use `https://repox.jfrog.io/artifactory/api/nuget/v3/nuget/index.json` with the SaaS reader at `development/artifactory/token/{REPO_OWNER_NAME_DASH}-private-reader`. | ||
|
|
||
| The `use-prod-edge` input defaults to empty. The first step then trims surrounding whitespace and normalizes the case of the inherited `NUGET_USE_PROD_EDGE` environment variable. Empty, `true`, and `false` are accepted; other values fail before requesting credentials. Production Edge is selected only for internal Windows or Linux runners when the normalized value is not `false`. Explicit `true` or `false` inputs override this default selection without reading the inherited variable; other input values fail before requesting credentials. | ||
|
|
||
| The wrapper preserves the existing generic Artifactory environment, calls the shared action, then restores the prior values and exports the fresh reader as `NuGetPackageSourceCredentials_Repox`. It uses the `Username=...;Password=...` syntax supported by both modern NuGet and the NuGet client shipped with Visual Studio 2017. NuGet uses this source-specific credential before the credentials in `NuGet.Config`, so Maven, publication, signing, and Orchestrator credentials retain their own scope. Credentials stay out of the configuration file; source mapping, signature requirements, and trusted signers are preserved. The committed configuration retains its SaaS default for local use. | ||
|
|
||
| The reader's configured default lifetime is one hour. A call refreshes the credential for subsequent steps; it does not refresh a running command. Keep calls close to network activity and refresh again before a later download phase. | ||
|
|
||
| To roll back CI downloads to SaaS, set the repository or organization Actions variable `NUGET_USE_PROD_EDGE` to `false`, or pass `use-prod-edge: 'false'` at a call site. The CI workflows pass the variable to the action through the matching environment variable. The wrapper resets the source to SaaS before calling the shared action on this path, so rollback switches both source and reader even after an Edge call in the same job. An explicit `use-prod-edge: 'true'` selects production Edge regardless of runner defaults. | ||
|
|
||
| NuGet's environment credential precedence and syntax are documented in [Consuming packages from authenticated feeds](https://learn.microsoft.com/en-us/nuget/consume-packages/consuming-packages-authenticated-feeds#credentials-in-environment-variables). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| name: Configure NuGet | ||
| description: Pair the Repox NuGet source with a fresh reader for the selected Artifactory instance. | ||
|
|
||
| inputs: | ||
| use-prod-edge: | ||
| description: Use production Edge on internal runners. Set false to use the SaaS source and reader. | ||
| default: '' | ||
|
|
||
| runs: | ||
| using: composite | ||
| steps: | ||
| - name: Select NuGet instance | ||
| id: instance | ||
| shell: bash | ||
| env: | ||
| USE_PROD_EDGE: ${{ inputs.use-prod-edge }} | ||
| RUNNER_ENVIRONMENT: ${{ runner.environment }} | ||
| run: | | ||
| set -euo pipefail | ||
| if [[ -z "$USE_PROD_EDGE" ]]; then | ||
| inherited_selection="$(printf '%s\n' "${NUGET_USE_PROD_EDGE:-}" | tr '[:upper:]' '[:lower:]' | sed -e ':all' -e '$!N' -e '$!b all' -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" | ||
| case "$inherited_selection" in | ||
| ''|true|false) ;; | ||
| *) echo '::error::NUGET_USE_PROD_EDGE must be empty, true or false'; exit 1 ;; | ||
| esac | ||
| USE_PROD_EDGE=false | ||
| if [[ ("$RUNNER_OS" == Windows || "$RUNNER_OS" == Linux) && "$RUNNER_ENVIRONMENT" != github-hosted && "$inherited_selection" != false ]]; then | ||
| USE_PROD_EDGE=true | ||
| fi | ||
| fi | ||
| case "$USE_PROD_EDGE" in | ||
| true|false) ;; | ||
| *) echo '::error::use-prod-edge must be true or false'; exit 1 ;; | ||
| esac | ||
|
gitar-bot[bot] marked this conversation as resolved.
Resolved
|
||
| printf 'use-prod-edge=%s\n' "$USE_PROD_EDGE" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Preserve Artifactory environment | ||
| id: environment | ||
| shell: bash | ||
| run: | | ||
| set -euo pipefail | ||
| for variable in ARTIFACTORY_URL ARTIFACTORY_USERNAME ARTIFACTORY_ACCESS_TOKEN ARTIFACTORY_USER ARTIFACTORY_PASSWORD ARTIFACTORY_READER_ROLE; do | ||
| printf '%s=%s\n' "$variable" "${!variable-}" >> "$GITHUB_OUTPUT" | ||
| done | ||
|
|
||
| - name: Reset NuGet source for SaaS rollback | ||
| if: steps.instance.outputs.use-prod-edge == 'false' | ||
| shell: bash | ||
| run: | | ||
| dotnet nuget update source Repox \ | ||
| --source https://repox.jfrog.io/artifactory/api/nuget/v3/nuget/index.json \ | ||
| --configfile NuGet.Config | ||
|
|
||
| - name: Configure NuGet source and reader | ||
| id: nuget | ||
| uses: SonarSource/ci-github-actions/config-nuget@b4eede988476ebb13a242fbc3ae4e8e374d78ad0 | ||
| with: | ||
| artifactory-reader-role: private-reader | ||
| repox-url: ${{ steps.instance.outputs.use-prod-edge == 'true' && 'https://repox.sonar.build' || 'https://repox.jfrog.io' }} | ||
|
|
||
| - name: Scope reader credentials to NuGet | ||
| if: always() && steps.environment.outcome == 'success' | ||
| shell: bash | ||
| env: | ||
| PREVIOUS_ARTIFACTORY_URL: ${{ steps.environment.outputs.ARTIFACTORY_URL }} | ||
| PREVIOUS_ARTIFACTORY_USERNAME: ${{ steps.environment.outputs.ARTIFACTORY_USERNAME }} | ||
| PREVIOUS_ARTIFACTORY_ACCESS_TOKEN: ${{ steps.environment.outputs.ARTIFACTORY_ACCESS_TOKEN }} | ||
| PREVIOUS_ARTIFACTORY_USER: ${{ steps.environment.outputs.ARTIFACTORY_USER }} | ||
| PREVIOUS_ARTIFACTORY_PASSWORD: ${{ steps.environment.outputs.ARTIFACTORY_PASSWORD }} | ||
| PREVIOUS_ARTIFACTORY_READER_ROLE: ${{ steps.environment.outputs.ARTIFACTORY_READER_ROLE }} | ||
| NUGET_CONFIGURATION_OUTCOME: ${{ steps.nuget.outcome }} | ||
| run: | | ||
| set -euo pipefail | ||
| for variable in ARTIFACTORY_URL ARTIFACTORY_USERNAME ARTIFACTORY_ACCESS_TOKEN ARTIFACTORY_USER ARTIFACTORY_PASSWORD ARTIFACTORY_READER_ROLE; do | ||
| previous_variable="PREVIOUS_$variable" | ||
| printf '%s=%s\n' "$variable" "${!previous_variable}" >> "$GITHUB_ENV" | ||
| done | ||
| if [[ "$NUGET_CONFIGURATION_OUTCOME" != success ]]; then | ||
| exit 0 | ||
| fi | ||
| : "${ARTIFACTORY_USERNAME:?NuGet reader username is required}" "${ARTIFACTORY_ACCESS_TOKEN:?NuGet reader token is required}" | ||
| # NuGet 4.9 treats authentication-type metadata after Password as part of the password. | ||
| credentials="Username=$ARTIFACTORY_USERNAME;Password=$ARTIFACTORY_ACCESS_TOKEN" | ||
| printf '::add-mask::%s\n' "$credentials" | ||
| printf 'NuGetPackageSourceCredentials_Repox=%s\n' "$credentials" >> "$GITHUB_ENV" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How much of this is reusable by the other 10 repos using NuGet? This looks like something that should live in one of the public tooling repos and be reused, instead of copied 10 times.