Skip to content
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

Automatic Python wheel building and publishing to PyPI #431

Merged
merged 34 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
87f4743
Read release tag
wenwei-dev Sep 4, 2023
7ee6f50
Fix step
wenwei-dev Sep 4, 2023
86336ce
Minor fix
wenwei-dev Sep 5, 2023
f81e2d7
Fix token name
wenwei-dev Sep 5, 2023
ad5abf7
Switch to dynamic version
wenwei-dev Sep 8, 2023
174da79
Add publish job
wenwei-dev Sep 8, 2023
c07071b
Testing
wenwei-dev Sep 8, 2023
8f170ec
Testing
wenwei-dev Sep 8, 2023
36d6b89
Remove publish condition
wenwei-dev Sep 8, 2023
990d8b5
Add readme
wenwei-dev Sep 8, 2023
e7b7ae3
Publish to test pypi
wenwei-dev Sep 8, 2023
7ed1136
Fix readme path
wenwei-dev Sep 8, 2023
06cec93
Revert "Switch to dynamic version"
wenwei-dev Sep 8, 2023
766263b
Merge branch 'trueagi-io:main' into main
wenwei-dev Sep 8, 2023
ec0b95d
Debugging
wenwei-dev Sep 12, 2023
54cfcab
Fix empty git ref when it is triggered by a release
wenwei-dev Sep 12, 2023
963ea39
Check out specific commit
wenwei-dev Sep 12, 2023
7c2b6af
Fix env var
wenwei-dev Sep 12, 2023
14dc0c5
Set commit head
wenwei-dev Sep 12, 2023
d8f5358
Try to share env var cross steps
wenwei-dev Sep 12, 2023
9157fa1
Fix unrecognized var
wenwei-dev Sep 12, 2023
eda8519
Fix unrecognized var
wenwei-dev Sep 12, 2023
9c042b7
Refine dependency
wenwei-dev Sep 12, 2023
fb75499
Fix uploading artifacts
wenwei-dev Sep 12, 2023
ace075f
Revert "Revert "Switch to dynamic version""
wenwei-dev Sep 12, 2023
0569e92
Revert workflow dep
wenwei-dev Sep 12, 2023
449394f
Set condition
wenwei-dev Sep 12, 2023
79d622f
Remove trigger inputs
wenwei-dev Sep 12, 2023
b237f06
Build full python versions
wenwei-dev Sep 12, 2023
9a30114
Update after PR review
wenwei-dev Sep 13, 2023
122ff6d
Merge branch 'main' into main
wenwei-dev Sep 13, 2023
93d7591
Opt out musllinux
wenwei-dev Sep 14, 2023
b9acf29
Configure trusted publisher
wenwei-dev Sep 14, 2023
a57cd68
Merge branch 'trueagi-io:main' into main
wenwei-dev Sep 14, 2023
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
85 changes: 58 additions & 27 deletions .github/workflows/release-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,9 @@ name: release python

on:
workflow_dispatch:
inputs:
release-tag:
description: 'GitHub release tag to publish packages'
required: false
type: string
prerelease:
description: 'Flag to create a pre-release'
default: true
required: false
type: boolean
release:
types: [published]


jobs:
build_wheels:
Expand All @@ -34,32 +27,70 @@ jobs:
- name: Checkout source code
uses: actions/checkout@v3

- name: Build wheels on Linux
if: runner.os == 'Linux'
uses: pypa/[email protected]
env:
# Linux cannot call "sh -c ./python/install-hyperonc.sh" because
# before-all command is also called with "sh -c"
CIBW_BEFORE_ALL: ./python/install-hyperonc.sh -u https://github.com/${{github.repository}}.git -r ${{github.ref}}
with:
package-dir: ./python
- run: |
echo "REF_NAME=${{github.ref_name}}" | tee -a $GITHUB_ENV
echo "EVENT_NAME=${{github.event_name}}" | tee -a $GITHUB_ENV
echo "PRERELEASE=${{github.event.release.prerelease}}" | tee -a $GITHUB_ENV
echo "TAG_NAME=${{github.event.release.tag_name}}" | tee -a $GITHUB_ENV
echo "COMMIT_HEAD=${{github.ref_name != '' && github.ref_name || env.GITHUB_SHA}}" | tee -a $GITHUB_ENV

- name: Build wheels on MacOSX
if: runner.os == 'macOS'
- name: Build wheels on ${{ matrix.os }}
uses: pypa/[email protected]
env:
# Mac OS X cannot call "./python/install-hyperonc.sh" probably because
# "/bin/sh" is not correct path for the shell there
CIBW_BEFORE_ALL: sh -c "./python/install-hyperonc.sh -u https://github.com/${{github.repository}}.git -r ${{github.ref}}"
CIBW_BEFORE_ALL: sh -c "./python/install-hyperonc.sh -u https://github.com/${{github.repository}}.git -r ${{env.COMMIT_HEAD}}"
CIBW_SKIP: "*musllinux*"
wenwei-dev marked this conversation as resolved.
Show resolved Hide resolved
with:
package-dir: ./python

- name: Publish artifacts on GitHub
- name: Publish Artifacts on GitHub Release
if: github.event.action == 'published'
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ./wheelhouse/*.whl
tag: ${{ inputs.release-tag }}
prerelease: ${{ inputs.prerelease }}
tag: ${{ github.ref }}
prerelease: ${{ github.event.release.prerelease }}
overwrite: true
file_glob: true

- name: Upload Artifacts
uses: actions/upload-artifact@v3
with:
name: python-wheels
path: ./wheelhouse/*.whl

publish-test-pypi:
name: Publish to Test PyPI
permissions:
id-token: write
environment:
name: test
runs-on: ubuntu-latest
needs: [build_wheels]
if: github.event.action == 'published'
steps:
- uses: actions/download-artifact@v3
with:
name: python-wheels
path: dist
- name: Publish package distributions to Test PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/

publish-pypi:
name: Publish to PyPI
permissions:
id-token: write
environment:
name: production
runs-on: ubuntu-latest
needs: [build_wheels]
if: github.event.action == 'published'
steps:
- uses: actions/download-artifact@v3
with:
name: python-wheels
path: dist
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
12 changes: 12 additions & 0 deletions python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Overview

OpenCog Hyperon is a substantially revised, novel version of OpenCog - which is currently at an active
pre-alpha stage of development and experimentation. One of the focuses in the Hyperon design is a successor
to the OpenCog Classic Atomese language with clear semantics supporting meta-language features,
different types of inference, etc. What we have landed on is an "Atomese 2" language called MeTTa (Meta Type Talk).

One can run MeTTa script from command line:

```
metta <name>.metta
```
2 changes: 1 addition & 1 deletion python/install-hyperonc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ mkdir -p ${HOME}/hyperonc
cd ${HOME}/hyperonc
git init
git remote add origin $HYPERONC_URL
git fetch origin $HYPERONC_REV
git fetch --depth=1 origin $HYPERONC_REV
git reset --hard FETCH_HEAD

mkdir -p ${HOME}/hyperonc/c/build
Expand Down
10 changes: 8 additions & 2 deletions python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[build-system]
requires = ["setuptools==65.6.3", "conan==1.60.2", "cmake==3.26.4"]
requires = ["setuptools==65.6.3", "conan==1.60.2", "cmake==3.26.4", "setuptools_scm[toml]>=6.2"]
build-backend = "setuptools.build_meta"

[project]
name = "hyperon"
version = "0.1.6"
description = "Hyperon API in Python"
readme = "README.md"
requires-python = ">=3.7"
keywords = ["metta", "hyperon", "opencog"]
license = {text = "MIT License"}
Expand All @@ -19,6 +19,7 @@ classifiers = [
dependencies = [
'importlib-metadata==6.6.0; python_version<"3.8"',
]
dynamic = ["version"]

[project.scripts]
metta = "hyperon.metta:main"
Expand All @@ -39,3 +40,8 @@ before-all = "sh -c ./python/install-hyperonc.sh"
skip = "*-musllinux_i686"
test-requires = ["pytest==7.3.2"]
test-command = "pytest {project}/python/tests"


[tool.setuptools_scm]
root = '..'