Skip to content

Commit 3bab177

Browse files
Pin python dependencies with Poetry (#60)
Ported from canonical/mysql-k8s-operator#273
1 parent c58d0d4 commit 3bab177

16 files changed

+2366
-328
lines changed

.github/renovate.json5

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
3+
"extends": ["github>canonical/data-platform//renovate_presets/charm.json5"],
4+
"reviewers": ["team:data-platform-mysql"],
5+
"packageRules": [
6+
// Later rules override earlier rules
7+
8+
// MySQL 8.X does not follow semantic versioning (e.g. 8.0.1 -> 8.0.2 can include a breaking change)
9+
// Therefore, use a separate Renovate group so that it has a separate PR
10+
{
11+
"matchManagers": ["poetry"],
12+
"matchPackageNames": ["mysql-connector-python"],
13+
"groupName": "MySQL Connector/Python"
14+
}
15+
]
16+
}

.github/workflows/ci.yaml

Lines changed: 56 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,24 @@ jobs:
2121
steps:
2222
- name: Checkout
2323
uses: actions/checkout@v3
24-
- name: Install tox
25-
# TODO: Consider replacing with custom image on self-hosted runner OR pinning version
26-
run: python3 -m pip install tox
24+
- name: Install tox & poetry
25+
run: |
26+
pipx install tox
27+
pipx install poetry
2728
- name: Run linters
2829
run: tox run -e lint
2930

3031
unit-test:
31-
name: Unit tests
32+
name: Unit test charm
3233
runs-on: ubuntu-latest
3334
timeout-minutes: 5
3435
steps:
3536
- name: Checkout
3637
uses: actions/checkout@v3
37-
- name: Install tox
38-
# TODO: Consider replacing with custom image on self-hosted runner OR pinning version
39-
run: python3 -m pip install tox
38+
- name: Install tox & poetry
39+
run: |
40+
pipx install tox
41+
pipx install poetry
4042
- name: Run tests
4143
run: tox run -e unit
4244
- name: Upload Coverage to Codecov
@@ -61,57 +63,86 @@ jobs:
6163

6264
build:
6365
name: Build charms
64-
uses: canonical/data-platform-workflows/.github/workflows/build_charms_with_cache.yaml@v2
66+
uses: canonical/data-platform-workflows/.github/workflows/[email protected]
67+
with:
68+
charmcraft-snap-revision: 1349 # version 2.3.0
6569
permissions:
6670
actions: write # Needed to manage GitHub Actions cache
6771

68-
integration-test:
72+
gh-hosted-collect-integration-tests:
73+
name: (GH hosted) Collect integration test groups
74+
needs:
75+
- lint
76+
- unit-test
77+
runs-on: ubuntu-latest
78+
steps:
79+
- name: Checkout
80+
uses: actions/checkout@v3
81+
- name: Install tox & poetry
82+
run: |
83+
pipx install tox
84+
pipx install poetry
85+
- name: Select test stability level
86+
id: select-test-stability
87+
run: |
88+
if [[ "${{ github.event_name }}" == "schedule" ]]
89+
then
90+
echo Running unstable and stable tests
91+
echo "mark_expression=" >> "$GITHUB_OUTPUT"
92+
else
93+
echo Skipping unstable tests
94+
echo "mark_expression=not unstable" >> "$GITHUB_OUTPUT"
95+
fi
96+
- name: Collect test groups
97+
id: collect-groups
98+
run: tox run -e integration -- tests/integration -m '${{ steps.select-test-stability.outputs.mark_expression }}' --collect-groups
99+
outputs:
100+
groups: ${{ steps.collect-groups.outputs.groups }}
101+
102+
gh-hosted-integration-test:
69103
strategy:
70104
fail-fast: false
71105
matrix:
72-
tox-environments:
73-
# TODO: uncomment when the following bug is resolved:
74-
# https://bugs.launchpad.net/charm-keystone/+bug/1990243
75-
# - integration-shared-db
76-
- integration-database
106+
groups: ${{ fromJSON(needs.gh-hosted-collect-integration-tests.outputs.groups) }}
77107
ubuntu-versions:
78108
# Update whenever charmcraft.yaml is changed
79109
- series: focal
80110
bases-index: 0
81111
- series: jammy
82112
bases-index: 1
83-
name: ${{ matrix.tox-environments }} | ${{ matrix.ubuntu-versions.series }}
113+
name: (GH hosted) ${{ matrix.groups.job_name }} | ${{ matrix.ubuntu-versions.series }}
84114
needs:
85115
- lint
86116
- unit-test
87117
- build
118+
- gh-hosted-collect-integration-tests
88119
runs-on: ubuntu-latest
89120
timeout-minutes: 120
90121
steps:
91122
- name: Checkout
92123
uses: actions/checkout@v3
124+
- name: Install tox & poetry
125+
run: |
126+
pipx install tox
127+
pipx install poetry
93128
- name: Setup operator environment
94-
# TODO: Replace with custom image on self-hosted runner
95129
uses: charmed-kubernetes/actions-operator@main
96130
with:
97131
provider: lxd
98-
bootstrap-options: "--agent-version 2.9.42"
99132
- name: Download packed charm(s)
100133
uses: actions/download-artifact@v3
101134
with:
102135
name: ${{ needs.build.outputs.artifact-name }}
103-
- name: Select tests
104-
id: select-tests
136+
- name: Select test stability level
137+
id: select-test-stability
105138
run: |
106-
if [ "${{ github.event_name }}" == "schedule" ]
139+
if [[ "${{ github.event_name }}" == "schedule" ]]
107140
then
108141
echo Running unstable and stable tests
109-
echo "mark_expression=" >> $GITHUB_OUTPUT
142+
echo "mark_expression=" >> "$GITHUB_OUTPUT"
110143
else
111144
echo Skipping unstable tests
112-
echo "mark_expression=not unstable" >> $GITHUB_OUTPUT
145+
echo "mark_expression=not unstable" >> "$GITHUB_OUTPUT"
113146
fi
114147
- name: Run integration tests
115-
run: tox run -e ${{ matrix.tox-environments }} -- -m '${{ steps.select-tests.outputs.mark_expression }}' --mysql-router-charm-series=${{ matrix.ubuntu-versions.series }} --mysql-router-charm-bases-index=${{ matrix.ubuntu-versions.bases-index }}
116-
env:
117-
CI_PACKED_CHARMS: ${{ needs.build.outputs.charms }}
148+
run: tox run -e integration -- "${{ matrix.groups.path_to_test_file }}" --group="${{ matrix.groups.group_number }}" -m '${{ steps.select-test-stability.outputs.mark_expression }}' --mysql-router-charm-series=${{ matrix.ubuntu-versions.series }} --mysql-router-charm-bases-index=${{ matrix.ubuntu-versions.bases-index }}

.github/workflows/release.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ jobs:
1717

1818
build:
1919
name: Build charm
20-
uses: canonical/data-platform-workflows/.github/workflows/build_charm_without_cache.yaml@v2
20+
uses: canonical/data-platform-workflows/.github/workflows/build_charm_without_cache.yaml@v5.0.1
2121

2222
release:
2323
name: Release charm
2424
needs:
2525
- ci-tests
2626
- build
27-
uses: canonical/data-platform-workflows/.github/workflows/release_charm.yaml@v2
27+
uses: canonical/data-platform-workflows/.github/workflows/release_charm.yaml@v5.0.1
2828
with:
2929
channel: dpe/edge
3030
artifact-name: ${{ needs.build.outputs.artifact-name }}

.github/workflows/sync_issue_to_jira.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
jobs:
1010
sync:
1111
name: Sync GitHub issue to Jira
12-
uses: canonical/data-platform-workflows/.github/workflows/sync_issue_to_jira.yaml@v2
12+
uses: canonical/data-platform-workflows/.github/workflows/sync_issue_to_jira.yaml@v5.0.1
1313
with:
1414
jira-base-url: https://warthogs.atlassian.net
1515
jira-project-key: DPE

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/requirements.txt
2+
/requirements-last-build.txt
3+
14
venv/
25
build/
36
*.charm

CONTRIBUTING.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,18 @@ git clone https://github.com/canonical/mysql-router-operator.git
5656
cd mysql-router-operator
5757
```
5858

59-
You can create an environment for development with `tox`:
59+
Install `tox` and `poetry`
60+
```shell
61+
python3 -m pip install --user pipx
62+
python3 -m pipx ensurepath
63+
pipx install tox
64+
pipx install poetry
65+
```
66+
67+
You can create an environment for development:
6068

6169
```shell
62-
tox devenv -e integration
63-
source venv/bin/activate
70+
poetry install
6471
```
6572

6673
### Testing
@@ -78,7 +85,7 @@ tox # runs 'lint' and 'unit' environments
7885
Build the charm in this git repository using:
7986

8087
```shell
81-
charmcraft pack
88+
tox run -e build
8289
```
8390

8491
### Deploy

charmcraft.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ bases:
2020
channel: "22.04"
2121
parts:
2222
charm:
23+
override-pull: |
24+
craftctl default
25+
if [[ ! -f requirements.txt ]]
26+
then
27+
echo 'ERROR: Use "tox run -e build" instead of calling "charmcraft pack" directly' >&2
28+
exit 1
29+
fi
2330
charm-entrypoint: src/machine_charm.py
2431
charm-binary-python-packages:
2532
- mysql-connector-python==8.0.32

0 commit comments

Comments
 (0)