-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add CI build and test for context-py #115
Changes from all commits
485b950
2ebf656
c09ed48
a84299a
c81d242
cda55b5
250ca1c
737a64b
d9e3809
b12056e
6d4440f
9df1689
bfb3d49
e2b8561
a7590fc
68f294c
36e543f
b6d00f7
bbf0b00
06095c3
f839892
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
# This file is autogenerated by maturin v1.5.1 | ||
# To regenerate, run | ||
# | ||
# maturin generate-ci -m ./context-py/Cargo.toml --platform linux --platform macos --pytest --output ./.github/workflows/pyo3.yml github | ||
# | ||
name: Build and test context-py | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- master | ||
tags: | ||
- "*" | ||
pull_request: {} | ||
workflow_dispatch: {} | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
linux: | ||
runs-on: ${{ matrix.platform.runner }} | ||
strategy: | ||
matrix: | ||
platform: | ||
- runner: ubuntu-latest | ||
target: x86_64 | ||
- runner: ubuntu-latest | ||
target: aarch64 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.10" | ||
- name: Build wheels | ||
uses: PyO3/maturin-action@v1 | ||
with: | ||
target: ${{ matrix.platform.target }} | ||
args: --release --out dist --find-interpreter --manifest-path ./context-py/Cargo.toml | ||
manylinux: auto | ||
container: "2_28" | ||
before-script-linux: | | ||
# Needed for `openssl-sys`: | ||
# https://docs.rs/openssl/latest/openssl/ | ||
if [ -f /usr/bin/dnf ]; then | ||
# quay.io/pypa/manylinux_2_28_x86_64:latest | ||
/usr/bin/dnf upgrade | ||
/usr/bin/dnf install -y pkgconf perl-IPC-Cmd openssl-devel python3-pip | ||
/usr/bin/ln -s /usr/bin/pip3 /usr/bin/pip | ||
/usr/bin/ln -sf /usr/bin/python3.11 /usr/bin/python3 | ||
elif [ -f /usr/bin/apt ]; then | ||
# ghcr.io/rust-cross/manylinux_2_28-cross:aarch64 | ||
/usr/bin/apt update | ||
/usr/bin/apt install -y pkg-config libssl-dev | ||
fi | ||
- name: Upload wheels | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: wheels-linux-${{ matrix.platform.target }} | ||
path: dist | ||
- name: pytest | ||
if: ${{ startsWith(matrix.platform.target, 'x86_64') }} | ||
shell: bash | ||
run: | | ||
set -e | ||
pip install context-py --find-links dist --force-reinstall | ||
pip install pytest | ||
cd ./context-py && pytest | ||
- name: pytest | ||
if: ${{ startsWith(matrix.platform.target, 'aarch64') }} | ||
uses: uraimo/run-on-arch-action@v2.5.0 | ||
with: | ||
arch: ${{ matrix.platform.target }} | ||
distro: ubuntu22.04 | ||
githubToken: ${{ github.token }} | ||
install: | | ||
apt-get update | ||
apt-get install -y --no-install-recommends python3 python3-pip | ||
pip3 install -U pip pytest | ||
run: | | ||
set -e | ||
pip3 install context-py --find-links dist --force-reinstall | ||
cd ./context-py && pytest | ||
|
||
macos: | ||
runs-on: ${{ matrix.platform.runner }} | ||
strategy: | ||
matrix: | ||
platform: | ||
- runner: macos-latest | ||
target: x86_64 | ||
- runner: macos-14 | ||
target: aarch64 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.10" | ||
- name: Build wheels | ||
uses: PyO3/maturin-action@v1 | ||
with: | ||
target: ${{ matrix.platform.target }} | ||
args: --release --out dist --find-interpreter --manifest-path ./context-py/Cargo.toml | ||
sccache: "true" | ||
- name: Upload wheels | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: wheels-macos-${{ matrix.platform.target }} | ||
path: dist | ||
|
||
sdist: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Build sdist | ||
uses: PyO3/maturin-action@v1 | ||
with: | ||
command: sdist | ||
args: --out dist --manifest-path ./context-py/Cargo.toml | ||
- name: Upload sdist | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: wheels-sdist | ||
path: dist |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[bandit] | ||
exclude = tests | ||
Comment on lines
+1
to
+2
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[settings] | ||
profile=black |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Generic, formatter-friendly config. | ||
select = ["B", "D3", "E", "F"] | ||
|
||
# Never enforce `E501` (line length violations). This should be handled by formatters. | ||
ignore = ["E501"] |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. upgraded to support python linters and formatters |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,34 +7,38 @@ cli: | |
plugins: | ||
sources: | ||
- id: trunk | ||
ref: v1.6.0 | ||
ref: v1.6.3 | ||
uri: https://github.com/trunk-io/plugins | ||
# Many linters and tools depend on runtimes - configure them here. (https://docs.trunk.io/runtimes) | ||
runtimes: | ||
enabled: | ||
- node@18.12.1 | ||
- python@3.10.8 | ||
- rust@1.71.1 | ||
# This is the section where you manage your linters. (https://docs.trunk.io/check/configuration) | ||
lint: | ||
enabled: | ||
- osv-scanner@1.8.1 | ||
- actionlint@1.7.1 | ||
- checkov@3.2.164 | ||
- clippy@1.75.0 | ||
- actionlint@1.7.3 | ||
- bandit@1.7.10 | ||
- black@24.8.0 | ||
- checkov@3.2.256 | ||
- clippy@1.71.1 | ||
- git-diff-check | ||
- markdownlint@0.41.0 | ||
- prettier@3.3.2 | ||
- rustfmt@1.75.0 | ||
- taplo@0.8.1 | ||
- trivy@0.52.2 | ||
- trufflehog@3.79.0 | ||
- isort@5.13.2 | ||
- markdownlint@0.42.0 | ||
- nixpkgs-fmt@1.3.0 | ||
- osv-scanner@1.9.0 | ||
- prettier@3.3.3 | ||
- ruff@0.6.8 | ||
- rustfmt@1.71.1 | ||
- taplo@0.9.3 | ||
- trufflehog@3.82.6 | ||
- yamllint@1.35.1 | ||
actions: | ||
disabled: | ||
enabled: | ||
- trunk-announce | ||
- trunk-check-pre-push | ||
- trunk-fmt-pre-commit | ||
enabled: | ||
- trunk-upgrade-available | ||
Comment on lines
-33
to
42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we want to use these |
||
tools: | ||
enabled: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__pycache__ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
def test_env_parse_and_validate(): | ||
from context_py import CIPlatform, EnvValidationLevel, env_parse, env_validate | ||
|
||
env_vars = { | ||
"GITHUB_ACTIONS": "true", | ||
"GITHUB_REF": "abc", | ||
"GITHUB_ACTOR": "Spikey", | ||
"GITHUB_REPOSITORY": "analytics-cli", | ||
"GITHUB_RUN_ID": "12345", | ||
} | ||
|
||
ci_info = env_parse(env_vars) | ||
env_validation = env_validate(ci_info) | ||
|
||
assert ci_info.platform == CIPlatform.GitHubActions | ||
assert env_validation.max_level() == EnvValidationLevel.SubOptimal | ||
assert [issue.error_message for issue in env_validation.issues_flat()] == [ | ||
"CI info author email too short", | ||
"CI info author name too short", | ||
"CI info commit message too short", | ||
"CI info committer email too short", | ||
"CI info committer name too short", | ||
"CI info title too short", | ||
], "\n" + "\n".join([issue.error_message for issue in env_validation.issues_flat()]) | ||
|
||
|
||
def test_junit_parse_and_validate(): | ||
import datetime | ||
|
||
from context_py import JunitValidationLevel, junit_parse, junit_validate | ||
|
||
timestamp = datetime.datetime.now().astimezone(datetime.timezone.utc).isoformat() | ||
junit_xml = f""" | ||
<testsuites name="my-test-run" tests="1" failures="1" errors="0"> | ||
<testsuite name="my-test-suite" tests="1" disabled="0" errors="0" failures="1" timestamp="{timestamp}"> | ||
<testcase name="failure-case" file="test.py" classname="MyClass" timestamp="{timestamp}" time="1"> | ||
<failure/> | ||
</testcase> | ||
</testsuite> | ||
</testsuites> | ||
""" | ||
|
||
report = junit_parse(str.encode(junit_xml)) | ||
junit_report_validation = junit_validate(report[0]) | ||
|
||
assert ( | ||
junit_report_validation.max_level() == JunitValidationLevel.Valid | ||
), "\n" + "\n".join( | ||
[ | ||
issue.error_message | ||
for test_suite in junit_report_validation.test_suites_owned() | ||
for test_case in test_suite.test_cases_owned() | ||
for issue in test_case.issues_flat() | ||
] | ||
) | ||
|
||
|
||
def test_repo_validate(): | ||
import math | ||
import time | ||
|
||
from context_py import BundleRepo, RepoUrlParts, RepoValidationLevel, repo_validate | ||
|
||
repo = RepoUrlParts("github", "trunk-io", "analytics-cli") | ||
bundle_repo = BundleRepo( | ||
repo, | ||
".", | ||
"https://github.com/trunk-io/analytics-cli", | ||
"abc", | ||
"main", | ||
math.floor(time.time()), | ||
"commit", | ||
"Spikey", | ||
"spikey@trunk.io", | ||
) | ||
|
||
repo_validation = repo_validate(bundle_repo) | ||
|
||
assert repo_validation.max_level() == RepoValidationLevel.Valid, "\n" + "\n".join( | ||
[issue.error_message for issue in repo_validation.issues_flat()] | ||
) |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file is not used by |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.