Skip to content

Commit

Permalink
Fetch version, pip install in workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
RajivChitale committed Feb 25, 2024
1 parent 7435853 commit dd93928
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 2 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/upload_pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Upload to PyPI

on:
release:
types:
- published
push:
branches:
- pip-package # or
workflow_dispatch:
inputs:
pypi_repo:
description: 'Repo to upload to (testpypi or pypi)'
default: 'testpypi'
required: true
type: choice
options:
- testpypi
- pypi

jobs:
build_wheels:
uses: ./.github/workflows/wheel.yml

upload_pypi:
permissions:
id-token: write
needs: [build_wheels]
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v3
with:
name: artifact
path: $GITHUB_WORKSPACE/CompilerInterface/dist

- name: Publish package to TestPyPI
uses: pypa/[email protected]
with:
repository-url: https://test.pypi.org/
if: ${{ github.event.inputs.pypi_repo != 'pypi' }}

# - name: Publish package to PyPI
# uses: pypa/[email protected]
# with:
# repository-url: https://upload.pypi.org/legacy/
# if: ${{ github.event.inputs.pypi_repo == 'pypi' }}
29 changes: 29 additions & 0 deletions .github/workflows/wheel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Build wheels

on: [push, workflow_dispatch, workflow_call]

jobs:
build_wheels:
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-20.04]

steps:
- uses: actions/checkout@v3

- name: Build wheels
run: |
cd $GITHUB_WORKSPACE/CompilerInterface
python fetch_version.py
cp ../README.md ./
pip wheel . -w ./dist
pip install dist/cinter*.whl
- uses: actions/upload-artifact@v3
with:
path: $GITHUB_WORKSPACE/CompilerInterface/dist/*.whl

- name: List files in dist directory
run: ls -l $GITHUB_WORKSPACE/CompilerInterface/dist
27 changes: 27 additions & 0 deletions CompilerInterface/fetch_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import subprocess as sp
import pathlib as pl
import re

version_regex = re.compile(r"^project\(MLCompilerBridge VERSION (?P<version>[^)]+)\)$")
toml_field_regex = r'version[ ]*=[ ]*"(.*)"'

VERSION = ""
with open("../CMakeLists.txt", "r") as f:
for line in f:
vmatch = version_regex.match(line) # Not using walrus because Python3.6
if vmatch:
VERSION = vmatch.group("version")
break

print("Version detected =", VERSION)
lines = []
with open("./pyproject.toml", "r") as f:
lines = f.readlines()

with open("./pyproject.toml", "w") as f:
for line in lines:
if re.search(toml_field_regex, line):
new_text = f'version = "{VERSION}"\n'
f.write(new_text)
else:
f.write(line)
4 changes: 2 additions & 2 deletions CompilerInterface/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[project]
name = "compilerinterface"
name = "cinter"
version = "0.0.1"
authors = [ {name = "The authors of \"The Next 700 ML-Enabled Compiler Optimizations\"" }]
description = "Communication framework for ML-Enabled Compiler Optimizations."
license = { text= "Apache License v2.0 with LLVM Exceptions"}
readme = "../README.md"
readme = "README.md"
requires-python = ">=3.7"
classifiers = [
"Programming Language :: Python :: 3",
Expand Down

0 comments on commit dd93928

Please sign in to comment.