Skip to content

Commit 74a4fba

Browse files
authored
Merge pull request #367 from vil02/prepare_for_automated_publish
chore: automate publishing
2 parents f2a5bb7 + 7238f6a commit 74a4fba

File tree

4 files changed

+108
-0
lines changed

4 files changed

+108
-0
lines changed

.github/workflows/create_tag.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
name: create_tag
3+
4+
'on':
5+
workflow_dispatch:
6+
push:
7+
branches:
8+
- master
9+
10+
jobs:
11+
create_tag:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
with:
18+
token: ${{secrets.PUSH_TOKEN}}
19+
20+
- name: Set up Python
21+
uses: actions/setup-python@v5
22+
with:
23+
python-version: 3.11
24+
25+
- name: Set up Poetry
26+
uses: snok/install-poetry@v1
27+
28+
- name: Tag and push
29+
run: |
30+
./create_tag.sh
31+
...

.github/workflows/publish.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
name: publish
3+
4+
'on':
5+
workflow_dispatch:
6+
release:
7+
types:
8+
- created
9+
10+
jobs:
11+
publish:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
18+
- name: Set up Python
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: 3.11
22+
23+
- name: Set up Poetry
24+
uses: snok/install-poetry@v1
25+
26+
- name: Publish to PyPi
27+
env:
28+
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }}
29+
run: poetry publish --build
30+
...

bump_version.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
if [[ "$#" -ne 1 ]]; then
6+
echo "Provide one argument."
7+
exit 1
8+
fi
9+
10+
VERSION_ARG=$1
11+
readonly VERSION_ARG
12+
13+
poetry version "${VERSION_ARG}"
14+
15+
16+
NEW_VERSION=$(poetry version --short)
17+
readonly NEW_VERSION
18+
19+
git add pyproject.toml
20+
git commit -m "chore: bump version to \`${NEW_VERSION}\`"

create_tag.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
current_branch=$(git branch --show-current)
6+
readonly current_branch
7+
if [[ "${current_branch}" != "master" ]]; then
8+
echo "You are not on the master."
9+
exit 1
10+
fi
11+
12+
current_version=$(poetry version --short)
13+
readonly current_version
14+
if [[ -z "${current_version}" ]]; then
15+
echo "Failed to get the current version from poetry."
16+
exit 1
17+
fi
18+
19+
tag_name="v${current_version}"
20+
readonly tag_name
21+
if git ls-remote --tags origin | grep "refs/tags/${tag_name}"; then
22+
echo "Tag ${tag_name} already exists."
23+
exit 0
24+
fi
25+
26+
git tag "${tag_name}"
27+
git push origin tag "${tag_name}"

0 commit comments

Comments
 (0)