Skip to content

Commit

Permalink
Add Github Actions to release to testpypi on commit and to pypi and G…
Browse files Browse the repository at this point in the history
…ithub on new tag
  • Loading branch information
firecat53 committed Nov 19, 2024
1 parent 7d423f1 commit 4d236c9
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 0 deletions.
133 changes: 133 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
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 testing dependencies
run: |
sudo apt update
sudo apt install -y suckless-tools xdotool
- name: Install Hatch
run: |
python -m pip install --upgrade pip
pip install hatch hatchling hatch-vcs
- name: Build package
run: hatch build

- name: Test package
run: hatch run make test

- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: keepmenu
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/keepmenu # Replace <package-name> 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: keepmenu
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: keepmenu
path: dist/
- name: Sign the dists with Sigstore
uses: sigstore/[email protected]
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/keepmenu

permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: keepmenu
path: dist/
- name: Publish to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ classifiers = [
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Topic :: Utilities",
]
dependencies = [
Expand All @@ -48,6 +49,9 @@ Homepage = "https://github.com/firecat53/keepmenu"
source = "vcs"
fallback-version = "0.0.0"

[tool.hatch.version.raw-options]
local_scheme = "no-local-version"

[tool.hatch.build.hooks.vcs]
version-file = "keepmenu/_version.py"

Expand Down

0 comments on commit 4d236c9

Please sign in to comment.