-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b118994
commit 9bfd692
Showing
2 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from github import Github | ||
import os | ||
import re | ||
|
||
# Caminho para o diretório atual do script | ||
script_dir = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
# Caminho para o setup.py relativo ao diretório do script | ||
setup_path = os.path.join(script_dir, "../../setup.py") | ||
|
||
# Leitura da versão do setup.py | ||
with open(setup_path, "r") as f: | ||
setup_contents = f.read() | ||
|
||
match = re.search(r"# Version: ([^\n]+)", setup_contents) | ||
if match: | ||
setup_version = match.group(1) | ||
else: | ||
raise ValueError("Could not find version in setup.py") | ||
|
||
# Acessa o repositório atual | ||
g = Github(os.getenv("GITHUB_TOKEN")) | ||
repo = g.get_repo(os.getenv("GITHUB_REPOSITORY")) | ||
|
||
# Busca a última release | ||
releases = repo.get_releases() | ||
latest_release = next((release for release in releases), None) | ||
|
||
# Se a versão do setup.py for diferente da última release, cria uma nova release | ||
if latest_release is None or latest_release.tag_name != setup_version: | ||
repo.create_git_ref(ref=f"refs/tags/{setup_version}", sha=os.getenv("GITHUB_SHA")) | ||
repo.create_git_release( | ||
tag=setup_version, | ||
name=f"Release {setup_version}", | ||
message="", | ||
draft=False, | ||
prerelease=False, | ||
target_commitish=os.getenv("GITHUB_SHA"), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: Create Release and Upload Python Package | ||
|
||
on: | ||
push: | ||
paths: | ||
- "setup.py" | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out code | ||
uses: actions/checkout@v2 | ||
|
||
- 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 PyGithub | ||
pip install twine | ||
pip install build | ||
- name: Create Release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: python .github/scripts/create_release.py | ||
|
||
- name: Build package | ||
run: python -m build | ||
|
||
- name: Check if version exists | ||
run: | | ||
python -m twine check dist/* | ||
if python -m twine check dist/* | grep "already exists"; then | ||
echo "Version already exists, skipping publish step" | ||
exit 0 | ||
fi | ||
- name: Publish package | ||
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 | ||
with: | ||
user: __token__ | ||
password: ${{ secrets.PYPI_API_TOKEN }} |