diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..73eeb70 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,43 @@ +name: CI + +on: + push: + branches: + - main + pull_request: + branches: + - main + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + run-tests: + name: Run Tests + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install python + uses: actions/setup-python@v2 + with: + python-version: "3.11.9" + + - name: Setup venv + run: python -m venv .venv + + - name: Install Python dependencies + run: | + python -m pip install --upgrade pip + python -m pip install maturin + + - name: Run tests + run: | + . .venv/bin/activate + maturin develop + which python + which maturin + python tests/test.py diff --git a/.github/workflows/CI.yml b/.github/workflows/release.yaml similarity index 68% rename from .github/workflows/CI.yml rename to .github/workflows/release.yaml index 4187cfa..b40e95a 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/release.yaml @@ -1,15 +1,12 @@ # This file is abased on the autogenerated file by maturin v1.5.1 # It is modified to remove some architectures that were failing to build -name: CI +# Build and release the package to PyPI +name: Release on: push: - branches: - - main - - master tags: - '*' - pull_request: workflow_dispatch: concurrency: @@ -20,38 +17,19 @@ permissions: contents: read jobs: - # from https://github.com/astral-sh/ruff/blob/main/.github/workflows/release.yaml validate-tag: - name: Validate tag - runs-on: ubuntu-latest - # If you don't set an input tag, it's a dry run (no uploads). - if: ${{ inputs.tag }} - steps: - - uses: actions/checkout@v4 - with: - ref: main # We checkout the main branch to check for the commit - - name: Check main branch - if: ${{ inputs.sha }} - run: | - # Fetch the main branch since a shallow checkout is used by default - git fetch origin main --unshallow - if ! git branch --contains ${{ inputs.sha }} | grep -E '(^|\s)main$'; then - echo "The specified sha is not on the main branch" >&2 - exit 1 - fi - - name: Check tag consistency - run: | - # Switch to the commit we want to release - git checkout ${{ inputs.sha }} - version=$(grep "version = " pyproject.toml | sed -e 's/version = "\(.*\)"/\1/g') - if [ "${{ inputs.tag }}" != "${version}" ]; then - echo "The input tag does not match the version from pyproject.toml:" >&2 - echo "${{ inputs.tag }}" >&2 - echo "${version}" >&2 - exit 1 - else - echo "Releasing ${version}" - fi + name: Validate tag + runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/') + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # Ensure all history and tags are fetched + - name: Set up environment + run: echo "TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV + - name: Validate tags with Makefile + run: make validate-tags + linux: runs-on: ${{ matrix.platform.runner }} strategy: @@ -150,13 +128,11 @@ jobs: with: name: wheels-sdist path: dist - + release: name: Release runs-on: ubuntu-latest - # if: "startsWith(github.ref, 'refs/tags/')" - # TODO(@nohehf): Re add validate-tag dependency - needs: [linux, windows, macos, sdist] + needs: [linux, windows, macos, sdist, validate-tag] steps: - uses: actions/download-artifact@v4 - name: Publish to PyPI @@ -166,3 +142,11 @@ jobs: with: command: upload args: --non-interactive --skip-existing wheels-*/* + - name: Create GitHub Release + uses: softprops/action-gh-release@v1 + if: success() + with: + files: | + wheels-*/* + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/Cargo.lock b/Cargo.lock index 9eb0599..35b36f0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1233,7 +1233,7 @@ dependencies = [ [[package]] name = "stack-graphs-python-bindings" -version = "0.1.0" +version = "0.0.5" dependencies = [ "pyo3", "stack-graphs", diff --git a/Cargo.toml b/Cargo.toml index 6fdbcfa..a2585d9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "stack-graphs-python-bindings" -version = "0.1.0" +version = "0.0.5" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/Makefile b/Makefile index 686ece7..a2b9adc 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,9 @@ +.PHONY: setup +setup: + pyenv virtualenvs | grep stack-graphs-python-bindings || pyenv virtualenv 3.11.9 stack-graphs-python-bindings + pyenv activate stack-graphs-python-bindings + pip install maturin + .PHONY: develop develop: maturin develop @@ -6,3 +12,40 @@ develop: test: develop ## TODO: Add actual tests with pytest python tests/test.py + +.PHONY: validate-tags release + +VERSION_PY := $(shell grep 'version = ' pyproject.toml | sed -e 's/version = "\(.*\)"/\1/') +VERSION_RS := $(shell grep 'version =' Cargo.toml | sed -n 's/^version = "\(.*\)"/\1/p') + +# Usage: make validate-tags TAG=1.0.0 +validate-tag: + @if [ -z "$(TAG)" ]; then \ + echo "Error: No TAG specified. Usage: make validate-tags TAG=1.0.0"; \ + exit 1; \ + fi + @if [ "$(TAG)" != "$(VERSION_PY)" ]; then \ + echo "Tag $(TAG) does not match version in pyproject.toml $(VERSION_PY)"; \ + exit 1; \ + fi + @if [ "$(TAG)" != "$(VERSION_RS)" ]; then \ + echo "Tag $(TAG) does not match version in cargo.toml $(VERSION_RS)"; \ + exit 1; \ + fi + @echo "Tag $(TAG) is valid and matches version in both files." + +# Usage: make release TAG=1.0.0 +release: validate-tag + $(eval CURRENT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)) + @if [ "$(CURRENT_BRANCH)" != "main" ]; then \ + echo "Release can only be performed from the main branch. Current branch is $(CURRENT_BRANCH)."; \ + exit 1; \ + fi + $(eval LATEST_TAG := $(shell git describe --tags --abbrev=0)) + @if [ "$(LATEST_TAG)" = "$(VERSION_PY)" ]; then \ + echo "No version bump detected. Current version $(VERSION_PY) matches the latest tag $(LATEST_TAG)."; \ + exit 1; \ + fi + git tag $(VERSION_PY) + git push origin $(VERSION_PY) + @echo "Released new version $(VERSION_PY)"