From eb98c12754200884300e19996566a9498bae3bea Mon Sep 17 00:00:00 2001 From: Scott Hansen Date: Thu, 21 Nov 2024 21:04:24 -0800 Subject: [PATCH] Add github workflow to publish to testpypi on commit and to release to pypi and github on tag commit --- .github/workflows/main.yml | 125 +++++++++++++++++++++++++++++++++++++ flake.lock | 6 +- pyproject.toml | 3 + 3 files changed, 131 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..7b9bc62 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,125 @@ +name: main + +on: + push: + branches: + - main + tags: + - '*' + pull_request: + branches: + - main + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # Ensures version gets set correctly + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.x" + + - name: Install Hatch + run: | + python -m pip install --upgrade pip + pip install hatch hatchling hatch-vcs + + - name: Build package + run: hatch build + + - name: Store the distribution packages + uses: actions/upload-artifact@v4 + with: + name: bitwarden-menu + path: dist/ + + publish-to-pypi: + name: Publish to PyPI + if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes + needs: + - build + runs-on: ubuntu-latest + environment: + name: pypi + url: https://pypi.org/p/bitwarden-menu # Replace with your PyPI project name + permissions: + id-token: write # IMPORTANT: mandatory for trusted publishing + + steps: + - name: Download all the dists + uses: actions/download-artifact@v4 + with: + name: bitwarden-menu + path: dist/ + - name: Publish to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + + github-release: + name: >- + Sign the with Sigstore and upload to GitHub Release + needs: + - publish-to-pypi + runs-on: ubuntu-latest + + permissions: + contents: write # IMPORTANT: mandatory for making GitHub Releases + id-token: write # IMPORTANT: mandatory for sigstore + + steps: + - name: Download all the dists + uses: actions/download-artifact@v4 + with: + name: bitwarden-menu + path: dist/ + - name: Sign the dists with Sigstore + uses: sigstore/gh-action-sigstore-python@v3.0.0 + with: + inputs: >- + ./dist/*.tar.gz + ./dist/*.whl + - name: Create GitHub Release + env: + GITHUB_TOKEN: ${{ github.token }} + run: >- + gh release create + '${{ github.ref_name }}' + --repo '${{ github.repository }}' + --notes "" + - name: Upload artifact signatures to GitHub Release + env: + GITHUB_TOKEN: ${{ github.token }} + # Upload to GitHub Release using the `gh` CLI. + # `dist/` contains the built packages, and the + # sigstore-produced signatures and certificates. + run: >- + gh release upload + '${{ github.ref_name }}' dist/** + --repo '${{ github.repository }}' + + publish-to-testpypi: + name: Publish to TestPyPI + needs: + - build + runs-on: ubuntu-latest + + environment: + name: testpypi + url: https://test.pypi.org/p/bitwarden-menu + + permissions: + id-token: write # IMPORTANT: mandatory for trusted publishing + + steps: + - name: Download all the dists + uses: actions/download-artifact@v4 + with: + name: bitwarden-menu + path: dist/ + - name: Publish to TestPyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + repository-url: https://test.pypi.org/legacy/ diff --git a/flake.lock b/flake.lock index 49bf1bc..bf53ed2 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1728492678, - "narHash": "sha256-9UTxR8eukdg+XZeHgxW5hQA9fIKHsKCdOIUycTryeVw=", + "lastModified": 1731676054, + "narHash": "sha256-OZiZ3m8SCMfh3B6bfGC/Bm4x3qc1m2SVEAlkV6iY7Yg=", "owner": "nixos", "repo": "nixpkgs", - "rev": "5633bcff0c6162b9e4b5f1264264611e950c8ec7", + "rev": "5e4fbfb6b3de1aa2872b76d49fafc942626e2add", "type": "github" }, "original": { diff --git a/pyproject.toml b/pyproject.toml index d42c3f4..2a24d03 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -48,6 +48,9 @@ Homepage = "https://github.com/firecat53/bitwarden-menu" source = "vcs" fallback-version = "0.0.0" +[tool.hatch.version.raw-options] +local_scheme = "no-local-version" + [tool.hatch.build.hooks.vcs] version-file = "bwm/_version.py"