Skip to content
This repository was archived by the owner on Jun 28, 2024. It is now read-only.

Commit 0b88776

Browse files
authored
New publish workflows (#109)
* Add new version workflows * Use PYPI_TOKEN as secret
1 parent b172816 commit 0b88776

File tree

7 files changed

+230
-26
lines changed

7 files changed

+230
-26
lines changed

.github/actions/setup/action.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
name: Setup
3+
description: Setup Python and install dependencies.
4+
5+
inputs:
6+
python_version:
7+
description: The Python version.
8+
required: false
9+
default: '3.11'
10+
poetry_version:
11+
description: The Poetry version.
12+
required: false
13+
default: '1.5.1'
14+
install_dependencies:
15+
description: Install dependencies.
16+
required: false
17+
default: 'true'
18+
19+
runs:
20+
using: composite
21+
steps:
22+
- name: Setup Poetry cache on Linux
23+
uses: actions/cache@v3
24+
if: runner.os == 'Linux'
25+
with:
26+
key: poetry-${{ inputs.poetry_version }}-${{ inputs.python_version }}-${{ runner.os }}-${{ runner.arch }}
27+
path: |
28+
~/.local/bin
29+
~/.local/share/pypoetry
30+
- name: Setup Poetry cache on macOS
31+
uses: actions/cache@v3
32+
if: runner.os == 'macOS'
33+
with:
34+
key: poetry-${{ inputs.poetry_version }}-${{ inputs.python_version }}-${{ runner.os }}-${{ runner.arch }}
35+
path: |
36+
~/.local/bin
37+
~/.local/share/pypoetry
38+
~/Library/Application Support/pypoetry
39+
- name: Setup Python
40+
uses: actions/setup-python@v4
41+
with:
42+
python-version: ${{ inputs.python_version }}
43+
- name: Setup Poetry
44+
uses: Gr1N/setup-poetry@v8
45+
with:
46+
poetry-version: ${{ inputs.poetry_version }}
47+
- name: Setup Python with cache
48+
uses: actions/setup-python@v4
49+
if: inputs.install_dependencies == 'true'
50+
with:
51+
cache: poetry
52+
python-version: ${{ inputs.python_version }}
53+
- name: Check lockfile
54+
if: inputs.install_dependencies == 'true'
55+
shell: bash
56+
run: poetry lock --check
57+
- name: Install dependencies
58+
if: inputs.install_dependencies == 'true'
59+
shell: bash
60+
run: poetry install --sync

.github/workflows/_build.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
name: _build
3+
4+
on:
5+
workflow_call:
6+
inputs:
7+
python_version:
8+
description: The Python version.
9+
type: string
10+
required: false
11+
default: '3.11'
12+
runs_on:
13+
description: The runner environment.
14+
type: string
15+
required: false
16+
default: ubuntu-latest
17+
outputs:
18+
artifact_name:
19+
description: The artifact name.
20+
value: build-${{ github.sha }}
21+
22+
jobs:
23+
build:
24+
name: Package
25+
runs-on: ubuntu-latest
26+
timeout-minutes: 30
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v3
30+
- name: Setup
31+
uses: ./.github/actions/setup
32+
with:
33+
python_version: ${{ inputs.python_version }}
34+
- name: Build
35+
run: make build
36+
- name: Upload artifact
37+
uses: actions/upload-artifact@v3
38+
with:
39+
name: build-${{ github.sha }}
40+
if-no-files-found: error
41+
path: dist/

.github/workflows/_publish.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
name: _publish
3+
4+
on:
5+
workflow_call:
6+
inputs:
7+
artifact_name:
8+
description: The artifact name.
9+
type: string
10+
required: true
11+
secrets:
12+
registry_token:
13+
description: The package registry token.
14+
required: true
15+
16+
jobs:
17+
publish:
18+
name: Publish package
19+
runs-on: ubuntu-latest
20+
timeout-minutes: 30
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v3
24+
- name: Setup
25+
uses: ./.github/actions/setup
26+
with:
27+
install_dependencies: 'false'
28+
- name: Download artifact
29+
uses: actions/download-artifact@v3
30+
with:
31+
name: ${{ inputs.artifact_name }}
32+
path: dist/
33+
- name: Publish
34+
run: poetry publish --skip-existing -u $USERNAME -p $PASSWORD
35+
env:
36+
USERNAME: __token__
37+
PASSWORD: ${{ secrets.registry_token }}

.github/workflows/publish.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
name: Publish
3+
4+
run-name: Publish ${{ github.ref_name }}
5+
6+
on:
7+
push:
8+
tags:
9+
- v*
10+
11+
jobs:
12+
build:
13+
name: Build
14+
uses: ./.github/workflows/_build.yml
15+
release:
16+
name: GitHub Releases
17+
runs-on: ubuntu-latest
18+
timeout-minutes: 30
19+
needs: build
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v3
23+
- name: Download artifact
24+
uses: actions/download-artifact@v3
25+
with:
26+
name: ${{ needs.build.outputs.artifact_name }}
27+
path: dist/
28+
- name: Create GitHub release
29+
uses: softprops/action-gh-release@v1
30+
with:
31+
token: ${{ secrets.GH_TOKEN }}
32+
fail_on_unmatched_files: true
33+
prerelease: ${{ contains(github.ref_name, 'a') || contains(github.ref_name, 'b') || contains(github.ref_name, 'rc') }}
34+
files: dist/*
35+
pypi:
36+
name: PyPI
37+
uses: ./.github/workflows/_publish.yml
38+
needs: build
39+
with:
40+
artifact_name: ${{ needs.build.outputs.artifact_name }}
41+
secrets:
42+
registry_token: ${{ secrets.PYPI_TOKEN }}

.github/workflows/release.yml

Lines changed: 0 additions & 26 deletions
This file was deleted.

.github/workflows/version.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
name: Version
3+
4+
run-name: Cut ${{ github.event.inputs.version }}
5+
6+
on:
7+
workflow_dispatch:
8+
inputs:
9+
version:
10+
description: Version to cut
11+
required: true
12+
13+
jobs:
14+
tag:
15+
name: Tag
16+
runs-on: ubuntu-latest
17+
timeout-minutes: 30
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v3
21+
with:
22+
token: ${{ secrets.GH_TOKEN }}
23+
- name: Import GPG key
24+
uses: crazy-max/ghaction-import-gpg@v5
25+
with:
26+
git_user_signingkey: true
27+
git_commit_gpgsign: true
28+
git_committer_name: ${{ secrets.GIT_USER_NAME }}
29+
git_committer_email: ${{ secrets.GIT_USER_EMAIL }}
30+
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
31+
passphrase: ${{ secrets.GPG_PASSPHRASE }}
32+
- name: Setup
33+
uses: ./.github/actions/setup
34+
- name: Cut ${{ github.event.inputs.version }} version
35+
run: |
36+
poetry version "${{ github.event.inputs.version }}"
37+
make version

Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
all: build
2+
3+
build:
4+
@rm -rf dist
5+
@poetry build
6+
7+
version:
8+
@git add pyproject.toml
9+
@git commit -m "$$(poetry version -s)"
10+
@git tag --sign "v$$(poetry version -s)" -m "$(poetry version -s)"
11+
@git push --follow-tags
12+
13+
.PHONY: build version

0 commit comments

Comments
 (0)