Skip to content

Commit

Permalink
Add publish and release workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
Flagro committed Feb 13, 2024
1 parent 8df956a commit d4a1e10
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 0 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Publish PyPi package

on:
workflow_run:
workflows: ["Release Workflow"]
types:
- completed
workflow_dispatch:

jobs:
build-and-publish:
name: Build and publish PyPi package
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
permissions:
packages: write
contents: read
steps:
- name: Check out the repo
uses: actions/checkout@v4

- name: Fetch tags
run: git fetch --depth=1 --tags

- name: Get latest tag or set default
id: latest_tag
run: |
TAG=$(git tag -l --sort=-v:refname | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1)
if [ -z "$TAG" ]; then
TAG="latest"
fi
echo "::set-output name=tag::$TAG"
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.9'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine toml build
- name: Update pyproject.toml
run: |
python -c "\
import toml; \
pyproject = toml.load('pyproject.toml'); \
pyproject['project']['version'] = '${{ steps.latest_tag.outputs.tag }}'; \
toml.dump(pyproject, open('pyproject.toml', 'w'))"
- name: Build and publish
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
python -m build
twine upload dist/*
86 changes: 86 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Release Workflow

on:
workflow_dispatch:
inputs:
releaseType:
description: 'Release Type'
required: true
default: 'patch'
type: choice
options:
- major
- minor
- patch
draft:
description: 'Create a draft release'
required: false
default: false
type: boolean
prerelease:
description: 'Mark release as a prerelease'
required: false
default: false
type: boolean
releaseMessage:
description: 'Release Message'
required: false
default: ''
type: string

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '14'

- name: Fetch tags
run: git fetch --depth=1 --tags

- name: Get latest tag or set default
id: latest_tag
run: |
TAG=$(git tag -l --sort=-v:refname | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1)
if [ -z "$TAG" ]; then
TAG="0.0.0"
fi
echo "::set-output name=tag::$TAG"
- name: Create dummy package.json
run: |
echo "{\"version\": \"${{ steps.latest_tag.outputs.tag }}\"}" > package.json
cat package.json
- name: Calculate next version
id: next_version
run: |
npm --no-git-tag-version version ${{ github.event.inputs.releaseType }}
NEXT_VERSION=$(node -p "require('./package.json').version")
echo "Next version: $NEXT_VERSION"
echo "::set-output name=version::$NEXT_VERSION"
- name: Create Git tag
run: git tag ${{ steps.next_version.outputs.version }}

- name: Push Git tag
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git push origin ${{ steps.next_version.outputs.version }}
- name: Create Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.next_version.outputs.version }}
release_name: Release v${{ steps.next_version.outputs.version }}
body: ${{ github.event.inputs.releaseMessage }}
draft: ${{ github.event.inputs.draft }}
prerelease: ${{ github.event.inputs.prerelease }}

0 comments on commit d4a1e10

Please sign in to comment.