Skip to content

Commit

Permalink
fix until tag
Browse files Browse the repository at this point in the history
  • Loading branch information
getzze committed Nov 12, 2024
1 parent 6bbed23 commit fdfd224
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 42 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/prepare-release-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ on:
# Set permissions at the job level.
permissions: {}

env:
FORCE_COLOR: "1"

jobs:
build:
runs-on: ubuntu-latest
Expand Down
34 changes: 16 additions & 18 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ permissions:
contents: read
id-token: write

env:
FORCE_COLOR: "1"

# https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/
jobs:
# Always build & lint package.
Expand Down Expand Up @@ -46,27 +49,21 @@ jobs:
id-token: write
contents: write
steps:
- name: Fetch version
id: version
run: |
VERSION=${GITHUB_HEAD_REF#release-}
echo Version: $VERSION
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Push tag with version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Tag the commit
run: |
git tag --annotate --message="Release version ${{ VERSION }}" ${{ VERSION }} ${{ github.sha }}
git push origin ${{ VERSION }}
- name: Tag the commit
run: |
RELEASE_VERSION=${GITHUB_HEAD_REF#release-}
echo Release version: $RELEASE_VERSION
git config user.name 'subliminal bot'
git config user.email diaoulael@gmail.com
git tag --annotate --message="Release version $RELEASE_VERSION" $RELEASE_VERSION ${{ github.sha }}
git push origin $RELEASE_VERSION
github-release:
name: Make a GitHub Release and upload Python package.
name: Make a GitHub Release.
needs: [build-package]
if: github.repository == 'Diaoul/subliminal' && startsWith(github.ref, 'refs/tags/') # only publish a Github release on push tag
runs-on: ubuntu-latest
Expand All @@ -93,6 +90,7 @@ jobs:
draft: true

publish-to-pypi:
name: Publish package to pypi.
needs: [build-package]
environment:
name: pypi
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ name = "subliminal"
package = "subliminal"
directory = "changelog.d"
filename = "HISTORY.rst"
title_format = "`version <https://github.com/Diaoul/subliminal/tree/{version}>`_ - {project_date}"
title_format = "`v{version} <https://github.com/Diaoul/subliminal/tree/{version}>`_ ({project_date})"
issue_format = "`#{issue} <https://github.com/Diaoul/subliminal/issues/{issue}>`_"
underlines = ["^", "-", "~"]

Expand Down
28 changes: 16 additions & 12 deletions scripts/prepare-release-pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,20 @@ def login(token: str) -> Repository:
def find_next_version(base_branch: str, *, is_major: bool, is_minor: bool, prerelease: str) -> str:
"""Find the next version, being a major, minor or patch bump."""
output = check_output(['git', 'tag'], encoding='UTF-8')
valid_versions = []
valid_versions: list[tuple[int, ...]] = []
for v in output.splitlines():
m = re.match(r'\d.\d.\d+$', v.strip())
# Match 'major.minor.patch', do not match tags of pre-release versions
m = re.match(r'v?(\d+)\.(\d+)\.(\d+)$', v.strip())
if m:
valid_versions.append(tuple(int(x) for x in v.split('.')))
valid_versions.append(tuple(int(x) for x in m.groups()))

valid_versions.sort()
last_version = valid_versions[-1]

print(f'Current version from git tag: {Fore.CYAN}{last_version}')
bump_str = 'major' if is_major else 'minor' if is_minor else 'patch'
print(f'Bump {bump_str} version')

if is_major:
return f'{last_version[0]+1}.0.0{prerelease}'
if is_minor:
Expand Down Expand Up @@ -109,14 +114,14 @@ def prepare_release_pr(base_branch: str, bump: str, token: str, prerelease: str)

release_branch = f'release-{version}'

# run(
# ['git', 'config', 'user.name', 'pytest bot'],
# check=True,
# )
# run(
# ['git', 'config', 'user.email', 'pytestbot@gmail.com'],
# check=True,
# )
run(
['git', 'config', 'user.name', 'subliminal bot'],
check=True,
)
run(
['git', 'config', 'user.email', 'diaoulael@gmail.com'],
check=True,
)

run(
['git', 'checkout', '-b', release_branch, f'origin/{base_branch}'],
Expand Down Expand Up @@ -144,7 +149,6 @@ def prepare_release_pr(base_branch: str, bump: str, token: str, prerelease: str)
version,
template_name,
release_branch, # doc_version
'--skip-check-links',
]
print('Running', ' '.join(cmdline))
run(
Expand Down
22 changes: 11 additions & 11 deletions scripts/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,20 @@ def regen(version: str) -> None:

def fix_formatting() -> None:
"""Runs pre-commit in all files to ensure they are formatted correctly."""
print(f'{Fore.CYAN}[generate.fix_linting] {Fore.RESET}Fixing formatting using pre-commit')
print(f'{Fore.CYAN}[generate.fix_formatting] {Fore.RESET}Fixing formatting using pre-commit')
check_call(['tox', '-e', 'pre-commit'])


def check_links() -> None:
"""Runs sphinx-build to check links."""
print(f'{Fore.CYAN}[generate.check_links] {Fore.RESET}Checking links')
check_call(['tox', '-e', 'docs-checklinks'])
def check_docs() -> None:
"""Runs sphinx-build to check docs."""
print(f'{Fore.CYAN}[generate.check_docs] {Fore.RESET}Checking docs')
check_call(['tox', '-e', 'docs'])


def changelog(version: str, *, write_out: bool = False) -> None:
"""Call towncrier to generate the changelog."""
addopts = [] if write_out else ['--draft']
check_call(['towncrier', '--yes', '--version', version, *addopts])
check_call(['towncrier', 'build', '--yes', '--version', version, *addopts])


def bump_version(version: str) -> None:
Expand All @@ -99,14 +99,14 @@ def bump_version(version: str) -> None:
file.open('w').write(new_content)


def pre_release(version: str, template_name: str, doc_version: str, *, skip_check_links: bool) -> None:
def pre_release(version: str, template_name: str, doc_version: str, *, skip_check_docs: bool) -> None:
"""Generates new docs and update the version."""
# announce(version, template_name, doc_version)
# regen(version)
changelog(version, write_out=True)
fix_formatting()
# if not skip_check_links:
# check_links()
if not skip_check_docs:
check_docs()
bump_version(version)

msg = f'Prepare release version {version}'
Expand Down Expand Up @@ -134,13 +134,13 @@ def main() -> None: # noqa: D103
help='For prereleases, the version to link to in the docs',
default='',
)
parser.add_argument('--skip-check-links', action='store_true', default=False)
parser.add_argument('--skip-check-docs', help='Skip doc tests', action='store_true', default=False)
options = parser.parse_args()
pre_release(
options.version,
options.template_name,
options.doc_version,
skip_check_links=options.skip_check_links,
skip_check_docs=options.skip_check_docs,
)


Expand Down

0 comments on commit fdfd224

Please sign in to comment.