Repository navigation
BUILD-13251: Add config-bun action #369
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
Merged
Merged
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| --- | ||
| name: Config Bun | ||
| description: GitHub Action to configure Bun dependency resolution with Artifactory authentication and caching | ||
| inputs: | ||
| working-directory: | ||
| description: Relative path under github.workspace containing bun.lock | ||
| default: . | ||
| artifactory-reader-role: | ||
| description: Suffix for the Artifactory reader role in Vault. Defaults to `private-reader` for private repositories, and `public-reader` | ||
| for public repositories. | ||
| default: '' | ||
| repox-url: | ||
| description: URL for Repox used to resolve dependencies. Defaults to SaaS on GitHub-hosted runners and the production Edge | ||
| on self-hosted runners. Explicit URLs override runner selection. | ||
| default: ${{ runner.environment == 'github-hosted' && 'https://repox.jfrog.io' || 'https://repox-internal.sonar.build' }} | ||
| disable-caching: | ||
| description: Whether to disable Bun install caching entirely | ||
| default: 'false' | ||
| host-actions-root: | ||
| description: Path to the actions folder on the host (used when called from another local action) | ||
| default: '' | ||
|
|
||
| outputs: | ||
| registry: | ||
| description: The npm registry URL selected for Bun. Also set as environment variable BUN_CONFIG_REGISTRY. | ||
| value: ${{ steps.config.outputs.registry }} | ||
|
|
||
| runs: | ||
| using: composite | ||
| steps: | ||
| - id: config-bun-completed | ||
| if: env.CONFIG_BUN_COMPLETED != '' | ||
| shell: bash | ||
| run: | | ||
| echo "Action already called by $CONFIG_BUN_COMPLETED, execution skipped." | ||
| echo "skip=true" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Set local action paths | ||
| if: steps.config-bun-completed.outputs.skip != 'true' | ||
| shell: bash | ||
| env: | ||
| ARTIFACTORY_READER_ROLE: ${{ inputs.artifactory-reader-role != '' && inputs.artifactory-reader-role || | ||
| (github.event.repository.visibility == 'public' && 'public-reader' || 'private-reader') }} | ||
| run: | | ||
| ACTION_PATH_CONFIG_BUN="${{ github.action_path }}" | ||
| host_actions_root="${{ inputs.host-actions-root }}" | ||
| if [[ -n "$host_actions_root" ]]; then | ||
| ACTION_PATH_CONFIG_BUN="$host_actions_root/config-bun" | ||
| fi | ||
| echo "ACTION_PATH_CONFIG_BUN=$ACTION_PATH_CONFIG_BUN" >> "$GITHUB_ENV" | ||
| echo "ARTIFACTORY_READER_ROLE=${ARTIFACTORY_READER_ROLE}" >> "$GITHUB_ENV" | ||
|
|
||
| - uses: SonarSource/vault-action-wrapper@a7fa5fd4a4e4e0f2593f6137c0812cac196cf4ce # 3.7.0 | ||
| if: steps.config-bun-completed.outputs.skip != 'true' | ||
| id: secrets | ||
| with: | ||
| # yamllint disable rule:line-length | ||
| url: ${{ contains(inputs.repox-url, '.dev.sonar.build') && 'https://vault.dev.sonar.build' || 'https://vault.sonar.build' }} | ||
| secrets: | | ||
| development/${{ contains(inputs.repox-url, 'jfrog.io') && 'artifactory' || (contains(inputs.repox-url, '.dev.sonar.build') && 'artifactory-edge-dev' || 'artifactory-edge-prod') }}/token/{REPO_OWNER_NAME_DASH}-${{ env.ARTIFACTORY_READER_ROLE }} username | ARTIFACTORY_USERNAME; | ||
| development/${{ contains(inputs.repox-url, 'jfrog.io') && 'artifactory' || (contains(inputs.repox-url, '.dev.sonar.build') && 'artifactory-edge-dev' || 'artifactory-edge-prod') }}/token/{REPO_OWNER_NAME_DASH}-${{ env.ARTIFACTORY_READER_ROLE }} access_token | ARTIFACTORY_ACCESS_TOKEN; | ||
| # yamllint enable rule:line-length | ||
|
|
||
| - name: Configure Bun registry | ||
| id: config | ||
| if: steps.config-bun-completed.outputs.skip != 'true' | ||
| shell: bash | ||
| working-directory: ${{ inputs.working-directory }} | ||
| env: | ||
| ARTIFACTORY_URL: ${{ format('{0}/artifactory', inputs.repox-url) }} | ||
| ARTIFACTORY_USERNAME: ${{ steps.secrets.outputs.vault && fromJSON(steps.secrets.outputs.vault).ARTIFACTORY_USERNAME || '' }} | ||
| ARTIFACTORY_ACCESS_TOKEN: ${{ steps.secrets.outputs.vault && fromJSON(steps.secrets.outputs.vault).ARTIFACTORY_ACCESS_TOKEN || '' }} | ||
| run: $ACTION_PATH_CONFIG_BUN/bun_config.sh | ||
|
|
||
| - name: Cache Bun dependencies | ||
| uses: SonarSource/gh-action_cache@0b86c7a0e6c3cb8238c826be7dd9fdfd02f16f8b # v1.7.3 | ||
| if: steps.config-bun-completed.outputs.skip != 'true' && inputs.disable-caching != 'true' | ||
| with: | ||
| path: ~/.bun/install/cache | ||
|
hedinasr marked this conversation as resolved.
|
||
| key: bun-${{ runner.os }}-${{ hashFiles(format('{0}/bun.lock', inputs.working-directory)) }} | ||
| restore-keys: bun-${{ runner.os }}- | ||
|
|
||
| - name: Set Config Bun completed | ||
| if: steps.config-bun-completed.outputs.skip != 'true' | ||
| shell: bash | ||
| run: echo "CONFIG_BUN_COMPLETED=$GITHUB_ACTION" >> "$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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| #!/bin/bash | ||
| # Config script for Bun to resolve npm packages from SonarSource Artifactory. | ||
| # | ||
| # Required environment variables (must be explicitly provided): | ||
| # - ARTIFACTORY_URL: URL to Artifactory repository | ||
| # - ARTIFACTORY_USERNAME: Username for Artifactory authentication | ||
| # - ARTIFACTORY_ACCESS_TOKEN: Access token to read Repox repositories | ||
| # | ||
| # GitHub Actions auto-provided: | ||
| # - GITHUB_ENV: Path to GitHub Actions environment file | ||
| # - GITHUB_OUTPUT: Path to GitHub Actions output file | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| : "${ARTIFACTORY_URL:?}" "${ARTIFACTORY_USERNAME:?}" "${ARTIFACTORY_ACCESS_TOKEN:?}" "${GITHUB_ENV:?}" "${GITHUB_OUTPUT:?}" | ||
|
|
||
| configure_bun_registry() { | ||
| local registry="${ARTIFACTORY_URL}/api/npm/npm/" | ||
|
|
||
| { | ||
| echo "BUN_CONFIG_REGISTRY=$registry" | ||
| echo "BUN_CONFIG_TOKEN=$ARTIFACTORY_ACCESS_TOKEN" | ||
| echo "ARTIFACTORY_USERNAME=$ARTIFACTORY_USERNAME" | ||
| echo "ARTIFACTORY_ACCESS_TOKEN=$ARTIFACTORY_ACCESS_TOKEN" | ||
| } >> "$GITHUB_ENV" | ||
| echo "registry=$registry" >> "$GITHUB_OUTPUT" | ||
| echo "Dependency registry: $registry" | ||
| return 0 | ||
|
gitar-bot[bot] marked this conversation as resolved.
|
||
| } | ||
|
|
||
| main() { | ||
| echo "::group::Configure Bun" | ||
| configure_bun_registry | ||
| echo "::endgroup::" | ||
| return 0 | ||
| } | ||
|
|
||
| if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then | ||
| main | ||
| fi | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| #!/usr/bin/env bash | ||
| eval "$(shellspec - -c) exit 1" | ||
|
|
||
| export GITHUB_ENV=/dev/null | ||
| export GITHUB_OUTPUT=/dev/null | ||
| export ARTIFACTORY_URL="https://repox-internal.sonar.build/artifactory" | ||
| export ARTIFACTORY_USERNAME="test-user" | ||
| export ARTIFACTORY_ACCESS_TOKEN="test-token" | ||
|
|
||
| EDGE_REGISTRY="https://repox-internal.sonar.build/artifactory/api/npm/npm/" | ||
|
|
||
| Describe 'config-bun/bun_config.sh' | ||
| It 'does not run main when sourced' | ||
| When run source config-bun/bun_config.sh | ||
| The status should be success | ||
| The lines of output should equal 0 | ||
| The lines of error should equal 0 | ||
| End | ||
| End | ||
|
|
||
| Include config-bun/bun_config.sh | ||
|
|
||
| Describe 'configure_bun_registry()' | ||
| It 'exports the selected registry and its reader token' | ||
| GITHUB_ENV=$(mktemp) | ||
| GITHUB_OUTPUT=$(mktemp) | ||
| export GITHUB_ENV GITHUB_OUTPUT | ||
| When call configure_bun_registry | ||
| The status should be success | ||
| The output should equal "Dependency registry: $EDGE_REGISTRY" | ||
| The contents of file "$GITHUB_ENV" should include "BUN_CONFIG_REGISTRY=$EDGE_REGISTRY" | ||
| The contents of file "$GITHUB_ENV" should include "BUN_CONFIG_TOKEN=test-token" | ||
| The contents of file "$GITHUB_ENV" should not include "NPM_CONFIG_REGISTRY" | ||
| The contents of file "$GITHUB_ENV" should include "ARTIFACTORY_USERNAME=test-user" | ||
| The contents of file "$GITHUB_ENV" should include "ARTIFACTORY_ACCESS_TOKEN=test-token" | ||
| The contents of file "$GITHUB_OUTPUT" should equal "registry=$EDGE_REGISTRY" | ||
| End | ||
| End | ||
|
|
||
| Describe 'main()' | ||
| It 'configures the registry within a GitHub Actions group' | ||
| GITHUB_ENV=$(mktemp) | ||
| GITHUB_OUTPUT=$(mktemp) | ||
| export GITHUB_ENV GITHUB_OUTPUT | ||
| When run script config-bun/bun_config.sh | ||
| The status should be success | ||
| The line 1 should equal "::group::Configure Bun" | ||
| The line 2 should equal "Dependency registry: $EDGE_REGISTRY" | ||
| The line 3 should equal "::endgroup::" | ||
| End | ||
|
|
||
| It 'fails without a reader token' | ||
| export ARTIFACTORY_ACCESS_TOKEN="" | ||
| When run script config-bun/bun_config.sh | ||
| The status should be failure | ||
| The error should include "ARTIFACTORY_ACCESS_TOKEN" | ||
| End | ||
| End |
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.
Uh oh!
There was an error while loading. Please reload this page.