Skip to content

Commit

Permalink
Merge branch 'main' of github.com:zapatacomputing/orquestra-vqa into …
Browse files Browse the repository at this point in the history
…zqs-1011-2
  • Loading branch information
AthenaCaesura committed May 12, 2022
2 parents e4364f9 + 11ee12e commit 6db1709
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 45 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/publish_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# This workflow can be trigerred manually.

# Don't extend this workflow. If any more steps are needed please extend the
# "publish-release" action in "z_quantum_actions". Allows reusing between repos.
name: publish-release

on:
workflow_dispatch:

jobs:
publish-release:
runs-on: ubuntu-latest

steps:
# Needed to get access to publish-release action definition
- name: Check out the released repo
uses: actions/checkout@v2
with:
# Fetch whole repo to get access to tags to read current package
# version.
fetch-depth: 0

# ------------------------------------------------------------------------
# Loads private SSH key to the SSH agent. Allows to install dependencies
# from private git repos, but requires setting `secrets.SSH_PRIVATE_KEY`
# in repo settings.
# ------------------------------------------------------------------------
- uses: ./subtrees/z_quantum_actions/actions/ssh_setup
with:
ssh_key: ${{ secrets.SSH_PRIVATE_KEY }}

- name: Get orquestra-quantum
uses: actions/checkout@v2
with:
repository: zapatacomputing/orquestra-quantum
path: orquestra-quantum
ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}

- name: Get orquestra-opt
uses: actions/checkout@v2
with:
repository: zapatacomputing/orquestra-opt
path: orquestra-opt
ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}


- name: Run publish release action
uses: ./subtrees/z_quantum_actions/actions/publish-release
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
include subtrees/z_quantum_actions/Makefile

github_actions:
python3 -m venv ${VENV} && \
${VENV}/bin/python3 -m pip install --upgrade pip && \
${VENV}/bin/python3 -m pip install ./orquestra-quantum && \
${VENV}/bin/python3 -m pip install ./orquestra-opt && \
${VENV}/bin/python3 -m pip install -e '.[dev]'
python3 -m venv ${VENV_NAME} && \
${VENV_NAME}/bin/python3 -m pip install --upgrade pip && \
${VENV_NAME}/bin/python3 -m pip install ./orquestra-quantum && \
${VENV_NAME}/bin/python3 -m pip install ./orquestra-opt && \
${VENV_NAME}/bin/python3 -m pip install -e '.[dev]'
23 changes: 18 additions & 5 deletions subtrees/z_quantum_actions/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ default:
| sed -r 's/-default//g; /default/d ; s/(.*)/\t make \1/g ; s/:.*$$//g'


export VENV := venv
PYTHON := $(shell PATH="venv/bin:${PATH}" python3 -c 'import sys; print(sys.executable)')
export VENV_NAME := my_little_venv
PYTHON := $(shell PATH="${VENV_NAME}/bin:${PATH}" python3 -c 'import sys; print(sys.executable)')
REPO := $(shell git config --get remote.origin.url)
PYTHON_MOD := $(shell find src -maxdepth 3 -mindepth 3 -type d | sed '/.*cache/d; s/src\/python\/// ; s/\//./')
PACKAGE_NAME := "foo"

ifeq ($(PYTHON),)
$(error "PYTHON=$(PYTHON)")
Expand Down Expand Up @@ -48,10 +49,19 @@ install-default: clean
dev-default: clean
$(PYTHON) -m pip install -e .[dev]

# Why we want to use `python3` and not `$(PYTHON)` here.
# In order to enable running make commands both from CICD and locally
# we need to use virtualenv when running on GitHub Actions, as otherwise
# we might get into rare and hard to debug edge cases (as we did in the past).
# After this action is executed $(PYTHON) will get resolved to the Python version
# from virtual environment.
# This make task is used to create new virtual environment so we want to use
# `python3` here as it's more explicit, because $(PYTHON) would evaluate to
# something else after executing this task, which might be confusing.
github_actions-default:
python3 -m venv ${VENV} && \
${VENV}/bin/python3 -m pip install --upgrade pip && \
${VENV}/bin/python3 -m pip install -e '.[dev]'
python3 -m venv ${VENV_NAME} && \
${VENV_NAME}/bin/python3 -m pip install --upgrade pip && \
${VENV_NAME}/bin/python3 -m pip install -e '.[dev]'

flake8-default: clean
$(PYTHON) -m flake8 --ignore=E203,E266,F401,W503 --max-line-length=88 src tests
Expand Down Expand Up @@ -87,6 +97,9 @@ muster-default: style coverage
build-system-deps-default:
:

get-next-version-default: github_actions
${VENV_NAME}/bin/python3 subtrees/z_quantum_actions/bin/get_next_version.py $(PACKAGE_NAME)

# This is what converts the -default targets into base target names.
# Do not remove!!!
%: %-default
Expand Down
7 changes: 5 additions & 2 deletions subtrees/z_quantum_actions/actions/publish-release/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ runs:
- name: Get next version
id: get-next-version
shell: bash
# Inputs: none
# Note: We assume library name is the same as repository name
# Outputs: `next_version` - a bumped semver string of form "major.minor.patch"
run: python3 subtrees/z_quantum_actions/bin/get_next_version.py
run: make get-next-version PACKAGE_NAME="${{ github.event.repository.name }}"
# This is needed if we work on the private repositories, doesn't bother us otherwise though
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock

- name: Push new version tag
id: push-new-version-tag
Expand Down
15 changes: 6 additions & 9 deletions subtrees/z_quantum_actions/bin/get_next_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
# Reads current project version, bumps "minor", and sets the "next_version" output
# variable using Github's special stdout syntax.


import sys
import re
import subprocess
import typing as t
from importlib.metadata import version


class Semver(t.NamedTuple):
Expand Down Expand Up @@ -39,10 +39,6 @@ def bump_minor(self):
)


def _read_current_version() -> str:
return subprocess.check_output(["python3", "setup.py", "--version"]).decode()


SEMVER_REGEX = (
r"(?P<major>[0-9]+)\.(?P<minor>[0-9]+)(\.(?P<patch>[0-9]+))?([-\.](?P<pre>.+))?"
)
Expand Down Expand Up @@ -77,15 +73,15 @@ def _set_github_output(name: str, value):
print(f"::set-output name={name}::{value}")


def main():
def main(package_name):
"""Run the actual script logic.
Args:
version_verride: should contain Github Action input. Empty strings are treated
as "nil" values. This is because that's how bash passes nils.
"""

current_version = _read_current_version()
current_version = version(package_name)
print(f"Read current version as: {current_version}")

next_version = parse_version_str(current_version).bump_minor.version_str
Expand All @@ -95,4 +91,5 @@ def main():


if __name__ == "__main__":
main()
package_name = sys.argv[1]
main(package_name=package_name)
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ on:
workflow_dispatch:

jobs:
run-action:
publish-release:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
Expand Down

This file was deleted.

0 comments on commit 6db1709

Please sign in to comment.