Skip to content

Commit e1ca571

Browse files
authored
SCANPY-217: Migrate from Cirrus CI to GitHub Action (#262)
1 parent c7591f3 commit e1ca571

File tree

6 files changed

+347
-195
lines changed

6 files changed

+347
-195
lines changed

.cirrus.yml

Lines changed: 1 addition & 195 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ env:
1616
CRON_NIGHTLY_JOB_NAME: "nightly"
1717

1818
only_if: $CIRRUS_USER_COLLABORATOR == 'true' && $CIRRUS_TAG == "" && ($CIRRUS_PR != "" || $CIRRUS_BRANCH == 'master' || $CIRRUS_BRANCH =~ "branch-.*")
19+
1920
linux_container_definition: &LINUX_CONTAINER_DEFINITION
2021
eks_container:
2122
dockerfile: .cirrus/poetry.Dockerfile
@@ -31,57 +32,12 @@ linux_container_definition: &LINUX_CONTAINER_DEFINITION
3132
cpu: 3
3233
memory: 8G
3334

34-
win_vm_definition: &WINDOWS_VM_DEFINITION
35-
env:
36-
JF_ALIAS: "jf"
37-
ec2_instance:
38-
experimental: true # see https://github.com/cirruslabs/cirrus-ci-docs/issues/1051
39-
image: base-windows-jdk17-v*
40-
platform: windows
41-
region: eu-central-1
42-
type: c6id.4xlarge
43-
preemptible: false
44-
use_ssd: true
45-
46-
win_ssd_and_clone:
47-
&WIN_SSD_AND_CLONE # copy&paste from https://github.com/SonarSource/sonar-cpp/blob/a8c6f1e45a12393508682a013ac7ee35eb92bece/.cirrus.yml#L45
48-
prepare_disk_script:
49-
- ps: |
50-
Get-Disk -Number 2 | Initialize-Disk -PassThru | New-Partition -UseMaximumSize -DriveLetter Z
51-
Format-Volume -DriveLetter Z -FileSystem NTFS -Confirm:$false
52-
- echo "CIRRUS_WORKING_DIR=Z:/cirrus-ci-build" >> $CIRRUS_ENV
53-
# we don't clone submodules because they are not needed for the tests
54-
clone_script: |
55-
git config --system core.longpaths true
56-
if [ -z "$CIRRUS_PR" ]; then
57-
git clone --branch=$CIRRUS_BRANCH https://x-access-token:${CIRRUS_REPO_CLONE_TOKEN}@github.com/${CIRRUS_REPO_FULL_NAME}.git $CIRRUS_WORKING_DIR
58-
git reset --hard $CIRRUS_CHANGE_IN_REPO
59-
else
60-
git clone https://x-access-token:${CIRRUS_REPO_CLONE_TOKEN}@github.com/${CIRRUS_REPO_FULL_NAME}.git $CIRRUS_WORKING_DIR
61-
git fetch origin pull/$CIRRUS_PR/head:pull/$CIRRUS_PR
62-
git reset --hard $CIRRUS_CHANGE_IN_REPO
63-
fi
64-
6535
.jfrog_config_template: &JFROG_CONFIG_TEMPLATE
6636
jfrog_config_script:
6737
- $JF_ALIAS config add repox --artifactory-url "$ARTIFACTORY_URL" --access-token "$ARTIFACTORY_PRIVATE_ACCESS_TOKEN"
6838
- $JF_ALIAS poetry-config --server-id-resolve repox --repo-resolve sonarsource-pypi
6939
- $JF_ALIAS poetry install --build-name="$CIRRUS_REPO_NAME" --build-number="$CI_BUILD_NUMBER"
7040

71-
poetry_win_install: &POETRY_WIN_INSTALL
72-
<<: *WINDOWS_VM_DEFINITION
73-
<<: *WIN_SSD_AND_CLONE
74-
env:
75-
PYTHON_VERSION: 3.12.1
76-
POETRY_VERSION: 2.0.1
77-
jfrog_win_install_script:
78-
- powershell "Start-Process -Wait -Verb RunAs powershell '-NoProfile iwr https://releases.jfrog.io/artifactory/jfrog-cli/v2-jf/[RELEASE]/jfrog-cli-windows-amd64/jf.exe -OutFile $env:SYSTEMROOT\system32\jf.exe'"
79-
- jf intro
80-
poetry_win_install_script:
81-
- source cirrus-env QA
82-
- pip install poetry=="$POETRY_VERSION"
83-
<<: *JFROG_CONFIG_TEMPLATE
84-
8541
poetry_cache_template: &POETRY_CACHE
8642
poetry_cache:
8743
folder: ~/.cache/poetry/
@@ -93,11 +49,6 @@ poetry_cache_template: &POETRY_CACHE
9349
poetry_install_script:
9450
- poetry install
9551

96-
.poetry_set_version_template: &POETRY_SET_VERSION
97-
poetry_set_version_script:
98-
- source set_poetry_build_version "$CI_BUILD_NUMBER"
99-
- echo "PROJECT_VERSION=$PROJECT_VERSION" >> $CIRRUS_ENV
100-
10152
.poetry_macos_template: &POETRY_MACOS_TEMPLATE
10253
<<: *POETRY_CACHE
10354
jfrog_install_script:
@@ -120,104 +71,6 @@ macos_worker_template: &MACOS_WORKER_DEFINITION
12071
labels:
12172
envname: prod
12273

123-
formatting_task:
124-
alias: formatting
125-
name: "Formatting"
126-
<<: *LINUX_CONTAINER_DEFINITION
127-
<<: *POETRY_INSTALL
128-
formatting_script:
129-
- poetry run black src/ tests/ --check
130-
- poetry run licenseheaders -t license_header.tmpl -o "SonarSource SA" -y 2011-2024 -n "Sonar Scanner Python" -E .py -d src/
131-
- poetry run licenseheaders -t license_header.tmpl -o "SonarSource SA" -y 2011-2024 -n "Sonar Scanner Python" -E .py -d tests/
132-
- git diff --name-only --exit-code ./src ./tests
133-
134-
documentation_task:
135-
alias: documentation
136-
name: "CLI Documentation"
137-
<<: *LINUX_CONTAINER_DEFINITION
138-
<<: *POETRY_INSTALL
139-
cli_docs_script:
140-
- poetry run python tools/generate_cli_documentation.py
141-
- git diff --exit-code CLI_ARGS.md
142-
143-
analysis_base_linux_template: &ANALYSIS_BASE_LINUX_TEMPLATE
144-
<<: *LINUX_CONTAINER_DEFINITION
145-
<<: *POETRY_INSTALL
146-
# For analysis we don't need to set the build versions, but we still need to access jfrog to recover the dependencies
147-
analysis_script:
148-
- poetry run pytest --cov-report=xml:coverage.xml --cov-config=pyproject.toml --cov=src --cov-branch tests
149-
- poetry run mypy src/ > mypy-report.txt || true # mypy exits with 1 if there are errors
150-
- uv venv
151-
- source .venv/bin/activate
152-
- uv pip install pysonar
153-
- . .cirrus/analysis.sh
154-
always:
155-
pytest_artifacts:
156-
path: "coverage.xml"
157-
format: junit
158-
type: text/xml
159-
160-
analysis_next_task:
161-
<<: *ANALYSIS_BASE_LINUX_TEMPLATE
162-
alias: sonar_analysis_next
163-
name: "NEXT Analysis"
164-
env:
165-
SONAR_TOKEN: VAULT[development/kv/data/next data.token]
166-
SONAR_HOST_URL: https://next.sonarqube.com/sonarqube
167-
168-
analysis_SQC_EU_shadow_task:
169-
<<: *ANALYSIS_BASE_LINUX_TEMPLATE
170-
# only executed in CRON job AND on master branch
171-
only_if: $CIRRUS_CRON == $CRON_NIGHTLY_JOB_NAME && $CIRRUS_BRANCH == "master"
172-
alias: sonar_analysis_shadow_sqc_eu
173-
name: "SQC-EU Shadow Analysis"
174-
env:
175-
SONAR_TOKEN: VAULT[development/kv/data/sonarcloud data.token]
176-
SONAR_HOST_URL: https://sonarcloud.io
177-
178-
analysis_SQC_US_shadow_task:
179-
<<: *ANALYSIS_BASE_LINUX_TEMPLATE
180-
# only executed in CRON job AND on master branch
181-
only_if: $CIRRUS_CRON == $CRON_NIGHTLY_JOB_NAME && $CIRRUS_BRANCH == "master"
182-
alias: sonar_analysis_shadow_sqc_us
183-
name: "SQC-US Shadow Analysis"
184-
env:
185-
SONAR_TOKEN: VAULT[development/kv/data/sonarqube-us data.token]
186-
SONAR_HOST_URL: https://sonarqube.us
187-
188-
qa_task:
189-
alias: qa
190-
matrix:
191-
- name: "Test Python 3.9.18"
192-
eks_container:
193-
docker_arguments:
194-
PYTHON_VERSION: 3.9.18
195-
- name: "Test Python 3.9.6"
196-
eks_container:
197-
docker_arguments:
198-
PYTHON_VERSION: 3.9.6
199-
- name: "Test Python 3.10"
200-
eks_container:
201-
docker_arguments:
202-
PYTHON_VERSION: 3.10.13
203-
- name: "Test Python 3.11"
204-
eks_container:
205-
docker_arguments:
206-
PYTHON_VERSION: 3.11.7
207-
- name: "Test Python 3.12"
208-
eks_container:
209-
docker_arguments:
210-
PYTHON_VERSION: 3.12.1
211-
- name: "Test Python 3.13"
212-
eks_container:
213-
docker_arguments:
214-
PYTHON_VERSION: 3.13.2
215-
<<: *LINUX_CONTAINER_DEFINITION
216-
<<: *POETRY_INSTALL
217-
<<: *POETRY_SET_VERSION
218-
qa_script:
219-
- poetry run pytest tests/
220-
22174
qa_macos_task:
22275
alias: qa_macos
22376
only_if: $CIRRUS_CRON == "macos-its-cron"
@@ -238,35 +91,6 @@ qa_macos_task:
23891
test_313_script:
23992
- .cirrus/run_macos_tests.sh "3.13.2"
24093

241-
qa_windows_task:
242-
name: "Test Windows"
243-
<<: *POETRY_WIN_INSTALL
244-
<<: *POETRY_SET_VERSION
245-
alias: qa_windows
246-
qa_script:
247-
- poetry run pytest tests/
248-
- exit $LASTEXITCODE
249-
250-
build_task:
251-
<<: *LINUX_CONTAINER_DEFINITION
252-
<<: *POETRY_INSTALL
253-
<<: *POETRY_SET_VERSION
254-
alias: build
255-
name: "Build"
256-
build_script: regular_poetry_build_publish
257-
258-
its_task:
259-
name: "Integration Tests"
260-
alias: its
261-
sonarqube_cache:
262-
folder: sonarqube_cache/
263-
populate_script: mkdir -p sonarqube_cache && wget -q https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-$SONARQUBE_VERSION.zip -O sonarqube_cache/sonarqube.zip
264-
fingerprint_script: echo "sonarqube-$SONARQUBE_VERSION"
265-
<<: *LINUX_CONTAINER_DEFINITION
266-
<<: *POETRY_INSTALL
267-
its_script:
268-
- .cirrus/run_its.sh
269-
27094
its_macos_task:
27195
name: "[macOS] Integration Tests"
27296
alias: its_macos
@@ -280,25 +104,7 @@ its_macos_task:
280104
its_script:
281105
- .cirrus/run_its.sh
282106

283-
promote_task:
284-
depends_on:
285-
- formatting
286-
- sonar_analysis_next
287-
- qa
288-
- qa_windows
289-
- build
290-
- its
291-
env:
292-
ARTIFACTORY_PROMOTE_ACCESS_TOKEN: VAULT[development/artifactory/token/${CIRRUS_REPO_OWNER}-${CIRRUS_REPO_NAME}-promoter access_token]
293-
GITHUB_TOKEN: VAULT[development/github/token/${CIRRUS_REPO_OWNER}-${CIRRUS_REPO_NAME}-promotion token]
294-
<<: *LINUX_CONTAINER_DEFINITION
295-
<<: *POETRY_INSTALL
296-
<<: *POETRY_SET_VERSION
297-
promote_script: cirrus_promote
298-
299107
run_iris_task:
300-
depends_on:
301-
- promote
302108
<<: *LINUX_CONTAINER_DEFINITION
303109
# only executed in CRON job AND on master branch
304110
only_if: $CIRRUS_CRON == $CRON_NIGHTLY_JOB_NAME && $CIRRUS_BRANCH == "master"
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
---
2+
name: Configure Poetry
3+
description: GitHub Action to configure a poetry project
4+
5+
inputs:
6+
python-version:
7+
description: The version of python to use
8+
default: 3.12.1
9+
poetry-version:
10+
description: The version of poetry to install
11+
default: 2.2.1
12+
jfrog-version:
13+
description: The version of jFrog to install
14+
default: 2.77.0
15+
poetry-virtualenvs-path:
16+
description: Path to the Poetry virtual environments, relative to GitHub workspace. The folder is cached only if it is a subdirectory of
17+
`poetry-cache-dir`.
18+
default: .cache/pypoetry/virtualenvs
19+
poetry-cache-dir:
20+
description: Path to the Poetry cache directory, relative to GitHub workspace.
21+
default: .cache/pypoetry
22+
outputs:
23+
BUILD_NUMBER:
24+
description: The build number, incremented or reused if already cached
25+
value: ${{ steps.get_build_number.outputs.BUILD_NUMBER }}
26+
27+
runs:
28+
using: composite
29+
steps:
30+
- name: Set build parameters
31+
shell: bash
32+
env:
33+
ARTIFACTORY_READER_ROLE: private-reader
34+
run: |
35+
echo "ARTIFACTORY_READER_ROLE=${ARTIFACTORY_READER_ROLE}" >> "$GITHUB_ENV"
36+
- uses: SonarSource/ci-github-actions/get-build-number@v1
37+
id: get_build_number
38+
- name: Cache local Poetry cache
39+
uses: SonarSource/ci-github-actions/cache@v1
40+
with:
41+
path: ${{ inputs.poetry-cache-dir }}
42+
key: poetry-${{ runner.os }}-${{ hashFiles('poetry.lock') }}
43+
restore-keys: poetry-${{ runner.os }}-
44+
- name: Install mise and Python
45+
uses: jdx/mise-action@5ac50f778e26fac95da98d50503682459e86d566 # v3.2.0
46+
with:
47+
version: 2025.7.12
48+
install_args: "python@${{ inputs.python-version }}"
49+
- name: Install jfrog and poetry through mise
50+
uses: jdx/mise-action@5ac50f778e26fac95da98d50503682459e86d566 # v3.2.0
51+
with:
52+
version: 2025.7.12
53+
experimental: true # needed to use the http backend for installation of jfrog on windows
54+
- name: Vault
55+
# yamllint disable rule:line-length
56+
id: secrets
57+
uses: SonarSource/vault-action-wrapper@320bd31b03e5dacaac6be51bbbb15adf7caccc32 # 3.1.0
58+
with:
59+
secrets: |
60+
development/artifactory/token/{REPO_OWNER_NAME_DASH}-${{ env.ARTIFACTORY_READER_ROLE }} access_token | ARTIFACTORY_ACCESS_TOKEN;
61+
# yamllint enable rule:line-length
62+
- name: Config Poetry
63+
id: config
64+
shell: bash
65+
env:
66+
ARTIFACTORY_URL: https://repox.jfrog.io/artifactory
67+
ARTIFACTORY_PYPI_REPO: sonarsource-pypi
68+
ARTIFACTORY_ACCESS_TOKEN: ${{ fromJSON(steps.secrets.outputs.vault).ARTIFACTORY_ACCESS_TOKEN }}
69+
POETRY_VIRTUALENVS_PATH: ${{ github.workspace }}/${{ inputs.poetry-virtualenvs-path }}
70+
POETRY_CACHE_DIR: ${{ github.workspace }}/${{ inputs.poetry-cache-dir }}
71+
run: |
72+
echo "POETRY_VIRTUALENVS_PATH=${POETRY_VIRTUALENVS_PATH}" >> "$GITHUB_ENV"
73+
echo "POETRY_CACHE_DIR=${POETRY_CACHE_DIR}" >> "$GITHUB_ENV"
74+
${GITHUB_ACTION_PATH}/config-poetry.sh
75+
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+
config_poetry() {
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/scripts/run_its.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
unzip -q sonarqube_cache/sonarqube.zip -d sonarqube
5+
6+
PLATFORM="linux-x86-64"
7+
if [[ "$(uname)" == "Darwin" ]]; then
8+
PLATFORM="macosx-universal-64"
9+
fi
10+
11+
cd $(ls -d sonarqube/*/)
12+
./bin/${PLATFORM}/sonar.sh start
13+
cd -
14+
15+
unset SONAR_TOKEN
16+
unset SONAR_HOST_URL
17+
18+
poetry install
19+
poetry run pytest --its tests/its

0 commit comments

Comments
 (0)