|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - '*' |
| 7 | + |
| 8 | +jobs: |
| 9 | + build: |
| 10 | + if: github.repository == 'typeddjango/django-stubs' |
| 11 | + runs-on: ubuntu-latest |
| 12 | + |
| 13 | + steps: |
| 14 | + - uses: actions/checkout@v3 |
| 15 | + |
| 16 | + - uses: actions/setup-python@v3 |
| 17 | + with: |
| 18 | + python-version: '3.9' |
| 19 | + |
| 20 | + - name: Install dependencies |
| 21 | + run: | |
| 22 | + python -m pip install -U pip |
| 23 | + python -m pip install -U setuptools twine wheel |
| 24 | +
|
| 25 | + - name: Build package |
| 26 | + run: | |
| 27 | + python setup.py --version |
| 28 | + python setup.py sdist bdist_wheel |
| 29 | +
|
| 30 | + - name: Publish package to PyPI |
| 31 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 32 | + with: |
| 33 | + user: __token__ |
| 34 | + password: ${{ secrets.PYPI_API_TOKEN }} |
| 35 | + |
| 36 | + print_hash: true |
| 37 | + |
| 38 | + - name: Create release |
| 39 | + uses: actions/github-script@v6 |
| 40 | + with: |
| 41 | + script: | |
| 42 | + const tagName = context.ref.replace(/^refs\/tags\//, ''); |
| 43 | + const release = await github.rest.repos.createRelease({ |
| 44 | + owner: context.repo.owner, |
| 45 | + repo: context.repo.repo, |
| 46 | + tag_name: tagName, |
| 47 | + name: `Release ${tagName.replace(/^v/, '')}`, |
| 48 | + }); |
| 49 | +
|
| 50 | + if (release.status < 200 || release.status >= 300) { |
| 51 | + core.setFailed(`Could not create release for tag '${tagName}'`); |
| 52 | + return; |
| 53 | + } |
| 54 | +
|
| 55 | + # https://github.community/t/run-github-actions-job-only-if-previous-job-has-failed/174786/2 |
| 56 | + create-issue-on-failure: |
| 57 | + name: Create an issue if release failed |
| 58 | + runs-on: ubuntu-latest |
| 59 | + needs: [build] |
| 60 | + if: ${{ github.repository == 'typeddjango/django-stubs' && always() && needs.build.result == 'failure' }} |
| 61 | + permissions: |
| 62 | + issues: write |
| 63 | + steps: |
| 64 | + - uses: actions/github-script@v6 |
| 65 | + with: |
| 66 | + script: | |
| 67 | + await github.rest.issues.create({ |
| 68 | + owner: context.repo.owner, |
| 69 | + repo: context.repo.repo, |
| 70 | + title: `Release failure on ${new Date().toDateString()}`, |
| 71 | + body: `Details: https://github.com/${context.repo.owner}/${context.repo.repo}/actions/workflows/release.yml`, |
| 72 | + }) |
0 commit comments