Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 38 additions & 23 deletions .github/workflows/build_and_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,47 @@ name: Publish Python 🐍 distributions 📦 to PyPI
on:
push:
tags:
- '*'
- '*'

jobs:
build-n-publish:
name: Build and publish Python 🐍 distributions 📦 to PyPI
runs-on: ubuntu-latest

# Required for PyPI Trusted Publishing (OIDC). No API token or
# password is stored in this repository. The token is minted on
# demand by GitHub and verified by PyPI against the trusted
# publisher configuration for this project.
permissions:
id-token: write

steps:
- uses: actions/checkout@master
- name: Set up Python 3.12
uses: actions/setup-python@v3
with:
python-version: '3.12'
- name: Install pypa/setuptools
run: >-
python -m
pip install setuptools wheel
- name: Extract tag name
id: tag
run: echo ::set-output name=TAG_NAME::$(echo $GITHUB_REF | cut -d / -f 3)
- name: Update version in setup.py
run: >-
sed -i "s/{{VERSION_PLACEHOLDER}}/${{ steps.tag.outputs.TAG_NAME }}/g" setup.py
- name: Build a binary wheel
run: >-
python setup.py sdist bdist_wheel
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.PYPI_API_TOKEN }}
- uses: actions/checkout@v4

- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Install build tooling
run: python -m pip install --upgrade pip build

- name: Verify that the tag matches the package version
run: |
TAG_NAME="${GITHUB_REF_NAME#v}"
PACKAGE_VERSION=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])")
echo "Tag: $TAG_NAME"
echo "Package version: $PACKAGE_VERSION"
if [ "$TAG_NAME" != "$PACKAGE_VERSION" ]; then
echo "::error::Tag '${GITHUB_REF_NAME}' does not match the version '${PACKAGE_VERSION}' in pyproject.toml."
exit 1
fi

- name: Build a binary wheel and source distribution
run: python -m build

# Publishes via PyPI Trusted Publishing (OIDC). The distribution
# is attested (PEP 740) and the provenance is shown on PyPI under
# the "Provenance" information for the release files.
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
46 changes: 46 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Tests ✅

on:
push:
branches: [main]
pull_request:

jobs:
test:
name: Run tests (Python ${{ matrix.python-version }}, ${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: ['3.10', '3.11', '3.12']
include:
# Python 3.8/3.9 are not available in the ubuntu-latest (24.04)
# toolcache, so they run on ubuntu-22.04 instead.
- os: ubuntu-22.04
python-version: '3.8'
- os: ubuntu-22.04
python-version: '3.9'
- os: windows-latest
python-version: '3.12'
- os: macos-latest
python-version: '3.12'

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
# The test suite imports codesafe from the repository root, so the
# package itself does not need to be built; only its runtime
# dependencies are required.
run: |
python -m pip install --upgrade pip
python -m pip install "cryptography>=41" "cloudpickle>=2.2"

- name: Run test suite
run: python -m unittest test.py test_poc_vulnerability.py -v
14 changes: 13 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,16 @@ __pycache__
*.pyc
dist/
build/
venv/
venv/
*.egg-info/
.eggs/
htmlcov/
.pytest_cache/
.coverage
venv/
.venv/
encrypted_code.encrypt
decrypted.py
codesafe_rce_marker.txt
pathlib_test.txt
v2_test_prog.encrypt
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Thank you for considering contributing to **CodeSafe**! Contributions, whether t
Create a fork of this repository to your GitHub account and clone it locally.

2. **Set Up the Environment**
Ensure you have Python 3.6+ installed. You should also install compatible versions of the necessary dependencies for the project.
Ensure you have Python 3.8+ installed. You should also install compatible versions of the necessary dependencies for the project.

3. **Run Tests**
Before making changes, run tests to confirm that everything works.
Expand Down
Loading
Loading