Skip to content

Commit

Permalink
twisted-alike (so similar) automatic publishing on gha (#315)
Browse files Browse the repository at this point in the history
  • Loading branch information
altendky authored Mar 20, 2021
1 parent 499c8f7 commit 7267fb5
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 11 deletions.
57 changes: 54 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: CI
on:
push:
branches: [ master ]
tags: [ "**" ]
pull_request:
branches: [ master ]

Expand Down Expand Up @@ -53,7 +54,8 @@ jobs:
test:
name: ${{ matrix.task.name}} - ${{ matrix.os.name }} ${{ matrix.python.name }}
runs-on: ${{ matrix.os.runs-on }}
needs: build
needs:
- build
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -125,6 +127,8 @@ jobs:
check:
name: ${{ matrix.task.name}} - ${{ matrix.python.name }}
runs-on: ubuntu-latest
needs:
- build
strategy:
fail-fast: false
matrix:
Expand All @@ -137,8 +141,6 @@ jobs:
task:
- name: Flake8
tox: flake8
- name: Check Manifest
tox: check-manifest
- name: Check Newsfragment
tox: check-newsfragment

Expand All @@ -147,6 +149,12 @@ jobs:
with:
fetch-depth: 0

- name: Download package files
uses: actions/download-artifact@v2
with:
name: dist
path: dist/

- name: Set up ${{ matrix.python.name }}
uses: actions/setup-python@v2
with:
Expand All @@ -160,13 +168,56 @@ jobs:
- name: Tox
run: tox -c tox.ini -e ${{ matrix.task.tox }}

pypi-publish:
# https://github.community/t/is-it-possible-to-require-all-github-actions-tasks-to-pass-without-enumerating-them/117957/4?u=graingert
name: Check tag and publish
runs-on: ubuntu-latest

needs:
- build
- test
- check
steps:
- uses: actions/checkout@v2

- name: Download package files
uses: actions/download-artifact@v2
with:
name: dist
path: dist/

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8

- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install pep517
- name: Display structure of files to be pushed
run: ls --recursive dist/

- name: Check matched tag version and branch version - on tag
if: startsWith(github.ref, 'refs/tags/')
run: python admin/check_tag_version_match.py "${{ github.ref }}"

- name: Publish to PyPI - on tag
if: startsWith(github.ref, 'refs/tags/')
uses: pypa/[email protected]
with:
password: ${{ secrets.PYPI_TOKEN }}
verbose: true

all:
name: All
runs-on: ubuntu-latest
needs:
- build
- test
- check
- pypi-publish
steps:
- name: This
shell: python
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ include CODE_OF_CONDUCT.md
include pyproject.toml
include tox.ini
include tox_build.sh
include tox_check-release.sh
recursive-include src *.rst

exclude bin
Expand Down
34 changes: 34 additions & 0 deletions admin/check_tag_version_match.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#
# Used during the release process to make sure that we release based on a
# tag that has the same version as the current twisted.__version.
#
# Designed to be conditionally called inside GitHub Actions release job.
# Tags should use PEP440 version scheme.
#
# To be called as: admin/check_tag_version_match.py refs/tags/twisted-20.3.0
#
import sys

import pep517.meta

TAG_PREFIX = "refs/tags/"

if len(sys.argv) < 2:
print("No tag check requested.")
sys.exit(0)

branch_version = pep517.meta.load(".").version
run_version = sys.argv[1]

if not run_version.startswith(TAG_PREFIX):
print("Not a twisted release tag name '{}.".format(run_version))
sys.exit(1)

run_version = run_version[len(TAG_PREFIX) :]

if run_version != branch_version:
print("Branch is at '{}' while tag is '{}'".format(branch_version, run_version))
exit(1)

print("All good. Branch and tag versions match for '{}'.".format(branch_version))
sys.exit(0)
2 changes: 1 addition & 1 deletion src/towncrier/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@

from incremental import Version

__version__ = Version("towncrier", 19, 2, 0)
__version__ = Version("towncrier", 21, 3, 0, dev=4)
__all__ = ["__version__"]
Empty file.
9 changes: 2 additions & 7 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@ deps =
commands =
flake8 src/towncrier/

[testenv:check-manifest]
skip_install = True
deps =
check_manifest
commands =
check-manifest -v

[testenv:check-newsfragment]
commands =
python -m towncrier.check
Expand Down Expand Up @@ -44,6 +37,8 @@ allowlist_externals =
changedir = {envtmpdir}
deps =
build
check-manifest>=0.44
twine
setenv =
toxinidir={toxinidir}
skip_install = true
Expand Down
10 changes: 10 additions & 0 deletions tox_build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# build the sdist

set -evx

check-manifest --verbose ${toxinidir}

python -m build --sdist --outdir ${toxinidir}/dist/ ${toxinidir}

tar -xvf ${toxinidir}/dist/*
cd *

# build the wheel from the sdist
python -m build --wheel --outdir ${toxinidir}/dist/ .
cd -

twine check ${toxinidir}/dist/*

0 comments on commit 7267fb5

Please sign in to comment.