-
Notifications
You must be signed in to change notification settings - Fork 5
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
add deployment scripts #31
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4f0c888
merge setup.cfg into pyproject.toml
rkaminsk 794b6f9
remove config leftovers
rkaminsk 914ffd5
add refined deployment workflow
rkaminsk 83ec75d
make sure that the tests run
rkaminsk e2d4c1c
add deployment info
rkaminsk b3b002e
remove empty folders
rkaminsk b3122e6
update DEPLOYMENT.md
rkaminsk 3ccd420
run tests before deployment
rkaminsk 6d6c093
adjust renaming script
rkaminsk 9c0e059
lower version (closes #34)
rkaminsk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
name: deploy to pypi | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
tags: | ||
- 'v[0-9]+.[0-9]+.[0-9]+' | ||
|
||
jobs: | ||
test: | ||
uses: ./.github/workflows/test.yml | ||
|
||
deploy: | ||
name: deploy | ||
needs: test | ||
permissions: | ||
id-token: write | ||
environment: release | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version: 3.11 | ||
|
||
- name: install build dependencies | ||
run: python3 -m pip install build | ||
|
||
- name: build package | ||
run: python3 -m build --sdist --wheel --outdir dist/ | ||
|
||
- name: upload package | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: package | ||
path: dist/ | ||
|
||
- name: publish package (pypi) | ||
if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }} | ||
uses: pypa/gh-action-pypi-publish@release/v1 | ||
with: | ||
repository-url: "https://pypi.org/legacy/" | ||
|
||
- name: publish package (test.pypi) | ||
if: ${{ github.event_name == 'workflow_dispatch' }} | ||
uses: pypa/gh-action-pypi-publish@release/v1 | ||
with: | ||
repository-url: "https://test.pypi.org/legacy/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# Changes | ||
|
||
## v1.0.0 | ||
## v0.1.0 | ||
|
||
- create project |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
## Deployment | ||
|
||
Releases are deployed on [pypi] whenever a tag of form `vMajor.Minor.Revision` | ||
is pushed. Furthemore, the deployment workflow can be triggered manually to | ||
deploy test releases on [test.pypi]. | ||
|
||
For this to work, the workflow has to be granted permission to deploy on the | ||
two services. Please follow this packaging [guide] to setup your accounts | ||
accordingly. We also recommend to setup a github [environment] to restrict which | ||
contributers can deploy packages. | ||
|
||
[pypi]: https://pypi.org/ | ||
[test.pypi]: https://test.pypi.org/ | ||
[guide]: https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/ | ||
[environment]: https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,34 +5,65 @@ | |
|
||
import os | ||
import re | ||
import subprocess | ||
|
||
|
||
def read(prompt, regex): | ||
def read(prompt, regex, default): | ||
""" | ||
Read a string from command line. | ||
|
||
The string has to match the given regular expression. | ||
""" | ||
if default: | ||
prompt += f" [{default}]" | ||
prompt += ": " | ||
|
||
while True: | ||
ret = input(prompt) | ||
if not ret and default: | ||
ret = default | ||
match = re.match(regex, ret) | ||
if match is not None: | ||
return ret | ||
print(f"the project name has to match the regular expression: {regex}") | ||
|
||
|
||
def git_config_get(attr): | ||
""" | ||
Get a git config value. | ||
""" | ||
try: | ||
return subprocess.check_output(["git", "config", "--get", attr]).decode().strip() | ||
except subprocess.CalledProcessError: | ||
return None | ||
|
||
def main(): | ||
""" | ||
Rename the project. | ||
""" | ||
project = read("project name: ", r"^[a-z][a-z0-9_]*$") | ||
author = read("author: ", r".+") | ||
email = read("email: ", r".+") | ||
|
||
author = git_config_get("user.name") | ||
email = git_config_get("user.email") | ||
origin = git_config_get("remote.origin.url") | ||
url, project = None, None | ||
|
||
if origin is not None: | ||
match = re.match(r"^.*[:/]([^:/]*)/([^/]*)(\.git)?$", origin) | ||
if match is not None: | ||
org, project = match.group(1), match.group(2) | ||
url = f"https://github.com/{org}/{project}/" | ||
project = project.replace("-", "_") | ||
|
||
project = read("project name", r"^[a-z][a-z0-9_]*$", project) | ||
author = read("author", r".+", author) | ||
email = read("email", r".+", email) | ||
url = read("url", r".+", url) | ||
|
||
replacements = { | ||
"[email protected]": email, | ||
"Mister Fillname": author, | ||
"https://fillname.org/": url, | ||
"fillname": project, | ||
"<author-email>": email, | ||
"<author>": author, | ||
} | ||
|
||
def replace(filepath): | ||
|
@@ -48,8 +79,8 @@ def replace(filepath): | |
".pre-commit-config.yaml", | ||
"noxfile.py", | ||
"pyproject.toml", | ||
"setup.cfg", | ||
"CONTRIBUTING.md", | ||
"DEPLOYMENT.md", | ||
"DEVELOPMENT.md", | ||
"LICENSE", | ||
"README.md", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,38 @@ requires = [ | |
] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[project] | ||
name = "fillname" | ||
authors = [ | ||
{ name = "Mister Fillname", email = "[email protected]" } | ||
] | ||
description = "A template project." | ||
requires-python = ">=3.9" | ||
license = {file = "LICENSE"} | ||
dynamic = [ "version" ] | ||
readme = "README.md" | ||
|
||
[project.urls] | ||
Hompage = "https://fillname.org/" | ||
|
||
[project.optional-dependencies] | ||
format = [ "black", "isort", "autoflake" ] | ||
lint_pylint = [ "pylint" ] | ||
typecheck = [ "types-setuptools", "mypy" ] | ||
test = [ "coverage[toml]" ] | ||
doc = [ "sphinx", "furo", "nbsphinx", "sphinx_copybutton", "myst-parser" ] | ||
dev = [ "fillname[test,typecheck,lint_pylint]" ] | ||
|
||
[project.scripts] | ||
fillname = "fillname.__main__:main" | ||
|
||
[tool.setuptools.packages.find] | ||
where = ["src"] | ||
|
||
[tool.setuptools_scm] | ||
version_scheme = "python-simplified-semver" | ||
local_scheme = "no-local-version" | ||
|
||
[tool.isort] | ||
profile = "black" | ||
line_length = 120 | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Miss Fillname ? @rkaminsk
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about Mx. Fillname ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I think
<author>
was also okay.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's intended. It will be replaced by the init script.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With <author> it might still have worked. But for example with <email> the tests failed because <email> did not have the proper form.
The only reason why I did the change was to give everything a form as it would occur in a real project to be able to test the project. It was not even intended as a joke. I just wanted to have Fillname in here to have unique token to replace. We can also use
Fillname Author
or similar if you think that is better.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, and now I also understand your comment as you wanted the template to be fit the regular expressions.
But I still don`t get why this could be useful. To test the project-template one would simply choose 4 fake things and then test for them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we use these values, the test workflow will fail because the project template cannot be installed (which is required for testing). The test workflow also runs for the template.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could make the values a bit more consistent:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I tried to replace it the way I suggested in my own project and could see the error you meant. Basically the pyproject.toml isnt able to install a project called "".
https://github.com/MaxOstrowski/test-template/
Not sure this is a bad thing though. It prevents the user from using the project without executing
init.py
first.On the other hand it's not looking too nice if the CI test in the template repo fail.
Maybe your more consistent set of names is a good tradeoff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is. Having the ci tests running, will ensure that we do not have unnecessary errors in the python code as we continue extending the template.
We could also extend the CI tests to run the init script but that would be a bit cumbersome to implement.
The current approach is an easy workaround with somewhat curios placeholders that is otherwise nice and simple.