Skip to content

Commit

Permalink
chore: new cis
Browse files Browse the repository at this point in the history
* chore: new cis

* chore: venv

* fix: case sensitive cargo.toml

* fix: ci

* fix: ci

* fix: ci

* fix: ci
  • Loading branch information
nohehf authored May 13, 2024
1 parent a762763 commit e220fed
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 42 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -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
64 changes: 24 additions & 40 deletions .github/workflows/CI.yml → .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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 }}
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
43 changes: 43 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)"

0 comments on commit e220fed

Please sign in to comment.