Skip to content

Commit

Permalink
Merge pull request #107 from CasperWA/test_release
Browse files Browse the repository at this point in the history
Automatically publish version tags to PyPI via GH Actions
  • Loading branch information
CasperWA committed Dec 11, 2019
2 parents c369b8c + a7085f5 commit 160951a
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 21 deletions.
24 changes: 24 additions & 0 deletions .ci/assert_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import os

try:
from optimade import __version__
except ImportError:
raise ImportError(
"optimade needs to be installed prior to running 'assert_version.py'"
)

package_version = f"v{__version__}"

tag_version = os.getenv("TAG_VERSION")
tag_version = tag_version[len("refs/tags/") :]

if tag_version == package_version:
print(f"The versions match: tag:'{tag_version}' == package:'{package_version}'")
exit(0)

print(
f"""The current package version '{package_version}' does not equal the tag version '{tag_version}'.
Update package version by \"invoke setver --new-ver='{tag_version[1:]}'\" and re-commit.
Please remove the tag from both GitHub and your local repository and try again!"""
)
exit(1)
4 changes: 2 additions & 2 deletions .ci/json_diff.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
diff=$(jsondiff openapi.json local_openapi.json);

if [ ! "$diff" = "{}" ]; then
echo -e "Generated OpenAPI spec did not match committed version. Diff:\n$diff";
if [ ! "$diff" = "{}" ]; then
echo -e "Generated OpenAPI spec did not match committed version.\nRun 'invoke update_openapijson' and re-commit.\nDiff:\n$diff";
exit 1;
fi
6 changes: 3 additions & 3 deletions .github/workflows/deps_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ jobs:
steps:
- uses: actions/checkout@v1

- name: Set up Python ${{ matrix.python-version }}
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
Expand Down Expand Up @@ -129,7 +129,7 @@ jobs:
steps:
- uses: actions/checkout@v1

- name: Set up Python ${{ matrix.python-version }}
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
Expand Down Expand Up @@ -157,7 +157,7 @@ jobs:
# steps:
# - uses: actions/checkout@v1

# - name: Set up Python ${{ matrix.python-version }}
# - name: Set up Python ${{ matrix.python-version }}
# uses: actions/setup-python@v1
# with:
# python-version: ${{ matrix.python-version }}
Expand Down
49 changes: 49 additions & 0 deletions .github/workflows/publish-on-pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Publish on PyPI

on:
push:
tags:
# After vMajor.Minor.Patch _anything_ is allowed (without "/") !
- v[0-9]+.[0-9]+.[0-9]+*

jobs:
publish:
runs-on: ubuntu-latest
if: github.repository == 'Materials-Consortia/optimade-python-tools' && startsWith(github.ref, 'refs/tags/v')

steps:
- name: Checkout repository
uses: actions/checkout@v1

- name: Set up Python 3.7
uses: actions/setup-python@v1
with:
python-version: 3.7

- name: Upgrade setuptools and install package
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade setuptools
python -m pip install -e .
- name: Assert package version
env:
TAG_VERSION: ${{ github.ref }}
run: python ./.ci/assert_version.py

- name: Build source distribution
run: python ./setup.py sdist

# This tests that publication to PyPI is possible, before properly publishing
- name: Publish package to TestPyPI
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.test_pypi_password }}
repository_url: https://test.pypi.org/legacy/

- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.pypi_password }}
18 changes: 12 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
repos:
- repo: https://github.com/ambv/black
rev: stable
hooks:
- id: black
default_language_version:
python: python3.7
- repo: https://github.com/ambv/black
rev: stable
hooks:
- id: black

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: trailing-whitespace
exclude: README.md
- id: check-yaml
- id: check-json
2 changes: 1 addition & 1 deletion optimade/grammar/v0.10.0.elastic.lark
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// optimade v0.10.0 grammar spec in lark grammar format,
// optimade v0.10.0 grammar spec in lark grammar format,
// written to work with the elasticsearch filtertransformer

start: or_expr
Expand Down
4 changes: 2 additions & 2 deletions optimade/grammar/v0.9.6.lark
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

start: KEYWORD expression
KEYWORD: "filter=" | "filter ="
expression: [expression CONJUNCTION] term
expression: [expression CONJUNCTION] term
term: [term CONJUNCTION] atom | "(" [term CONJUNCTION] term

atom: [NOT] comparison
atom: [NOT] comparison

comparison: VALUE OPERATOR VALUE [")"] | VALUE OPERATOR "'" (combined)* "'"
OPERATOR: /<=?|>=?|!?=/
Expand Down
2 changes: 1 addition & 1 deletion optimade/grammar/v0.9.7.lark
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ start: expression
expression: [expression CONJUNCTION] term
term: [term CONJUNCTION] atom | "(" [term CONJUNCTION] term ")"

atom: [NOT] comparison
atom: [NOT] comparison

comparison: VALUE OPERATOR VALUE | VALUE OPERATOR "'" combined "'"

Expand Down
7 changes: 3 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import os

from pathlib import Path
from setuptools import setup, find_packages

module_dir = os.path.dirname(os.path.abspath(__file__))
module_dir = Path(__file__).resolve().parent

# Dependencies
mongo_deps = ["pymongo~=3.8", "mongomock~=3.16"]
Expand All @@ -27,7 +26,7 @@
author="OPTiMaDe Development Team",
author_email="dev@optimade.org",
description="Tools for implementing and consuming OPTiMaDe APIs.",
long_description=open(os.path.join(module_dir, "README.md")).read(),
long_description=open(module_dir.joinpath("README.md")).read(),
long_description_content_type="text/markdown",
keywords="optimade jsonapi materials",
include_package_data=True,
Expand Down
8 changes: 6 additions & 2 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@


@task
def setver(c, patch=False, new_ver=""):
def setver(_, patch=False, new_ver=""):
if (not patch and not new_ver) or (patch and new_ver):
raise Exception("Either use --patch or specify e.g. --full='x.y.z.")
raise Exception(
"Either use --patch or specify e.g. --new-ver='Major.Minor.Patch(a|b|rc)?[0-9]+'"
)
if patch:
v = [int(x) for x in __version__.split(".")]
v[2] += 1
Expand All @@ -20,6 +22,7 @@ def setver(c, patch=False, new_ver=""):
]
with open("optimade/__init__.py", "w") as f:
f.write("\n".join(lines))
f.write("\n")

with open("setup.py", "r") as f:
lines = [
Expand All @@ -28,6 +31,7 @@ def setver(c, patch=False, new_ver=""):
]
with open("setup.py", "w") as f:
f.write("\n".join(lines))
f.write("\n")
print("Bumped version to {}".format(new_ver))


Expand Down

0 comments on commit 160951a

Please sign in to comment.