Skip to content

Commit

Permalink
Merge pull request #34 from fingerprintjs/use-semantic-release
Browse files Browse the repository at this point in the history
Use semantic-release for the release workflow
  • Loading branch information
ilfa authored Aug 10, 2023
2 parents e9220c4 + 8276ebb commit a183e3b
Show file tree
Hide file tree
Showing 10 changed files with 184 additions and 82 deletions.
61 changes: 3 additions & 58 deletions .github/workflows/analyze-commits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,61 +5,6 @@ permissions:
pull-requests: write
contents: write
jobs:
commitlint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: wagoid/commitlint-github-action@v5
id: commitlint
- if: ${{ failure() && steps.commitlint.outcome == 'failure' }}
uses: marocchino/sticky-pull-request-comment@3d60a5b2dae89d44e0c6ddc69dd7536aec2071cd
with:
header: Commitlint
recreate: true
message: |
## Wrong commit message format detected
We use [Semantic Commit Messages](https://gist.github.com/joshbuchea/6f47e86d2510bce28f8e7f42ae84c716) in our project.
> **Warning**
> Probably you forgot to activate local git hooks.
Run the next command in the project root to activate local hooks:
```sh
sh ./install_hooks.sh
```
More info you can find in [job logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
- if: ${{ success() }}
uses: marocchino/sticky-pull-request-comment@3d60a5b2dae89d44e0c6ddc69dd7536aec2071cd
with:
header: Commitlint
hide: true
hide_classify: "OUTDATED"
release-notes-comment:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Collect semantic-release-info
id: semantic_release_info
uses: fingerprintjs/action-semantic-release-info@v1
- if: ${{ steps.semantic_release_info.outputs.no_release == 'false' }}
name: Add comment to the PR
uses: marocchino/sticky-pull-request-comment@3d60a5b2dae89d44e0c6ddc69dd7536aec2071cd
with:
header: ReleasePreview
recreate: true
message: |
## This PR will create a ${{steps.semantic_release_info.outputs.type}} release :rocket:
${{steps.semantic_release_info.outputs.notes}}
- if: ${{ steps.semantic_release_info.outputs.no_release == 'true' }}
name: Add comment to the PR
uses: marocchino/sticky-pull-request-comment@3d60a5b2dae89d44e0c6ddc69dd7536aec2071cd
with:
header: ReleasePreview
recreate: true
message: |
## This PR will not create a new release :rocket:
analyze-commits:
name: Generate docs and coverage report
uses: fingerprintjs/dx-team-toolkit/.github/workflows/analyze-commits.yml@v1
21 changes: 12 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
- dev

jobs:
publish:
Expand All @@ -27,14 +28,16 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install python-semantic-release
pip install wheel
pip install twine
- name: Generate code with new version
run: ./generate.sh -v $(semantic-release print-version)

- name: Python Semantic Release
uses: python-semantic-release/python-semantic-release@c633414ae2a5518d21b852be66eac1cbc2dd8e87 # v7.34.6
- name: Semantic Release
uses: cycjimmy/semantic-release-action@91ab76a4a393a8d0c4739e9aea1818b56bc953ea
with:
github_token: ${{ secrets.GH_RELEASE_TOKEN }}
repository_username: ${{ secrets.PYPI_USERNAME }}
repository_password: ${{ secrets.PYPI_PASSWORD }}
extra_plugins: |
@semantic-release/[email protected]
[email protected]
[email protected]
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_GH_TOKEN }}
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
127 changes: 127 additions & 0 deletions .releaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
{
"branches": [
"main",
{
"name": "dev",
"prerelease": true
}
],
"plugins": [
[
"@semantic-release/commit-analyzer",
{
"releaseRules": [
{
"type": "build",
"scope": "deps",
"release": "patch"
},
{
"type": "docs",
"scope": "README",
"release": "patch"
}
]
}
],
[
"@semantic-release/release-notes-generator",
{
"preset": "conventionalCommits",
"presetConfig": {
"types": [
{
"type": "feat",
"section": "Features"
},
{
"type": "feature",
"section": "Features"
},
{
"type": "fix",
"section": "Bug Fixes"
},
{
"type": "perf",
"section": "Performance Improvements"
},
{
"type": "revert",
"section": "Reverts"
},
{
"type": "docs",
"scope": "README",
"section": "Documentation"
},
{
"type": "build",
"scope": "deps",
"section": "Build System"
},
{
"type": "docs",
"section": "Documentation",
"hidden": true
},
{
"type": "style",
"section": "Styles",
"hidden": true
},
{
"type": "chore",
"section": "Miscellaneous Chores",
"hidden": true
},
{
"type": "refactor",
"section": "Code Refactoring",
"hidden": true
},
{
"type": "test",
"section": "Tests",
"hidden": true
},
{
"type": "build",
"section": "Build System",
"hidden": true
},
{
"type": "ci",
"section": "Continuous Integration",
"hidden": true
}
]
}
}
],
"@semantic-release/changelog",
[
"@semantic-release/exec",
{
"prepareCmd": "./generate.sh -v \"${nextRelease.version}\""
}
],
"semantic-release-pypi",
[
"@semantic-release/git",
{
"assets": [
"generate.sh",
"CHANGELOG.md",
"README.md",
"setup.py",
"fingerprint_pro_server_api_sdk/configuration.py",
"fingerprint_pro_server_api_sdk/api_client.py",
"fingerprint_pro_server_api_sdk/api/fingerprint_api.py",
"test/test_fingerprint_api.py"
]
}
],
"@semantic-release/github"
]
}
18 changes: 18 additions & 0 deletions contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,21 @@ pip install -r test-requirements.txt
```shell
pytest
```

### How to publish

The library is automatically released and published to PyPi on every push to the main branch if there are relevant changes using [semantic-release](https://github.com/semantic-release/semantic-release) with following plugins:
* [@semantic-release/commit-analyzer](https://github.com/semantic-release/commit-analyzer)
* [@semantic-release/release-notes-generator](https://github.com/semantic-release/release-notes-generator)
* [@semantic-release/changelog](https://github.com/semantic-release/changelog)
* [@semantic-release/exec](https://github.com/semantic-release/exec)
* [semantic-release-pypi](https://github.com/abichinger/semantic-release-pypi)
* [@semantic-release/github](https://github.com/semantic-release/github)

The workflow must be approved by one of the maintainers, first.

#### Pre-release flow

Pre-release will be created after merging pr to the `dev` branch and running the `release` workflow.

Python uses PEP 440 for versions format, so we convert a pre-release version from semver to PEP 440 in the `./generate.sh`.
2 changes: 1 addition & 1 deletion fingerprint_pro_server_api_sdk/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def __init__(self, configuration=None, header_name=None, header_value=None,
try:
from multiprocessing.pool import ThreadPool
self.pool = ThreadPool()
except ImportError:
except (ImportError, OSError):
from fingerprint_pro_server_api_sdk.dummy_pool import DummyPool
self.pool = DummyPool()
else:
Expand Down
18 changes: 18 additions & 0 deletions generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ while getopts "v:" arg; do
esac
done

# Make prerelease version compatible with PEP 440
if [[ $VERSION =~ (.*-dev\.)([0-9]+) ]]; then
BASE_VERSION=${BASH_REMATCH[1]}
DEV_NUMBER=${BASH_REMATCH[2]}
VERSION="${BASE_VERSION%-dev.}.dev${DEV_NUMBER}"
fi

# jar was downloaded from here https://repo1.maven.org/maven2/io/swagger/codegen/v3/swagger-codegen-cli/3.0.34/

rm docs/*
Expand All @@ -34,3 +41,14 @@ platform=$(uname)
sed -i "/^------------ |/c\\" "$readme_filename"
fi
)

# Replace version in other files
(
if [ "$platform" = "Darwin" ]; then
sed -i '' "s/^VERSION='[^']*'/VERSION='${VERSION}'/" "./generate.sh"
sed -i '' "s/^VERSION = '[^']*'/VERSION = '${VERSION}'/" "./test/test_fingerprint_api.py"
else
sed -i "s/^VERSION='[^']*'/VERSION='${VERSION}'/" "./generate.sh"
sed -i "s/^VERSION = '[^']*'/VERSION = '${VERSION}'/" "./test/test_fingerprint_api.py"
fi
)
9 changes: 2 additions & 7 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
[semantic_release]
version_variable = generate.sh:VERSION,test/test_fingerprint_api.py:VERSION
version_source = tag
commit_version_number = true
branch = main
include_additional_files = README.md,setup.py,fingerprint_pro_server_api_sdk/configuration.py,fingerprint_pro_server_api_sdk/api_client.py,fingerprint_pro_server_api_sdk/api/fingerprint_api.py,test/test_fingerprint_api.py
commit_message = chore(release): {version} [skip ci]
[metadata]
version = 2.4.0
4 changes: 1 addition & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from setuptools import setup, find_packages # noqa: H301

NAME = "fingerprint-pro-server-api-sdk"
VERSION = "2.4.0"
# To install the library, run the following
#
# python setup.py install
Expand All @@ -39,8 +38,7 @@

setup(
name=NAME,
version=VERSION,
description="Fingerprint Pro Server API allows you to get information about visitors and about individual events in a server environment. It can be used for data exports, decision-making, and data analysis scenarios. Server API is intended for server-side usage, it's not intended to be used from the client side, whether it's a browser or a mobile device. ",
description="Fingerprint Pro Server API allows you to get information about visitors and about individual events in a server environment. It can be used for data exports, decision-making, and data analysis scenarios. Server API is intended for server-side usage, it's not intended to be used from the client side, whether it's a browser or a mobile device. ",
long_description=long_description,
long_description_content_type='text/markdown',
license="MIT",
Expand Down
2 changes: 1 addition & 1 deletion template/api_client.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ApiClient(object):
try:
from multiprocessing.pool import ThreadPool
self.pool = ThreadPool()
except ImportError:
except (ImportError, OSError):
from {{packageName}}.dummy_pool import DummyPool
self.pool = DummyPool()
else:
Expand Down
4 changes: 1 addition & 3 deletions template/setup.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import re
from setuptools import setup, find_packages # noqa: H301

NAME = "{{{projectName}}}"
VERSION = "{{packageVersion}}"
{{#apiInfo}}
{{#apis}}
{{^hasMore}}
Expand Down Expand Up @@ -40,8 +39,7 @@ long_description = re.sub(r"(?P<prefix>\[[^]]*]\()(?P<postfix>docs/[^)]*\))", '\

setup(
name=NAME,
version=VERSION,
description="{{appDescription}}",
description="{{{appDescription}}}",
long_description=long_description,
long_description_content_type='text/markdown',
license="MIT",
Expand Down

0 comments on commit a183e3b

Please sign in to comment.