From dd65249b8c397cbc36461d49af433687e9236142 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Wed, 29 Apr 2020 15:34:37 +0100 Subject: [PATCH] Add publish workflow --- .github/workflows/publish.yml | 23 ++++++++++++++++++++ .github/workflows/test-suite.yml | 2 -- scripts/publish | 36 +++++++++++++------------------- 3 files changed, 38 insertions(+), 23 deletions(-) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 000000000..473cb19b4 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,23 @@ +--- +name: Publish + +on: + push: + tags: + - '*' + +jobs: + publish: + name: "Publish release" + runs-on: "ubuntu-latest" + + steps: + - uses: "actions/checkout@v2" + - uses: "actions/setup-python@v1" + with: + python-version: 3.7 + - name: "Publish" + run: "scripts/publish" + env: + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} diff --git a/.github/workflows/test-suite.yml b/.github/workflows/test-suite.yml index 2d323e3dd..60ec0f7ec 100644 --- a/.github/workflows/test-suite.yml +++ b/.github/workflows/test-suite.yml @@ -2,8 +2,6 @@ name: Test Suite on: - push: - branches: ["master"] pull_request: branches: ["master"] diff --git a/scripts/publish b/scripts/publish index 178a6a324..6076e16f7 100755 --- a/scripts/publish +++ b/scripts/publish @@ -1,34 +1,28 @@ #!/bin/sh -e -export VERSION=`cat starlette/__init__.py | grep __version__ | sed "s/__version__ = //" | sed "s/'//g"` -export PREFIX="" +VERSION_FILE="starlette/__init__.py" + if [ -d 'venv' ] ; then - export PREFIX="venv/bin/" + PREFIX="venv/bin/" +else + PREFIX="" fi -scripts/clean +if [ ! -z "$GITHUB_ACTIONS" ]; then + git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" + git config --local user.name "GitHub Action" -if ! command -v "${PREFIX}twine" &>/dev/null ; then - echo "Unable to find the 'twine' command." - echo "Install from PyPI, using '${PREFIX}pip install twine'." - exit 1 -fi + VERSION=`grep __version__ ${VERSION_FILE} | grep -o '[0-9][^"]*'` -if ! command -v "${PREFIX}wheel" &>/dev/null ; then - echo "Unable to find the 'wheel' command." - echo "Install from PyPI, using '${PREFIX}pip install wheel'." + if [ "refs/tags/${VERSION}" != "${GITHUB_REF}" ] ; then + echo "GitHub Ref '${GITHUB_REF}' did not match package version '${VERSION}'" exit 1 + fi fi -find starlette -type f -name "*.py[co]" -delete -find starlette -type d -name __pycache__ -delete +set -x +${PREFIX}pip install twine wheel mkdocs mkdocs-material mkautodoc ${PREFIX}python setup.py sdist bdist_wheel ${PREFIX}twine upload dist/* -${PREFIX}mkdocs gh-deploy - -echo "You probably want to also tag the version now:" -echo "git tag -a ${VERSION} -m 'version ${VERSION}'" -echo "git push --tags" - -scripts/clean +${PREFIX}mkdocs gh-deploy --force