Skip to content

Add GitHub release action to upload to PyPI & create GitHub release #980

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Release

on:
push:
tags:
- '*'

jobs:
build:
if: github.repository == 'typeddjango/django-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__
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a comment: why __token__?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The username is just __token__ for an API token, not sure if you want to have that comment in the file.

See: https://packaging.python.org/en/latest/specifications/pypirc/#using-a-pypi-token

password: ${{ secrets.PYPI_API_TOKEN }}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This secret will need to be set up in the repo or in the org (Org would be best to allow each of the stub packages to use it)


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/django-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`,
})