-
Notifications
You must be signed in to change notification settings - Fork 20
74 lines (64 loc) · 2.49 KB
/
Publish-Package.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
name: Publish Package
on:
release:
types: [released]
env:
# Versions are also listed in PR.yml
POETRY_VERSION: 1.2.2
PYTHON_VERSION: 3.9 # Use latest
jobs:
publish_package:
name: Publish Package
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.release.target_commitish }} # This is the branch the release was created from. Normally main, but can be a dev branch
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token
fetch-depth: 0 # otherwise, you will failed to push refs to dest repo
- uses: actions/setup-python@v2
with:
python-version: ${{ env.PYTHON_VERSION }}
- uses: Gr1N/setup-poetry@v8
with:
poetry-version: ${{ env.POETRY_VERSION }}
# @TODO: This is a workaround for there not being a way to check the lock file
# See: https://github.com/python-poetry/poetry/issues/453
- name: Check for lock changes
run: |
poetry lock --check
- uses: actions/cache@v2
with:
path: ~/.cache/pypoetry/virtualenvs
key: ${{ runner.os }}-poetry-${{ hashFiles('poetry.lock') }}
- name: Install the Package
run: poetry install
- name: Lint the Code
run: poetry run ni-python-styleguide lint
- name: Run tests
run: poetry run pytest -v
# If the version is 0.1.0-alpha.0, this will set the version to 0.1.0
- name: Promote package version to release
run: |
poetry version patch
- name: Build Python package and publish to PyPI
if: ${{ github.event.release.target_commitish == 'main' }}
run: |
poetry publish --build --username __token__ --password ${{ secrets.PYPI_TOKEN}}
- name: Bump poetry version to next alpha version
run: |
poetry version prepatch
- name: Commit files
if: ${{ github.event.release.target_commitish == 'main' }}
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git pull --tags -f
git commit -m "Bump package version" -a
- name: Push changes
if: ${{ github.event.release.target_commitish == 'main' }}
uses: CasperWA/push-protected@v2
with:
token: ${{ secrets.ADMIN_PAT }}
branch: ${{ github.event.release.target_commitish }}
unprotect_reviews: true