Skip to content

Commit

Permalink
add automation scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
cgarciae committed Mar 18, 2023
1 parent 6247038 commit 5307f2f
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 25 deletions.
19 changes: 5 additions & 14 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ jobs:
name: Create Release
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v2

- name: Check out the code
uses: actions/checkout@v3
- name: Set up Python 3.8
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: 3.8

- name: Setup
id: setup
run: |
# install python dependencies
pip install typer==0.4.0
pip install typer==0.4.0 click==8.0.3
# variables
RELEASE_VERSION='${{ github.ref_name }}'
Expand Down Expand Up @@ -57,20 +57,11 @@ jobs:
# delete branch
git push -d origin ${{ github.ref_name }}
- name: Build Changelog
id: github_release
uses: mikepenz/release-changelog-builder-action@v2.9.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
toTag: ${{ steps.setup.outputs.RELEASE_VERSION }}

- name: Create Release
uses: actions/create-release@v1
with:
tag_name: ${{ steps.setup.outputs.RELEASE_VERSION }}
release_name: ${{ steps.setup.outputs.RELEASE_VERSION }}
body: ${{ steps.github_release.outputs.changelog }}
draft: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35 changes: 24 additions & 11 deletions .github/workflows/publish-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,43 @@ jobs:
name: Publish Docs and Package
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v2
- name: Check out the code
uses: actions/checkout@v3

- name: Set up Python 3.8
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: 3.8

- name: Install Poetry 📖
uses: snok/install-poetry@v1.1.1
- name: Install Poetry
uses: snok/install-poetry@v1.3.3
with:
version: 1.1.4
version: 1.4.0

- name: Setup Poetry
run: |
poetry config virtualenvs.in-project true
- name: Cache
id: cache
uses: actions/cache@v3.2.2
with:
path: '.venv'
key: publish-package-${{ hashFiles('poetry.lock') }}

- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: |
poetry install --without dev
- name: Install Package
run: |
poetry config virtualenvs.create false
pip install -U certifi
poetry install
poetry install --without dev
- name: Build Docs 🔨
run: |
cp README.md docs/index.md
python scripts/update_docs.py
mkdocs build
poetry run mkdocs build
- name: Deploy Page 🚀
uses: JamesIves/github-pages-deploy-action@4.1.6
Expand Down
35 changes: 35 additions & 0 deletions scripts/update_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import re
from pathlib import Path

import typer


# NOTE: this script could be written bash using sed, but I'm not sure if it's worth it
def main(release_name: str):
release_name = release_name.replace("-create-release", "")

# Update pyproject.toml
pyproject_path = Path("pyproject.toml")
pyproject_text = pyproject_path.read_text()
pyproject_text = re.sub(
r'version = ".*"',
f'version = "{release_name}"',
pyproject_text,
count=1,
)
pyproject_path.write_text(pyproject_text)

# Update __init__.py
init_path = Path("simple_pytree/__init__.py")
init_text = init_path.read_text()
init_text = re.sub(
r'__version__ = "(.*?)"',
f'__version__ = "{release_name}"',
init_text,
count=1,
)
init_path.write_text(init_text)


if __name__ == "__main__":
typer.run(main)

0 comments on commit 5307f2f

Please sign in to comment.