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

PR: Add CI workflow for package release on tag push #195

Merged
merged 5 commits into from
Dec 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
32 changes: 20 additions & 12 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
[bumpversion]
current_version = 5.0.8.dev
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(.(?P<suffix>.+))?
current_version = 5.0.9beta0
commit = True
message = Bump version: {current_version} → {new_version}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do the commit directly

tag = False
tag_name = {new_version}
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)((?P<release>[a-z]+)(?P<build>\d+))?
serialize =
{major}.{minor}.{patch}.{suffix}
{major}.{minor}.{patch}{release}{build}
{major}.{minor}.{patch}

[bumpversion:part:suffix]
optional_value = final
[bumpversion:part:release]
optional_value = prod
first_value = beta
values =
dev
final
beta
prod

[bumpversion:part:build]

[bumpversion:file:nbformat/_version.py]
parse = (?P<major>\d+),\s*(?P<minor>\d+),\s*(?P<patch>\d+)(,\s*['"](?P<suffix>\w+)['"])?
parse = (?P<major>\d+),\s*(?P<minor>\d+),\s*(?P<patch>\d+)(,\s*['"](?P<release>[a-z]+)(?P<build>\d+)['"])?
serialize =
{major}, {minor}, {patch}, '{suffix}'
{major}, {minor}, {patch}, '{release}{build}'
{major}, {minor}, {patch}

[bumpversion:file:docs/conf.py]
Expand All @@ -24,6 +31,7 @@ search = version = '{current_version}'
replace = version = '{new_version}'

[bumpversion:file:package.json]
parse = (?P<major>\d+).(?P<minor>\d+).(?P<patch>\d+)
serialize = {major}.{minor}.{patch}

parse = (?P<major>\d+).(?P<minor>\d+).(?P<patch>\d+)(-(?P<release>[a-z]+)\.(?P<build>\d+))?
serialize =
{major}.{minor}.{patch}-{release}.{build}
{major}.{minor}.{patch}
22 changes: 22 additions & 0 deletions .github/scripts/create_npmrc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python
# coding: utf-8

# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

# Standard library imports
import os


def create_npmrc():
"""
Create NPM configuration file in user home directory to use authentication
token from environment variables.
"""
fpath = os.path.expanduser("~/.npmrc")
with open(fpath, "w") as fh:
fh.write("//registry.npmjs.org/:_authToken=${NPM_TOKEN}")


if __name__ == "__main__":
create_npmrc()
38 changes: 38 additions & 0 deletions .github/scripts/parse_ref.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env python
# coding: utf-8

# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

# Standard library imports
import os
import subprocess

# Constants
HERE = os.path.abspath(os.path.dirname(__file__))
REPO_ROOT = os.path.dirname(os.path.dirname(HERE))


def parse_ref(current_ref):
"""
Extract version string from github reference string and create environment
variable for use within the CI workflows.

Parameters
----------
current_ref: str
The github reference string.
"""
if not current_ref.startswith("ref/tags/"):
raise Exception(f"Invalid ref `{current_ref}`!")

tag_name = current_ref.replace("ref/tags/", "")
if not tag_name.startswith("v"):
raise Exception(f"Invalid tag `{tag_name}`!")

print(f"::set-env name=RELEASE_TAG::{tag_name}")


if __name__ == "__main__":
current_ref = os.environ.get("GITHUB_REF")
parse_ref(current_ref)
49 changes: 49 additions & 0 deletions .github/workflows/release_publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Create Release and publish package

on:
push:
tags:
- '**'

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: '3.8'
- name: Install dependencies
run: |
pip install --upgrade pip setuptools
pip install bump2version check-manifest twine wheel
- name: Build release
run: |
check-manifest -v
python setup.py sdist bdist_wheel
python -m twine check dist/*
- name: Parse tag
run: python .github/scripts/parse_ref.py
- name: Create Release
id: create_release
uses: ncipollo/release-action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag: ${{ env.RELEASE_TAG }}
name: Release ${{ env.RELEASE_TAG }}
artifacts: ${{ env.CURRENT_LOCALE_DIR }}/dist/*
body: Release ${{ env.RELEASE_TAG }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Publish PyPI Package
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: python -m twine upload dist/*
- name: Create NPM configuration
run: python .github/scripts/create_npmrc.py
- name: Publish NPM Package
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npm publish
13 changes: 6 additions & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
fail-fast: false
matrix:
OS: ['ubuntu-latest', 'windows-latest']
PYTHON_VERSION: ['3.5', '3.6', '3.7','3.8']
PYTHON_VERSION: ['3.5', '3.6', '3.7', '3.8']
steps:
- uses: actions/checkout@v2
- name: Set up Python
Expand All @@ -29,11 +29,10 @@ jobs:
pip install .
pip freeze
- name: List dependencies
run: |
pip list
run: pip list
- name: Run tests
run: |
py.test nbformat/tests -v --cov=nbformat
run: py.test nbformat/tests -v --cov=nbformat
- name: Check manfest
run: check-manifest -v
- name: Coverage
run: |
codecov
run: codecov
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ __pycache__
*.bak
.ipynb_checkpoints
.tox
.DS_Store
**.DS_Store
\#*#
.#*
.coverage
Expand Down
17 changes: 8 additions & 9 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
include .bumpversion.cfg
include .mailmap
include COPYING.md
include CONTRIBUTING.md
include README.md
include RELEASING.md
include MANIFEST.in
recursive-include nbformat *.txt
recursive-exclude nbformat/tests *.*

# Javascript
include package.json
include index.js

# Documentation
graft docs
exclude docs/\#*

# Examples
graft examples

# docs subdirs we want to skip
prune docs/build
prune docs/gh-pages
prune docs/dist
exclude docs/.DS_Store
recursive-exclude docs/_build *

# Patterns to exclude from any directory
global-exclude *~
Expand Down
64 changes: 32 additions & 32 deletions RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@
First copy `nbformat/v4/nbformat/.v4.schema.json` to `nbformat/v4/nbformat/.v4.<new_minor_version_here>schema.json`.
Then edit the top of `nbformat/v4/nbbase.py`:

```
# Change the nbformat_minor and nbformat_schema variables when incrementing the
# nbformat version

# current major version
nbformat = 4

# current minor version
nbformat_minor = <new_minor_version_here>

# schema files for (major, minor) version tuples. (None, None) means the current version
nbformat_schema = {
(None, None): 'nbformat.v4.schema.json',
(4, 0): 'nbformat.v4.0.schema.json',
...
(4, <new_minor_version_here>): 'nbformat.v4.<new_minor_version_here>.schema.json'
}
```
```python
# Change the nbformat_minor and nbformat_schema variables when incrementing the
# nbformat version

# current major version
nbformat = 4

# current minor version
nbformat_minor = <new_minor_version_here>

# schema files for (major, minor) version tuples. (None, None) means the current version
nbformat_schema = {
(None, None): 'nbformat.v4.schema.json',
(4, 0): 'nbformat.v4.0.schema.json',
...
(4, <new_minor_version_here>): 'nbformat.v4.<new_minor_version_here>.schema.json'
}
```

If you do one of these steps but not the others it will fail many tests.

Expand All @@ -34,15 +34,20 @@ Change from patch to minor or major for appropriate version updates.

```bash
# Commit, test, publish, tag release
bumpversion minor # CHECK FIRST: If the patch version currently set is not sufficient
git commit -am "Prepared <release-id>"
bumpversion suffix # Remove the .dev
git commit -am "Generated release <release-id>"
git tag <release_version_here>
git push && git push --tags
bump2version release --tag
bump2version patch

git push upstream master
git push upstream --tags
```

## Push to PyPI
## Publish packages

PyPI and NPM packages will be built and published on CI when a tag is pushed.

## Manual publish procedure

### Push to PyPI

```bash
rm -rf dist/*
Expand All @@ -53,15 +58,10 @@ pip install dist/*
twine upload dist/*
```

## Push to npm
### Push to npm

```bash
npm publish
```

Note for JavaScript developers -- `bumpversion` updates the version in `package.json`.

## Prep repo for development

- `bumpversion patch # Resets the patch and dev versions`
- `git commit -am "Resumed patch dev"; git push`
Note for JavaScript developers -- `bump2version` updates the version in `package.json`.
2 changes: 1 addition & 1 deletion nbformat/_version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Make sure to update package.json, too!
version_info = (5, 0, 9, 'dev')
version_info = (5, 0, 9, 'beta0')
__version__ = '.'.join(map(str, version_info))
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nbformat-schema",
"version": "5.0.8",
"version": "5.0.9-beta.0",
"description": "JSON schemata for Jupyter notebook formats",
"main": "index.js",
"files": [
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@

extras_require = setuptools_args['extras_require'] = {
'fast': ['fastjsonschema'],
'test': ['fastjsonschema', 'testpath', 'pytest', 'pytest-cov'],
'test': ['check-manifest', 'fastjsonschema', 'testpath', 'pytest', 'pytest-cov'],
}

if 'setuptools' in sys.modules:
Expand Down