Skip to content

Commit 3649d7f

Browse files
committed
Test split poetry install action
1 parent 74d0075 commit 3649d7f

File tree

3 files changed

+93
-17
lines changed

3 files changed

+93
-17
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
name: Configure Poetry
3+
description: GitHub Action to configure a poetry project
4+
5+
outputs:
6+
project-version:
7+
description: The project version from pyproject.toml with BUILD_NUMBER
8+
value: ${{ steps.build.outputs.project-version }}
9+
BUILD_NUMBER:
10+
description: The build number, incremented or reused if already cached
11+
value: ${{ steps.get_build_number.outputs.BUILD_NUMBER }}
12+
13+
runs:
14+
using: composite
15+
steps:
16+
- name: Set build parameters
17+
shell: bash
18+
env:
19+
ARTIFACTORY_READER_ROLE: ${{ inputs.artifactory-reader-role != '' && inputs.artifactory-reader-role ||
20+
(github.event.repository.visibility == 'public' && 'public-reader' || 'private-reader') }}
21+
run: |
22+
echo "ARTIFACTORY_READER_ROLE=${ARTIFACTORY_READER_ROLE}" >> "$GITHUB_ENV"
23+
cp ${GITHUB_ACTION_PATH}/mise.local.toml mise.local.toml
24+
- uses: SonarSource/ci-github-actions/get-build-number@v1
25+
id: get_build_number
26+
- name: Cache local Poetry cache
27+
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
28+
with:
29+
path: ${{ github.workspace }}/.cache/pypoetry
30+
key: poetry-${{ runner.os }}-${{ hashFiles('poetry.lock') }}
31+
restore-keys: poetry-${{ runner.os }}-
32+
- uses: jdx/mise-action@5ac50f778e26fac95da98d50503682459e86d566 # v3.2.0
33+
shell: bash
34+
with:
35+
version: 2025.7.12
36+
install_args: "poetry@2.2.1"
37+
run: mise use -g poetry@2.2.1
38+
- name: Vault
39+
# yamllint disable rule:line-length
40+
id: secrets
41+
uses: SonarSource/vault-action-wrapper@320bd31b03e5dacaac6be51bbbb15adf7caccc32 # 3.1.0
42+
with:
43+
secrets: |
44+
development/artifactory/token/{REPO_OWNER_NAME_DASH}-${{ env.ARTIFACTORY_READER_ROLE }} access_token | ARTIFACTORY_ACCESS_TOKEN;
45+
# yamllint enable rule:line-length
46+
- name: Config Poetry
47+
id: build
48+
shell: bash
49+
env:
50+
ARTIFACTORY_URL: https://repox.jfrog.io
51+
ARTIFACTORY_PYPI_REPO: sonarsource-pypi
52+
ARTIFACTORY_ACCESS_TOKEN: ${{ fromJSON(steps.secrets.outputs.vault).ARTIFACTORY_ACCESS_TOKEN }}
53+
run: |
54+
cd "${{ inputs.working-directory }}"
55+
${GITHUB_ACTION_PATH}/config-poetry.sh
56+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
# Config script for SonarSource Poetry projects.
3+
4+
set -euo pipefail
5+
6+
: "${ARTIFACTORY_URL:?}"
7+
: "${ARTIFACTORY_PYPI_REPO:?}" "${ARTIFACTORY_ACCESS_TOKEN:?}"
8+
: "${BUILD_NUMBER:?}" "${GITHUB_REPOSITORY:?}"
9+
10+
set_build_env() {
11+
export PROJECT=${GITHUB_REPOSITORY#*/}
12+
echo "PROJECT: $PROJECT"
13+
}
14+
15+
jfrog_poetry_install() {
16+
jf config add repox --artifactory-url "$ARTIFACTORY_URL" --access-token "$ARTIFACTORY_ACCESS_TOKEN"
17+
jf poetry-config --server-id-resolve repox --repo-resolve "$ARTIFACTORY_PYPI_REPO"
18+
jf poetry install --build-name="$PROJECT" --build-number="$BUILD_NUMBER"
19+
}
20+
21+
main() {
22+
set_build_env
23+
config-poetry
24+
}
25+
26+
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
27+
main "$@"
28+
fi

.github/workflows/build.yml

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,7 @@ jobs:
3838
contents: write
3939
steps:
4040
- uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0
41-
- uses: jdx/mise-action@e3d7b8d67a7958d1207f6ed871e83b1ea780e7b0 #v3.3.1
42-
with:
43-
install_args: "poetry@2.2.1"
44-
- run: mise use -g poetry@2.2.1
45-
- uses: SonarSource/ci-github-actions/build-poetry@v1
46-
with:
47-
sonar-platform: none
48-
artifactory-reader-role: private-reader
49-
artifactory-deployer-role: qa-deployer
50-
- run: poetry install
41+
- uses: ./.github/actions/config-poetry
5142
- run: |
5243
poetry run black src/ tests/ --check
5344
poetry run licenseheaders -t license_header.tmpl -o "SonarSource SA" -y 2011-2024 -n "Sonar Scanner Python" -E .py -d src/
@@ -66,7 +57,6 @@ jobs:
6657
with:
6758
install_args: "poetry@2.2.1"
6859
- run: mise use -g poetry@2.2.1
69-
- run: poetry install
7060
- run: |
7161
poetry run python tools/generate_cli_documentation.py
7262
git diff --exit-code CLI_ARGS.md
@@ -86,13 +76,18 @@ jobs:
8676
mise use -g poetry@2.2.1
8777
- uses: SonarSource/ci-github-actions/build-poetry@v1
8878
with:
89-
sonar-platform: next
79+
sonar-platform: none
9080
artifactory-reader-role: private-reader
9181
artifactory-deployer-role: qa-deployer
9282
- run: poetry install
9383
- run: |
9484
poetry run pytest --cov-report=xml:coverage.xml --cov-config=pyproject.toml --cov=src --cov-branch tests
9585
poetry run mypy src/ > mypy-report.txt || true
86+
- uses: SonarSource/ci-github-actions/build-poetry@v1
87+
with:
88+
sonar-platform: next
89+
artifactory-reader-role: private-reader
90+
artifactory-deployer-role: qa-deployer
9691

9792
qa:
9893
name: "Test Python ${{ matrix.python-version }}"
@@ -148,7 +143,7 @@ jobs:
148143
steps:
149144
- uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0
150145
- name: Cache SonarQube
151-
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
146+
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
152147
with:
153148
path: sonarqube_cache/
154149
key: sonarqube-25.3.0.104237
@@ -160,10 +155,7 @@ jobs:
160155
fi
161156
env:
162157
SONARQUBE_VERSION: 25.3.0.104237
163-
- uses: SonarSource/ci-github-actions/build-poetry@v1
164-
with:
165-
sonar-platform: none
166-
script: .github/scripts/run_its.sh
158+
- run: .github/scripts/run_its.sh
167159

168160
promote:
169161
name: "Promote"

0 commit comments

Comments
 (0)