diff --git a/.github/scripts/configure-mise-python-index.sh b/.github/scripts/configure-mise-python-index.sh new file mode 100644 index 00000000..21ea17db --- /dev/null +++ b/.github/scripts/configure-mise-python-index.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +set -euo pipefail + +: "${ARTIFACTORY_URL:?}" "${ARTIFACTORY_USERNAME:?}" "${ARTIFACTORY_ACCESS_TOKEN:?}" "${GITHUB_ENV:?}" + +configure_mise_python_index() { + local authenticated_index registry_url + + authenticated_index="${ARTIFACTORY_URL%/}/api/pypi/sonarsource-pypi/simple" + authenticated_index="https://${ARTIFACTORY_USERNAME}:${ARTIFACTORY_ACCESS_TOKEN}@${authenticated_index#https://}" + registry_url="${authenticated_index%/}/{}/" + + echo "::add-mask::${authenticated_index}" + echo "::add-mask::${registry_url}" + { + echo "PIP_INDEX_URL=${authenticated_index}" + echo "UV_DEFAULT_INDEX=${authenticated_index}" + echo "MISE_PIPX_REGISTRY_URL=${registry_url}" + } >> "$GITHUB_ENV" +} + +if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then + configure_mise_python_index +fi diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 5a423022..9914a561 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -11,7 +11,7 @@ jobs: - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 - uses: ./config-npm - uses: ./config-pip - - uses: SonarSource/gh-action_pre-commit@2ddc0c7fdabce0adfaaa4075a17690972ed9961a # 1.2.0 + - uses: SonarSource/gh-action_pre-commit@27ee4b1872173a0bafea002be3c264f97f5c2c5d with: extra-args: > --from-ref=origin/${{ github.event.pull_request.base.ref }} diff --git a/.github/workflows/test-build-number.yml b/.github/workflows/test-build-number.yml index 0670aa96..02d3ce20 100644 --- a/.github/workflows/test-build-number.yml +++ b/.github/workflows/test-build-number.yml @@ -128,6 +128,9 @@ jobs: contents: read steps: - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 + - uses: ./config-pip + - name: Configure mise Python package indexes + run: bash .github/scripts/configure-mise-python-index.sh - uses: ./config-npm - uses: jdx/mise-action@e6a8b3978addb5a52f2b4cd9d91eafa7f0ab959d # v4.2.0 with: diff --git a/.github/workflows/test-shell-scripts.yml b/.github/workflows/test-shell-scripts.yml index 6e0f5020..6397a68a 100644 --- a/.github/workflows/test-shell-scripts.yml +++ b/.github/workflows/test-shell-scripts.yml @@ -19,6 +19,9 @@ jobs: - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 with: fetch-depth: 0 + - uses: ./config-pip + - name: Configure mise Python package indexes + run: bash .github/scripts/configure-mise-python-index.sh - uses: ./config-npm - uses: jdx/mise-action@e6a8b3978addb5a52f2b4cd9d91eafa7f0ab959d # v4.2.0 with: diff --git a/.github/workflows/test-update-release-channel.yml b/.github/workflows/test-update-release-channel.yml index 8bd3266a..d02b2073 100644 --- a/.github/workflows/test-update-release-channel.yml +++ b/.github/workflows/test-update-release-channel.yml @@ -31,6 +31,9 @@ jobs: [[ "${{ steps.urc.outputs.version-key }}" == "Distribution/test-fixture/stable.version" ]] [[ "${{ steps.urc.outputs.version-url }}" == "https://binaries.sonarsource.com/Distribution/test-fixture/stable.version" ]] [[ "${{ steps.urc.outputs.version }}" == "0.0.0-test" ]] + - uses: ./config-pip + - name: Configure mise Python package indexes + run: bash .github/scripts/configure-mise-python-index.sh - uses: ./config-npm - uses: jdx/mise-action@e6a8b3978addb5a52f2b4cd9d91eafa7f0ab959d # v4.2.0 with: diff --git a/spec/configure-mise-python-index_spec.sh b/spec/configure-mise-python-index_spec.sh new file mode 100644 index 00000000..cf9fcc11 --- /dev/null +++ b/spec/configure-mise-python-index_spec.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash +eval "$(shellspec - -c) exit 1" + +export ARTIFACTORY_URL="https://repox.jfrog.io/artifactory" +export ARTIFACTORY_USERNAME="test-user" +export ARTIFACTORY_ACCESS_TOKEN="test-token" +export GITHUB_ENV=/dev/null + +Describe '.github/scripts/configure-mise-python-index.sh' + It 'does not configure the environment when sourced' + When run source .github/scripts/configure-mise-python-index.sh + The status should be success + The lines of output should equal 0 + End +End + +Include .github/scripts/configure-mise-python-index.sh + +Describe 'configure_mise_python_index()' + It 'configures mise, uv, and pip to use the authenticated Repox index' + GITHUB_ENV=$(mktemp) + export GITHUB_ENV + When call configure_mise_python_index + The status should be success + The lines of output should equal 2 + The contents of file "$GITHUB_ENV" should include \ + "PIP_INDEX_URL=https://test-user:test-token@repox.jfrog.io/artifactory/api/pypi/sonarsource-pypi/simple" + The contents of file "$GITHUB_ENV" should include \ + "UV_DEFAULT_INDEX=https://test-user:test-token@repox.jfrog.io/artifactory/api/pypi/sonarsource-pypi/simple" + The contents of file "$GITHUB_ENV" should include \ + "MISE_PIPX_REGISTRY_URL=https://test-user:test-token@repox.jfrog.io/artifactory/api/pypi/sonarsource-pypi/simple/{}/" + End +End