diff --git a/src/artifacts-helper/NOTES.md b/src/artifacts-helper/NOTES.md index b440541..5e83843 100644 --- a/src/artifacts-helper/NOTES.md +++ b/src/artifacts-helper/NOTES.md @@ -49,10 +49,21 @@ This ensures any custom scripting in place during Codespaces build process will The shim scripts (e.g., `dotnet`, `npm`, `nuget`) now include a wait mechanism for the Azure DevOps authentication helper. When invoked, these scripts will: 1. Wait up to 3 minutes for the `ado-auth-helper` to become available (configurable via `MAX_WAIT` environment variable) -2. Display progress indicators every 20 seconds while waiting +2. Display progress indicators every 20 seconds while waiting (only when `ARTIFACTS_HELPER_VERBOSE=true`) 3. Continue execution once authentication is successful 4. **Continue with the underlying command even if authentication is not available** after the timeout +By default, the authentication process runs silently. To enable verbose logging (useful for troubleshooting), set the `ARTIFACTS_HELPER_VERBOSE` environment variable to `true`: + +```bash +export ARTIFACTS_HELPER_VERBOSE=true +``` + +When verbose mode is enabled, you will see step-by-step messages like: +- `::step::Waiting for AzDO Authentication Helper...` +- `::step::Running ado-auth-helper get-access-token...` +- `::step::✓ Access token retrieved successfully` + This ensures that package restore operations can proceed even if there's a slight delay in the authentication helper installation, which can occur in some codespace initialization scenarios. Commands will still execute without authentication, though they may fail to access private Azure Artifacts feeds. The scripts are designed to be sourced safely, meaning they won't terminate the calling shell if authentication fails - they will simply return an error code and allow the underlying tool to execute. This allows you to work with public packages or other package sources even when Azure Artifacts authentication is unavailable. diff --git a/src/artifacts-helper/devcontainer-feature.json b/src/artifacts-helper/devcontainer-feature.json index db0e108..2d7566b 100644 --- a/src/artifacts-helper/devcontainer-feature.json +++ b/src/artifacts-helper/devcontainer-feature.json @@ -1,7 +1,7 @@ { "name": "Azure Artifacts Credential Helper", "id": "artifacts-helper", - "version": "3.0.1", + "version": "3.0.2", "description": "Configures Codespace to authenticate with Azure Artifact feeds", "options": { "nugetURIPrefixes": { diff --git a/src/artifacts-helper/scripts/auth-ado.sh b/src/artifacts-helper/scripts/auth-ado.sh index 9ffc878..8ad0c75 100644 --- a/src/artifacts-helper/scripts/auth-ado.sh +++ b/src/artifacts-helper/scripts/auth-ado.sh @@ -1,13 +1,27 @@ #!/bin/bash +# Helper function to conditionally log messages +# Messages are only shown if ARTIFACTS_HELPER_VERBOSE is set to "true" +log_step() { + if [ "${ARTIFACTS_HELPER_VERBOSE}" = "true" ]; then + echo "::step::$1" + fi +} + +log_message() { + if [ "${ARTIFACTS_HELPER_VERBOSE}" = "true" ]; then + echo "$1" + fi +} + # If ACTIONS_ID_TOKEN_REQUEST_URL is set, we're in a GitHub Actions environment # Skip Azure DevOps authentication and just execute the real command if [ -n "${ACTIONS_ID_TOKEN_REQUEST_URL}" ]; then - echo "::step::GitHub Actions environment detected, skipping Azure DevOps authentication" + log_step "GitHub Actions environment detected, skipping Azure DevOps authentication" return 0 fi -echo "::step::Waiting for AzDO Authentication Helper..." +log_step "Waiting for AzDO Authentication Helper..." # Wait up to 3 minutes for the ado-auth-helper to be installed # Can be overridden via environment variable for testing @@ -16,9 +30,10 @@ ELAPSED=0 while [ $ELAPSED -lt $MAX_WAIT ]; do if [ -f "${HOME}/ado-auth-helper" ]; then - echo "::step::Running ado-auth-helper get-access-token..." + log_step "Running ado-auth-helper get-access-token..." ARTIFACTS_ACCESSTOKEN=$(${HOME}/ado-auth-helper get-access-token) - echo "::step::✓ Access token retrieved successfully" + log_step "✓ Access token retrieved successfully" + # Return 0 to indicate successful authentication return 0 fi sleep 2 @@ -26,12 +41,14 @@ while [ $ELAPSED -lt $MAX_WAIT ]; do # Progress indicator every 20 seconds if [ $((ELAPSED % 20)) -eq 0 ]; then - echo " Still waiting... (${ELAPSED}s elapsed)" + log_message " Still waiting... (${ELAPSED}s elapsed)" fi done # Timeout reached - continue without authentication +# Always show timeout warnings regardless of verbose setting, as this indicates a potential issue echo "::warning::AzDO Authentication Helper not found after ${MAX_WAIT} seconds" echo "Expected location: ${HOME}/ado-auth-helper" echo "Continuing without Azure Artifacts authentication..." +# Return 1 to indicate authentication was not successful, but don't exit (allow sourcing script to continue) return 1 \ No newline at end of file