Skip to content

Commit

Permalink
🔒 Add semantic release
Browse files Browse the repository at this point in the history
  • Loading branch information
perdy committed May 13, 2020
1 parent 7768329 commit b986cd8
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 32 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/ci_master.yaml
Expand Up @@ -4,8 +4,6 @@ on:
push:
branches:
- master
tags:
- "v[0-9]*.[0-9]*.[0-9]*"

jobs:
test:
Expand Down Expand Up @@ -54,11 +52,14 @@ jobs:
image: perdy/github-actions-builder:latest
steps:
- uses: actions/checkout@master
if: github.event_name == 'push' && github.ref != 'refs/heads/master'
- name: Setup node
uses: actions/setup-node@v1
with:
node-version: 12
- id: publish
name: Publish version
if: github.event_name == 'push' && github.ref != 'refs/heads/master'
run: python make publish --build
run: npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_ACTIONS_TOKEN }}
PYPI_USERNAME: ${{ secrets.PYPI_USERNAME }}
PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
58 changes: 58 additions & 0 deletions .releaserc
@@ -0,0 +1,58 @@
{
"branch": "master",
"plugins": [
[
"semantic-release-gitmoji",
{
"releaseRules": {
"major": [
":boom:"
],
"minor": [
":sparkles:"
],
"patch": [
":bug:",
":ambulance:",
":lock:"
]
}
}
],
[
"@semantic-release/changelog",
{
"changelogFile": "CHANGELOG.md",
"changelogTitle": "# Semantic Versioning Changelog"
}
],
[
"@semantic-release/exec",
{
"prepareCmd": "python make version ${nextRelease.version}",
"publishCmd": "python make publish --build"
}
],
[
"@semantic-release/git",
{
"message": ":bookmark: ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}",
"assets": [
"CHANGELOG.md",
"pyproject.toml",
"poetry.lock"
]
}
],
[
"@semantic-release/github",
{
"assets": [
{
"path": "dist/**"
}
]
}
]
]
}
4 changes: 0 additions & 4 deletions CHANGELOG.md
@@ -1,4 +0,0 @@
# Changes

v0.1.0 - 2018-09-24
* Initial release.
35 changes: 12 additions & 23 deletions make
Expand Up @@ -61,8 +61,15 @@ def clean(*args, **kwargs):
shutil.rmtree(path, ignore_errors=True)


@command(command_type=Type.SHELL, parser_opts={"help": "Build package"})
@command(
command_type=Type.SHELL,
args=((("-c", "--clean"), {"help": "Clean before build"}),),
parser_opts={"help": "Build package"},
)
def build(*args, **kwargs):
if kwargs["clean"]:
clean()

return [poetry("build", *args)]


Expand Down Expand Up @@ -96,29 +103,14 @@ def docs(*args, **kwargs):
return [poetry("run", "mkdocs", *args)]


@command(command_type=Type.PYTHON, parser_opts={"help": "Upgrade version"})
@command(command_type=Type.SHELL, parser_opts={"help": "Upgrade version"})
def version(*args, **kwargs):
if toml is None:
logger.error("Package toml is not installed, run 'pip install toml' to install it")
return -1

old_version = toml.load("pyproject.toml")["tool"]["poetry"]["version"]

subprocess.run(poetry("version", *args))

new_version = toml.load("pyproject.toml")["tool"]["poetry"]["version"]

subprocess.run(shlex.split(f"git add pyproject.toml poetry.lock"))
subprocess.run(shlex.split(f'git commit -m "Bumping version from {old_version} to {new_version}"'))
subprocess.run(shlex.split(f"git tag v{new_version}"))
return [poetry("version", *args)]


@command(
command_type=Type.SHELL,
args=(
(("--version",), {"help": "Version to upgrade", "choices": ("patch", "minor", "major")}),
(("-b", "--build"), {"help": "Build package", "action": "store_true"}),
),
args=((("-b", "--build"), {"help": "Build package", "action": "store_true"}),),
parser_opts={"help": "Publish package"},
)
def publish(*args, **kwargs):
Expand All @@ -130,11 +122,8 @@ def publish(*args, **kwargs):
if username and password:
cmds.append(poetry("config", "http-basic.pypi", username, password))

if kwargs.get("version", None):
version(version=kwargs["version"])

if kwargs["build"]:
cmds += build()
cmds += build(clean=True)

cmds.append(poetry("publish"))

Expand Down

0 comments on commit b986cd8

Please sign in to comment.