Skip to content

Commit

Permalink
[CLIENT-1837] CI/CD: Label version with git commit when building on a…
Browse files Browse the repository at this point in the history
… non-tagged commit (#605)

* Also label version when building unoptimized, with macOS debug support, or with uncommitted changes to the repo (i.e add a "dirty" label)
* Rename config.conf to config.conf.template and add config.conf to .gitignore, so creating and modifying config.conf won't cause the repo to be in a dirty state
  • Loading branch information
juliannguyen4 authored May 16, 2024
1 parent f321c35 commit 17335dc
Show file tree
Hide file tree
Showing 12 changed files with 149 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .github/actions/run-ee-server/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ runs:
working-directory: .github/workflows
shell: bash

- name: Create config.conf
run: cp config.conf.template config.conf
working-directory: test
shell: bash

- name: Use enterprise edition instead of community edition in config.conf
run: |
crudini --existing=param --set config.conf enterprise-edition hosts ''
Expand Down
24 changes: 14 additions & 10 deletions .github/workflows/build-wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ jobs:
with:
submodules: recursive
ref: ${{ inputs.ref }}
fetch-depth: 0

- name: Install build dependencies (pip packages)
run: python3 -m pip install -r requirements.txt
Expand Down Expand Up @@ -147,6 +148,7 @@ jobs:
with:
submodules: recursive
ref: ${{ inputs.ref }}
fetch-depth: 0

- name: Set up QEMU for cross compiling arm64
if: ${{ matrix.platform == 'aarch64' }}
Expand All @@ -170,16 +172,6 @@ jobs:
if: ${{ !inputs.run_tests }}
run: echo "TEST_COMMAND=python -c 'import aerospike'" >> $GITHUB_ENV

- name: Get current version if building a debug wheel
if: ${{ inputs.apply-no-optimizations }}
run: echo DEBUG_VERSION="$(cat VERSION)+unoptimized" >> $GITHUB_ENV

- name: Label version for debugging
if: ${{ inputs.apply-no-optimizations }}
uses: ./.github/actions/update-version
with:
new_version: ${{ env.DEBUG_VERSION }}

- name: Set unoptimize flag
if: ${{ inputs.apply-no-optimizations }}
run: echo "UNOPTIMIZED=1" >> $GITHUB_ENV
Expand Down Expand Up @@ -235,6 +227,7 @@ jobs:
with:
submodules: recursive
ref: ${{ inputs.ref }}
fetch-depth: 0

- name: Install Docker Engine
if: ${{ inputs.run_tests }}
Expand Down Expand Up @@ -323,6 +316,7 @@ jobs:
with:
submodules: recursive
ref: ${{ inputs.ref }}
fetch-depth: 0

# Update dependencies if needed
- name: Add brew to path
Expand Down Expand Up @@ -381,6 +375,10 @@ jobs:
run: python${{ matrix.python-version[1] }} -m pip install --break-system-packages --force-reinstall delocate -c ./requirements.txt
working-directory: .github/workflows

- name: Create config.conf
run: cp config.conf.template config.conf
working-directory: test

- run: delocate-wheel --require-archs "arm64" -w wheelhouse/ -v dist/*.whl
- run: python${{ matrix.python-version[1] }} -m pip install --break-system-packages --find-links=wheelhouse/ --no-index --force-reinstall aerospike

Expand Down Expand Up @@ -439,6 +437,7 @@ jobs:
with:
submodules: recursive
ref: ${{ inputs.ref }}
fetch-depth: 0

- name: Add msbuild to PATH
uses: microsoft/[email protected]
Expand Down Expand Up @@ -498,6 +497,11 @@ jobs:
uses: actions/download-artifact@v4
with:
name: ${{ matrix.python[0] }}-win_amd64.build

- name: Create config.conf
run: cp config.conf.template config.conf
working-directory: test

- name: Install wheel
run: python${{ matrix.python[1] }} -m pip install aerospike --force-reinstall --no-index --find-links=./
- name: Connect to Docker container on remote machine with Docker daemon
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/test-server-rc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ jobs:
- name: Run server RC
run: docker run -d -p 3000:3000 --name aerospike ${{ vars.SERVER_RC_REPO_LINK }}

- name: Create config.conf
run: cp config.conf.template config.conf
working-directory: test

- name: Wait for server to be ready
run: sleep 5

Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ jobs:
- uses: actions/checkout@v2
with:
submodules: recursive
fetch-depth: 0

- uses: actions/setup-python@v2
with:
Expand Down Expand Up @@ -102,6 +103,10 @@ jobs:
# Should be ready after 3 seconds
run: sleep 3

- name: Create config.conf
run: cp config.conf.template config.conf
working-directory: test

- name: Get number of tests
run: echo "NUM_TESTS=$(python3 -m pytest new_tests/ --collect-only -q | tail -n 1 | awk '{print $1;}')" >> $GITHUB_ENV
working-directory: test
Expand All @@ -119,6 +124,7 @@ jobs:
- uses: actions/checkout@v2
with:
submodules: recursive
fetch-depth: 0

- uses: actions/setup-python@v2
with:
Expand Down Expand Up @@ -275,6 +281,10 @@ jobs:
# Should be ready after 3 seconds
run: sleep 3

- name: Create config.conf
run: cp config.conf.template config.conf
working-directory: test

- name: Run tests
run: python -m pytest ./new_tests
working-directory: test
Expand Down Expand Up @@ -331,6 +341,10 @@ jobs:
# Should be ready after 3 seconds
run: sleep 3

- name: Create config.conf
run: cp config.conf.template config.conf
working-directory: test

- name: Run tests
run: python -m pytest ./new_tests -vv
working-directory: test
Expand Down Expand Up @@ -365,6 +379,10 @@ jobs:
# Should be ready after 3 seconds
run: sleep 3

- name: Create config.conf
run: cp config.conf.template config.conf
working-directory: test

- name: Run tests
run: python -m pytest ./new_tests
working-directory: test
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/valgrind.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0

- uses: actions/setup-python@v2
with:
Expand Down
17 changes: 15 additions & 2 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,18 @@ python3 -m pip install -r requirements.txt
python3 -m build
```

### Local version identifier

If you are building on a non-tagged commit, or there are uncommitted changes to the repository, a local version
identifier will be added to the version. The formatting of the local version identifier can be found [here](https://github.com/jwodder/versioningit/tree/v3.1.0?tab=readme-ov-file#example-configurations) under the versioneer
section.

The local version identifier will appear in:
- The package version in the wheel name
- `python3 -m pip show aerospike` if you installed the wheel

The local version identifier will NOT show up in `aerospike.__version__`.

### Unoptimized builds (only Linux and macOS)

By default, the Python client and the C client submodule are built with optimizations, which can make debugging
Expand All @@ -129,8 +141,7 @@ environment variable:
UNOPTIMIZED=1 python3 -m build
```

In Linux, the package version will be labelled with `+debug`. This label is not applied to macOS currently, but it
will be supported in the future (soon).
In Linux and macOS builds, the package version will be labelled with `+unoptimized`.

### Including debug symbols in macOS

Expand All @@ -144,6 +155,8 @@ This way, when you debug the Python client using lldb, the source files and line
breakpoints will actually work, etc. macOS builds with this option enabled do not have a labelled version yet, but this
will be added in the future.

In macOS builds, the package version will be labelled with `+dsym`.

### Building with sanitizer enabled

You can build the Python client with sanitizer to find memory errors and memory leaks. To do this, pass in an environment variable:
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ recursive-include src *
include modules/aerospike-lua-core/src/*.lua
global-include *.pyi
global-include *.typed
include custom-versionit-format.py
62 changes: 62 additions & 0 deletions custom-versionit-format.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from parver import Version
import versioningit
from typing import Any, Dict, Union
import pathlib

import versioningit.basics
import versioningit.git
import os

# Take in <version> and <string> as input
# If local version identifier doesn't exist, append +<string> to <version>
# Example: 15.0.0rc1 and dsym as input -> 15.0.0rc1+dsym
# If it does exist, append <version> with .<string>
# Then output new version as str
def append_to_local(version_str: str, value: str) -> str:
version = Version.parse(version_str, strict=True)
if version.local == None:
new_local = value
else:
new_local = f"{version.local}.{value}"

version = version.replace(local=new_local)
return version.__str__()

def my_vcs(
project_dir: Union[str, pathlib.Path],
params: Dict[str, Any]
) -> versioningit.VCSDescription:
vcs_description = versioningit.git.describe_git(
project_dir=project_dir,
params=params
)
if vcs_description.state == "exact":
# We don't want the format step to be skipped
# Workaround: https://github.com/jwodder/versioningit/issues/42#issuecomment-1235573432
vcs_description.state = "exact_"
return vcs_description

def my_format(
description: versioningit.VCSDescription,
base_version: str,
next_version: str,
params: Dict[str, Any]
) -> str:
# Even if the repository state matches a tag, we always need to label the version if it's unoptimized or includes
# dsym for macOS
if description.state != "exact_":
version_str = versioningit.basics.basic_format(
description=description,
base_version=base_version,
next_version=next_version,
params=params
)
else:
version_str = base_version

if os.getenv("UNOPTIMIZED"):
version_str = append_to_local(version_str, "unoptimized")
if os.getenv("INCLUDE_DSYM"):
version_str = append_to_local(version_str, "dsym")

return version_str
24 changes: 23 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
[build-system]
requires = ["setuptools"]
requires = [
"setuptools",
"versioningit==3.1.0",
# Used by our versioningit script that modifies the version
"parver==0.5"
]
build-backend = "setuptools.build_meta"

[project]
Expand Down Expand Up @@ -32,3 +37,20 @@ dynamic = ["version"]
[tool.setuptools]
zip-safe = false
include-package-data = true

[tool.versioningit]

[tool.versioningit.vcs]
method = {module = "custom-versionit-format", value="my_vcs"}

# Use versioneer formatting
[tool.versioningit.format]
method = {module = "custom-versionit-format", value="my_format"}
distance = "{base_version}+{distance}.{vcs}{rev}"
# Example formatted version: 1.2.3+42.ge174a1f

dirty = "{base_version}+{distance}.{vcs}{rev}.dirty"
# Example formatted version: 1.2.3+42.ge174a1f.dirty

distance-dirty = "{base_version}+{distance}.{vcs}{rev}.dirty"
# Example formatted version: 1.2.3+42.ge174a1f.dirty
1 change: 1 addition & 0 deletions test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
config.conf
6 changes: 5 additions & 1 deletion test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ python3 -m pytest new_tests/

[Pytest usage]:http://pytest.org/latest/usage.html

To set the server details, modify `config.conf`.
To set the server details:
- Create a copy of `config.conf.template` and rename it to `config.conf`. `config.conf` will be the config file used
for testing, and it will be ignored by git.
- Modify `config.conf` to suit your needs.

If a community edition server is to be used, specify the list of hosts in the
`[community-edition]` section. You can remove the `[enterprise-edition]` section
or leave its options empty.
Expand Down
File renamed without changes.

0 comments on commit 17335dc

Please sign in to comment.