From 6eeec9dd6113ad9c301212dfdef4228ec8b0921a Mon Sep 17 00:00:00 2001 From: "Terence D. Honles" Date: Tue, 7 Jun 2022 10:35:37 -0700 Subject: [PATCH] Add GitHub release action to upload to PyPI & create GitHub release --- .github/workflows/release.yml | 72 +++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..1dac81986 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,72 @@ +name: Release + +on: + push: + tags: + - '*' + +jobs: + build: + if: github.repository == 'typeddjango/djangorestframework-stubs' + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-python@v3 + with: + python-version: '3.9' + + - name: Install dependencies + run: | + python -m pip install -U pip + python -m pip install -U setuptools twine wheel + + - name: Build package + run: | + python setup.py --version + python setup.py sdist bdist_wheel + + - name: Publish package to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + user: __token__ + password: ${{ secrets.PYPI_API_TOKEN }} + + print_hash: true + + - name: Create release + uses: actions/github-script@v6 + with: + script: | + const tagName = context.ref.replace(/^refs\/tags\//, ''); + const release = await github.rest.repos.createRelease({ + owner: context.repo.owner, + repo: context.repo.repo, + tag_name: tagName, + name: `Release ${tagName.replace(/^v/, '')}`, + }); + + if (release.status < 200 || release.status >= 300) { + core.setFailed(`Could not create release for tag '${tagName}'`); + return; + } + + # https://github.community/t/run-github-actions-job-only-if-previous-job-has-failed/174786/2 + create-issue-on-failure: + name: Create an issue if release failed + runs-on: ubuntu-latest + needs: [build] + if: ${{ github.repository == 'typeddjango/djangorestframework-stubs' && always() && needs.build.result == 'failure' }} + permissions: + issues: write + steps: + - uses: actions/github-script@v6 + with: + script: | + await github.rest.issues.create({ + owner: context.repo.owner, + repo: context.repo.repo, + title: `Release failure on ${new Date().toDateString()}`, + body: `Details: https://github.com/${context.repo.owner}/${context.repo.repo}/actions/workflows/release.yml`, + })