diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3b2804f..5b44ede 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -4,7 +4,7 @@ on: - cron: "0 */4 * * *" workflow_dispatch: repository_dispatch: - types: [pypi_release] + types: [ pypi_release ] jobs: build: @@ -30,3 +30,8 @@ jobs: - run: pre-commit-mirror --language python --package-name ruff --entry 'ruff check --force-exclude' --id ruff --types-or python --types-or pyi --require-serial --description "Run 'ruff' for extremely fast Python linting" . - run: git push origin HEAD:refs/heads/main --tags + + - name: "Update version in README.md" + run: python update_version.py + + - run: git push origin HEAD:refs/heads/main diff --git a/update_version.py b/update_version.py new file mode 100644 index 0000000..2c83647 --- /dev/null +++ b/update_version.py @@ -0,0 +1,24 @@ +"""Updates the version in the readme and git commit.""" + +import re +from pathlib import Path +from subprocess import check_call, check_output + + +def main(): + readme_md = Path("README.md") + readme = readme_md.read_text() + rev = Path(".version").read_text().strip() + readme = re.sub("rev: .*", f"rev: v{rev}", readme) + readme_md.write_text(readme) + # Only commit on change + # https://stackoverflow.com/a/9393642/3549270 + if check_output(["git", "status", "-s"]).strip(): + check_call(["git", "add", readme_md]) + check_call(["git", "commit", "-m", f"Bump README.md version to {rev}"]) + else: + print("No change") + + +if __name__ == "__main__": + main()