Skip to content

Commit 8667ea8

Browse files
feat(BUILD-4592): Sonar build & release workflow (#41)
1 parent 84d875d commit 8667ea8

File tree

7 files changed

+253
-332
lines changed

7 files changed

+253
-332
lines changed

.cirrus.yml

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,48 @@
11
env:
22
ARTIFACTORY_URL: VAULT[development/kv/data/repox data.url]
3-
ARTIFACTORY_PRIVATE_USERNAME: vault-${CIRRUS_REPO_OWNER}-${CIRRUS_REPO_NAME}-private-reader
4-
ARTIFACTORY_PRIVATE_PASSWORD: VAULT[development/artifactory/token/${CIRRUS_REPO_OWNER}-${CIRRUS_REPO_NAME}-private-reader access_token]
5-
ARTIFACTORY_DEPLOY_USERNAME: vault-${CIRRUS_REPO_OWNER}-${CIRRUS_REPO_NAME}-qa-deployer
6-
ARTIFACTORY_DEPLOY_PASSWORD: VAULT[development/artifactory/token/${CIRRUS_REPO_OWNER}-${CIRRUS_REPO_NAME}-qa-deployer access_token]
7-
#Possible values for ARTIFACTORY_DEPLOY_REPO: sonarsource-private-qa, sonarsource-public-qa
8-
ARTIFACTORY_DEPLOY_REPO: sonarsource-public-qa
9-
REPOX_URL: VAULT[development/kv/data/repox data.url]
3+
ARTIFACTORY_PRIVATE_ACCESS_TOKEN: VAULT[development/artifactory/token/${CIRRUS_REPO_OWNER}-${CIRRUS_REPO_NAME}-private-reader access_token]
4+
ARTIFACTORY_DEPLOY_USERNAME: VAULT[development/artifactory/token/${CIRRUS_REPO_OWNER}-${CIRRUS_REPO_NAME}-qa-deployer username]
5+
ARTIFACTORY_DEPLOY_ACCESS_TOKEN: VAULT[development/artifactory/token/${CIRRUS_REPO_OWNER}-${CIRRUS_REPO_NAME}-qa-deployer access_token]
6+
ARTIFACTORY_DEPLOY_REPO: sonarsource-pypi-public-qa
107
GITHUB_TOKEN: VAULT[development/github/token/licenses-ro token]
118
SONAR_TOKEN: VAULT[development/kv/data/sonarcloud data.token]
129
SONAR_HOST_URL: https://sonarcloud.io
10+
DEPLOY_PULL_REQUEST: 'true'
11+
POETRY_VIRTUALENVS_PATH: ".cache/poetry/venvs"
12+
POETRY_CACHE_DIR: ".cache/poetry/pypoetry"
1313

14-
only_sonarsource_qa: &ONLY_SONARSOURCE_QA
15-
only_if: $CIRRUS_USER_COLLABORATOR == 'true' && $CIRRUS_TAG == "" && ($CIRRUS_PR != "" || $CIRRUS_BRANCH == "master" || $CIRRUS_BRANCH =~ "feature/*" || $CIRRUS_BRANCH =~ "dogfood-on-.*")
14+
only_if: $CIRRUS_USER_COLLABORATOR == "true" && $CIRRUS_TAG == "" && ($CIRRUS_PR != "" || $CIRRUS_BRANCH == $CIRRUS_DEFAULT_BRANCH || $CIRRUS_BRANCH =~ "feature/*" || $CIRRUS_BRANCH =~ "dogfood-on-.*")
1615

1716
container_definition: &CONTAINER_DEFINITION
1817
dockerfile: .cirrus/poetry.Dockerfile
1918
cluster_name: ${CIRRUS_CLUSTER_NAME}
2019
region: eu-central-1
21-
builder_image_name: POETRY_VM
20+
namespace: default
21+
builder_subnet_ids: ${CIRRUS_AWS_SUBNETS}
2222
builder_role: cirrus-builder
2323
builder_image: docker-builder-v*
2424
builder_instance_type: t3.small
25-
builder_subnet_id: ${CIRRUS_AWS_SUBNET}
26-
zone: eu-central-1
27-
namespace: default
2825
use_in_memory_disk: true
2926
docker_arguments:
3027
CIRRUS_AWS_ACCOUNT: ${CIRRUS_AWS_ACCOUNT}
31-
DEPLOY_PULL_REQUEST: true
3228
cpu: 3
3329
memory: 8G
3430

31+
poetry_cache_template: &POETRY_CACHE
32+
poetry_cache:
33+
folder: .cache/poetry/
34+
fingerprint_script: cat poetry.lock
3535

3636
.poetry_template: &POETRY_TEMPLATE
37-
<<: *ONLY_SONARSOURCE_QA
3837
eks_container:
3938
<<: *CONTAINER_DEFINITION
40-
poetry_script:
41-
- poetry config repositories.repox "${REPOX_URL}/api/pypi/sonarsource-pypi/simple/"
42-
- poetry config http-basic.repox "${ARTIFACTORY_PRIVATE_USERNAME}" "${ARTIFACTORY_PRIVATE_PASSWORD}"
43-
- poetry install
39+
<<: *POETRY_CACHE
40+
poetry_install_script:
41+
- source set_poetry_build_version "$CI_BUILD_NUMBER"
42+
- echo "PROJECT_VERSION=$PROJECT_VERSION" >> $CIRRUS_ENV
43+
- jfrog config add repox --artifactory-url "$ARTIFACTORY_URL" --access-token "$ARTIFACTORY_PRIVATE_ACCESS_TOKEN"
44+
- jfrog poetry-config --server-id-resolve repox --repo-resolve sonarsource-pypi
45+
- jfrog poetry install --build-name="$CIRRUS_REPO_NAME" --build-number="$CI_BUILD_NUMBER"
4446

4547
formatting_task:
4648
<<: *POETRY_TEMPLATE
@@ -60,6 +62,11 @@ analysis_task:
6062
analysis_script:
6163
- poetry run pytest --cov-report=xml:coverage.xml --cov-config=pyproject.toml --cov=src --cov-branch tests
6264
- sonar-scanner -Dsonar.organization=sonarsource -DbuildNumber=${CI_BUILD_NUMBER}
65+
always:
66+
pytest_artifacts:
67+
path: "coverage.xml"
68+
format: junit
69+
type: text/xml
6370

6471
qa_task:
6572
alias: qa
@@ -88,17 +95,24 @@ qa_task:
8895
qa_script:
8996
- poetry run pytest tests/
9097

91-
publish_task:
98+
build_task:
99+
<<: *POETRY_TEMPLATE
100+
alias: build
101+
name: "Build"
102+
build_script: regular_poetry_build_publish
103+
104+
promote_task:
92105
depends_on:
93106
- formatting
94107
- analysis
95108
- qa
109+
- build
110+
env:
111+
ARTIFACTORY_PROMOTE_ACCESS_TOKEN: VAULT[development/artifactory/token/${CIRRUS_REPO_OWNER}-${CIRRUS_REPO_NAME}-promoter access_token]
112+
GITHUB_TOKEN: VAULT[development/github/token/${CIRRUS_REPO_OWNER}-${CIRRUS_REPO_NAME}-promotion token]
113+
BURGR_URL: VAULT[development/kv/data/burgr data.url]
114+
BURGR_USERNAME: VAULT[development/kv/data/burgr data.cirrus_username]
115+
BURGR_PASSWORD: VAULT[development/kv/data/burgr data.cirrus_password]
116+
ARTIFACTS: :pysonar:tar.gz,:pysonar:whl:py3-none-any
96117
<<: *POETRY_TEMPLATE
97-
name: "Publish (Repox)"
98-
publish_script:
99-
- poetry version patch
100-
- poetry version $(poetry version -s).dev${CI_BUILD_NUMBER}
101-
- poetry build
102-
- poetry config repositories.sonarsource https://repox.jfrog.io/artifactory/api/pypi/sonarsource-pypi-builds
103-
- poetry publish -r sonarsource --username ${ARTIFACTORY_DEPLOY_USERNAME} --password ${ARTIFACTORY_DEPLOY_PASSWORD} --verbose
104-
118+
promote_script: cirrus_promote

.cirrus/poetry.Dockerfile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ RUN curl "https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-
2525
USER sonarsource
2626

2727
RUN curl -sSL https://install.python-poetry.org | python3 -
28-
ENV PATH=/usr/bin:$PATH
29-
ENV PATH="/home/sonarsource/bin:${PATH}"
3028
ENV PATH="${PATH}:/opt/sonar-scanner/bin"
3129
ENV PATH="${PATH}:/home/sonarsource/.local/bin"
3230

3331
ENV SONARCLOUD_ANALYSIS true
34-

.github/workflows/build-pr.yml

Lines changed: 0 additions & 53 deletions
This file was deleted.

.github/workflows/release.yml

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,17 @@
11
name: sonar-release
2-
# This workflow is triggered when publishing a new github release
2+
# This workflow is triggered when publishing a new GitHub release
33
on:
44
release:
55
types:
66
- published
77

88
jobs:
9-
pypi-publish:
10-
name: Upload release to TestPyPI
11-
runs-on: ubuntu-latest
12-
environment:
13-
name: pypi
9+
release:
1410
permissions:
15-
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
16-
contents: read
17-
steps:
18-
# retrieve your distributions here
19-
- uses: actions/checkout@v3
20-
- name: Set up Python
21-
uses: actions/setup-python@v4
22-
with:
23-
python-version: '3.x'
24-
- name: Install dependencies
25-
run: |
26-
python -m pip install --upgrade pip
27-
pip install build
28-
- name: Build package
29-
run: python -m build
30-
- name: Publish package distributions to TestPyPI
31-
uses: pypa/gh-action-pypi-publish@release/v1
32-
with:
33-
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
34-
repository-url: https://test.pypi.org/legacy/
11+
id-token: write
12+
contents: write
13+
uses: SonarSource/gh-action_release/.github/workflows/main.yaml@v5
14+
with:
15+
publishToPyPI: false
16+
publishToTestPyPI: true
17+
skipPythonReleasabilityChecks: true

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,16 @@ Also `dist/*` can be a bit more precise to upload a specific version of the bina
184184

185185
# Update the package version
186186

187-
To update the version use the hatch command:
187+
To update the version use the Poetry command:
188188

189189
```
190190
poetry version "X.Y.Z"
191191
```
192-
For more options on the version update see [the hatch documentation](https://hatch.pypa.io/latest/version/)
192+
or
193+
```shell
194+
poetry version patch
195+
```
196+
For more options on the version update see [the Poetry documentation](https://python-poetry.org/docs/cli/#version)
193197

194198
# Tooling
195199
## Formatting

0 commit comments

Comments
 (0)