Skip to content

Commit 473ec06

Browse files
committed
PYSCAN-14: Setup integration test (#29)
1 parent e72fe94 commit 473ec06

26 files changed

+1093
-21
lines changed

.github/workflows/build-pr.yml

Lines changed: 75 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,38 @@ jobs:
1212
test:
1313
runs-on: ubuntu-latest
1414
permissions:
15+
id-token: write # required by SonarSource/vault-action-wrapper
1516
contents: read # required by actions/checkout
1617
strategy:
1718
fail-fast: false
1819
matrix:
1920
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
2021
steps:
22+
- name: Get vault secrets
23+
id: secrets
24+
uses: SonarSource/vault-action-wrapper@v2
25+
with:
26+
secrets: |
27+
development/artifactory/token/{REPO_OWNER_NAME_DASH}-private-reader role | ARTIFACTORY_ROLE;
28+
development/artifactory/token/{REPO_OWNER_NAME_DASH}-private-reader access_token | ARTIFACTORY_PASSWORD;
29+
development/kv/data/repox url | REPOX_URL;
2130
- uses: actions/checkout@v3
31+
- name: Install Poetry
32+
run: |
33+
pipx install poetry
2234
- name: Set up Python ${{ matrix.python-version }}
2335
uses: actions/setup-python@v4
2436
with:
2537
python-version: ${{ matrix.python-version }}
38+
cache: "poetry"
2639
- name: Install dependencies
40+
env:
41+
ARTIFACTORY_USERNAME: vault-${{ fromJSON(steps.secrets.outputs.vault).ARTIFACTORY_ROLE }}
42+
ARTIFACTORY_PASSWORD: ${{ fromJSON(steps.secrets.outputs.vault).ARTIFACTORY_PASSWORD }}
43+
REPOX_URL: ${{ fromJSON(steps.secrets.outputs.vault).REPOX_URL }}
2744
run: |
28-
pipx install poetry
45+
poetry config repositories.repox "${REPOX_URL}/api/pypi/sonarsource-pypi/simple/"
46+
poetry config http-basic.repox "${ARTIFACTORY_USERNAME}" "${ARTIFACTORY_PASSWORD}"
2947
poetry install
3048
- name: Check tests
3149
run: |
@@ -44,34 +62,83 @@ jobs:
4462
uses: SonarSource/vault-action-wrapper@v2
4563
with:
4664
secrets: |
65+
development/artifactory/token/{REPO_OWNER_NAME_DASH}-private-reader role | ARTIFACTORY_ROLE;
4766
development/artifactory/token/{REPO_OWNER_NAME_DASH}-private-reader access_token | ARTIFACTORY_PASSWORD;
4867
development/kv/data/repox url | REPOX_URL;
4968
development/kv/data/sonarcloud token | SONARCLOUD_TOKEN;
5069
- uses: actions/checkout@v3
51-
- name: Set up Python
70+
- name: Install Poetry
71+
run: |
72+
pipx install poetry
73+
- name: Set up Python
5274
uses: actions/setup-python@v4
5375
with:
5476
python-version: |
5577
3.12
78+
cache: "poetry"
5679
- name: Install dependencies
80+
env:
81+
ARTIFACTORY_USERNAME: vault-${{ fromJSON(steps.secrets.outputs.vault).ARTIFACTORY_ROLE }}
82+
ARTIFACTORY_PASSWORD: ${{ fromJSON(steps.secrets.outputs.vault).ARTIFACTORY_PASSWORD }}
83+
REPOX_URL: ${{ fromJSON(steps.secrets.outputs.vault).REPOX_URL }}
5784
run: |
58-
pipx install poetry
85+
poetry config repositories.repox "${REPOX_URL}/api/pypi/sonarsource-pypi/simple/"
86+
poetry config http-basic.repox "${ARTIFACTORY_USERNAME}" "${ARTIFACTORY_PASSWORD}"
5987
poetry install
6088
- name: Check formatting
6189
run: |
6290
poetry run black src/ tests/ --check
6391
- name: Check licensing
6492
run: |
65-
poetry run licenseheaders -t license_header.tmpl -o "SonarSource SA" -y 2011-2023 -n "Sonar Scanner Python" -E .py -d src/
66-
poetry run licenseheaders -t license_header.tmpl -o "SonarSource SA" -y 2011-2023 -n "Sonar Scanner Python" -E .py -d tests/
67-
git diff --name-only --exit-code ./src ./tests
93+
poetry run licenseheaders -t license_header.tmpl -o "SonarSource SA" -y 2011-2024 -n "Sonar Scanner Python" -E .py -d src/
94+
poetry run licenseheaders -t license_header.tmpl -o "SonarSource SA" -y 2011-2024 -n "Sonar Scanner Python" -E .py -d tests/
95+
poetry run licenseheaders -t license_header.tmpl -o "SonarSource SA" -y 2011-2024 -n "Sonar Scanner Python" -E .py -d its/ -x its/sources/**.py
96+
git diff --name-only --exit-code ./src ./tests ./its
6897
- name: Check tests and generate coverage
6998
run: |
7099
poetry run pytest --cov-report=xml:coverage.xml --cov-config=pyproject.toml --cov=src --cov-branch tests
71-
env:
72-
ARTIFACTORY_ACCESS_TOKEN: ${{ fromJSON(steps.secrets.outputs.vault).ARTIFACTORY_PASSWORD }}
73100
- name: SonarCloud Scan
74101
uses: SonarSource/sonarcloud-github-action@master
75102
env:
76103
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
77104
SONAR_TOKEN: ${{ fromJSON(steps.secrets.outputs.vault).SONARCLOUD_TOKEN }}
105+
integration_tests:
106+
runs-on: ubuntu-latest
107+
permissions:
108+
id-token: write # required by SonarSource/vault-action-wrapper
109+
contents: read # required by actions/checkout
110+
strategy:
111+
fail-fast: false
112+
steps:
113+
- name: Get vault secrets
114+
id: secrets
115+
uses: SonarSource/vault-action-wrapper@v2
116+
with:
117+
secrets: |
118+
development/artifactory/token/{REPO_OWNER_NAME_DASH}-private-reader role | ARTIFACTORY_ROLE;
119+
development/artifactory/token/{REPO_OWNER_NAME_DASH}-private-reader access_token | ARTIFACTORY_PASSWORD;
120+
development/kv/data/repox url | REPOX_URL;
121+
- uses: actions/checkout@v3
122+
- name: Install Poetry
123+
run: |
124+
pipx install poetry
125+
- name: Set up Python
126+
uses: actions/setup-python@v4
127+
with:
128+
python-version: |
129+
3.12
130+
cache: "poetry"
131+
- name: Install its dependencies
132+
working-directory: ./its
133+
env:
134+
ARTIFACTORY_USERNAME: vault-${{ fromJSON(steps.secrets.outputs.vault).ARTIFACTORY_ROLE }}
135+
ARTIFACTORY_PASSWORD: ${{ fromJSON(steps.secrets.outputs.vault).ARTIFACTORY_PASSWORD }}
136+
REPOX_URL: ${{ fromJSON(steps.secrets.outputs.vault).REPOX_URL }}
137+
run: |
138+
poetry config repositories.repox "${REPOX_URL}/api/pypi/sonarsource-pypi/simple/"
139+
poetry config http-basic.repox "${ARTIFACTORY_USERNAME}" "${ARTIFACTORY_PASSWORD}"
140+
poetry install
141+
- name: Run integration tests
142+
working-directory: ./its
143+
run: |
144+
poetry run pytest

its/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Integration tests for py-sonar-scanner
2+
3+
## Prerequisits
4+
5+
- Python 3.12
6+
- Docker
7+
8+
## Setup
9+
10+
Before executing the tests be sure to install the dependencies.
11+
12+
In the __its__ folder:
13+
- Create a virtual environment `python3 -m venv <name>`
14+
- Source the environment `source <name>/bin/activate`
15+
- Install its dependencies `poetry install`
16+
- Install cli that will be used in the test:
17+
- to install the built package execute `pip install ../dist/py_sonar_scanner-<version>-py3-none-any-.whl`
18+
- to install the current dev version `pip install ..`
19+
20+
21+
## Running the integration tests
22+
23+
You can now run the tests with `poetry run pytest`
24+

its/compose.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
services:
2+
sonarqube:
3+
image: sonarqube:10.3-community
4+
ports:
5+
- "9000:9000"

0 commit comments

Comments
 (0)