From 54e7f019aaf3b6f6a5e350e478b26dd55f8decec Mon Sep 17 00:00:00 2001 From: Andre Lengwenus Date: Wed, 17 Jan 2024 18:03:02 +0000 Subject: [PATCH] Add automatic versioning and deploy to PyPi --- .github/workflows/ReleaseActions.yaml | 49 +++++++++++++++++++++++++++ MANIFEST.in | 1 + VERSION | 1 + build-scripts/env.cjs | 5 ++- pyproject.toml | 6 +++- src/version.ts | 1 + 6 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/ReleaseActions.yaml create mode 100644 VERSION create mode 100644 src/version.ts diff --git a/.github/workflows/ReleaseActions.yaml b/.github/workflows/ReleaseActions.yaml new file mode 100644 index 0000000..0c44065 --- /dev/null +++ b/.github/workflows/ReleaseActions.yaml @@ -0,0 +1,49 @@ +name: "Release actions" + +on: + release: + types: ["published"] + +env: + PYTHON_VERSION: "3.x" + +jobs: + deploy: + runs-on: ubuntu-latest + name: Deploy to PyPi + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Set up Python + uses: actions/setup-python@v5.0.0 + with: + python-version: ${{ env.PYTHON_VERSION }} + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version-file: ".nvmrc" + cache: yarn + - name: "Set version number from tag" + run: | + echo -n '${{ github.ref_name }}' > ./VERSION + sed -i 's/dev/${{ github.ref_name }}/g' ./src/version.ts + cat ./VERSION + cat ./src/version.ts + + - name: Install dependencies + run: | + python -m pip install build twine + ./script/bootstrap + + - name: Build + run: yarn build + + - name: Publish to PyPi + env: + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} + run: | + python -m build + twine upload dist/* diff --git a/MANIFEST.in b/MANIFEST.in index d9617df..008b9f5 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,2 +1,3 @@ graft lcn_frontend global-exclude *.py[cod] +include VERSION diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..38f8e88 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +dev diff --git a/build-scripts/env.cjs b/build-scripts/env.cjs index d6536b1..8c8b1ba 100644 --- a/build-scripts/env.cjs +++ b/build-scripts/env.cjs @@ -24,11 +24,10 @@ module.exports = { }, version() { const version = fs - .readFileSync(path.resolve(paths.polymer_dir, "pyproject.toml"), "utf8") - .match(/version\W+=\W"(.*?)"/); + .readFileSync(path.resolve(paths.polymer_dir, "VERSION"), "utf8") if (!version) { throw Error("Version not found"); } - return version[1]; + return version.trim(); }, }; diff --git a/pyproject.toml b/pyproject.toml index 62e82e3..476db68 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,18 +4,22 @@ build-backend = "setuptools.build_meta" [project] name = "lcn_frontend" -version = "0.1.0" license = {text = "MIT License"} description = "LCN panel for Home Assistant" +keywords = ["Home Assistant", "LCN"] readme = "README.md" authors = [ {name = "Andre Lengwenus", email = "alengwenus@gmail.com"}, ] requires-python = ">=3.10.0" +dynamic = ["version"] [project.urls] Repository = "https://github.com/alengwenus/lcn-frontend.git" +[tool.setuptools.dynamic] +version = {file = "VERSION"} + [tool.setuptools] platforms = ["any"] zip-safe = false diff --git a/src/version.ts b/src/version.ts new file mode 100644 index 0000000..3992e2c --- /dev/null +++ b/src/version.ts @@ -0,0 +1 @@ +export const VERSION = "dev";