Skip to content

Commit

Permalink
Merge pull request #740 from vsbogd/automate-release
Browse files Browse the repository at this point in the history
Add Dockerhub publishing step to the release GitHub Action workflow
  • Loading branch information
vsbogd authored Jul 12, 2024
2 parents 529c000 + e4d8f2b commit 5f85d87
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# This workflow builds Python distribution packages using cibuildwheel tool and
# environment and publishes packages as a part of a GitHub release.
# environment and publishes packages as a part of a GitHub release. Also it
# releases container image to the DockerHub.

# This workflow uses actions that are not certified by GitHub. They are
# provided by a third-party and are governed by separate terms of service,
# privacy policy, and support documentation.

name: release python
name: release

on:
workflow_dispatch:
release:
types: [published]


jobs:
build-wheels:
name: Build wheels on ${{ matrix.os }}
Expand Down Expand Up @@ -77,35 +77,79 @@ jobs:
permissions:
id-token: write
environment:
name: test
name: pypi-test
runs-on: ubuntu-latest
needs: [build-wheels]
if: github.event.action == 'published'
steps:
- uses: actions/download-artifact@v4
with:
pattern: python-wheels-*
merge-multiple: true
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/

- uses: actions/download-artifact@v4
with:
pattern: python-wheels-*
merge-multiple: true
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
name: pypi-production
runs-on: ubuntu-latest
needs: [build-wheels]
if: github.event.action == 'published'
steps:

- uses: actions/download-artifact@v4
with:
pattern: python-wheels-*
merge-multiple: true
path: dist

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

publish-docker:
name: Publish Docker image
environment:
name: dockerhub-production
runs-on: ubuntu-latest
needs: [build-wheels]
if: github.event.action == 'published'
steps:
- uses: actions/download-artifact@v4
with:
pattern: python-wheels-*
merge-multiple: true
path: dist
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

- name: Set up Docker BuildX
uses: docker/setup-buildx-action@v3

- name: Build and export to Docker
uses: docker/build-push-action@v6
with:
load: true
build-args: |
BUILDKIT_CONTEXT_KEEP_GIT_DIR=1
tags: trueagi/hyperon:test

- name: Test
run: |
echo "(* 7 6)" | docker run --rm trueagi/hyperon:test metta-repl
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v6
with:
push: true
build-args: |
BUILDKIT_CONTEXT_KEEP_GIT_DIR=1
tags: |
trueagi/hyperon:${{github.event.release.tag_name}}
trueagi/hyperon:latest
11 changes: 8 additions & 3 deletions repl/src/metta_shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ pub mod metta_interface_mod {
}

pub fn confirm_hyperonpy_version(req_str: &str) -> Result<(), String> {

let req = parse_version_specifiers(req_str).unwrap();
let version_string = get_hyperonpy_version()?;
//NOTE: Version parsing errors will be encountered by users building hyperonpy from source with an abnormal configuration
Expand All @@ -78,7 +77,8 @@ pub mod metta_interface_mod {

match || -> Result<_, String> {
//Confirm the hyperonpy version is compatible
confirm_hyperonpy_version(">=0.1.0, <0.2.0")?;
let req_str = Self::required_hyperon_version();
confirm_hyperonpy_version(&req_str)?;

//Initialize the Hyperon environment
let new_shim = MettaShim::init_common_env(working_dir, include_paths)?;
Expand All @@ -93,6 +93,11 @@ pub mod metta_interface_mod {
}
}

fn required_hyperon_version() -> String {
const PACKAGE_VERSION: &str = env!("CARGO_PKG_VERSION");
format!("=={PACKAGE_VERSION}")
}

pub fn init_common_env(working_dir: PathBuf, include_paths: Vec<PathBuf>) -> Result<MettaShim, String> {
match Python::with_gil(|py| -> PyResult<(Py<PyModule>, Py<PyAny>)> {
let py_mod = PyModule::from_code(py, Self::PY_CODE, "", "")?;
Expand Down Expand Up @@ -470,4 +475,4 @@ pub fn strip_quotes(src: &str) -> &str {
}
}
src
}
}

0 comments on commit 5f85d87

Please sign in to comment.