-
Notifications
You must be signed in to change notification settings - Fork 0
112 lines (94 loc) · 3.22 KB
/
workflow-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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
name: package
on:
push:
branches:
- master
tags:
- '*'
pull_request:
workflow_dispatch:
env:
PIP_NO_CACHE_DIR: "off"
POETRY_VIRTUALENVS_IN_PROJECT: "true"
POETRY_NO_INTERACTION: "1"
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions: read-all
jobs:
checks:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10']
django-version: ["~=3.2.0", "~=4.0.0"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4.1.0
with:
python-version: ${{ matrix.python-version }}
- name: Setup poetry
run: |
curl -sSL "https://install.python-poetry.org" | python
echo "Adding `poetry` to `$PATH`"
echo "$HOME/.poetry/bin" >> $GITHUB_PATH
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-py${{ matrix.python-version }}-django${{ matrix.django-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
run: poetry install
- name: Install Django
run: poetry run pip install django${{ matrix.django-version }}
- name: Run checks
run: make test
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ./coverage.xml
# token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
# Releasing package, when in `master` branch or tag
release-package:
runs-on: ubuntu-latest
needs: [checks]
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v4.1.0
with:
python-version: "3.10"
- name: Setup poetry
env:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
TEST_PYPI_TOKEN: ${{ secrets.TEST_PYPI_TOKEN }}
run: |
curl -sSL "https://install.python-poetry.org" | python
echo "Adding `poetry` to `$PATH`"
echo "$HOME/.poetry/bin" >> $GITHUB_PATH
echo "Add test-pypi repo"
poetry config repositories.test-pypi https://test.pypi.org/legacy/
echo "Login"
poetry config pypi-token.pypi $PYPI_TOKEN || true
poetry config pypi-token.test-pypi $TEST_PYPI_TOKEN || true
- name: Add version to environment vars
run: |
PROJECT_VERSION=$(poetry version --short)
echo "PROJECT_VERSION=$PROJECT_VERSION" >> $GITHUB_ENV
- name: Check if tag version matches project version
if: startsWith(github.ref, 'refs/tags/')
run: |
TAG=${GITHUB_REF:10}
echo $TAG
echo $PROJECT_VERSION
if [[ "$TAG" != "$PROJECT_VERSION" ]]; then exit 1; fi
- name: Build and publish (dry-run)
if: github.actor != 'dependabot[bot]'
run: rm -rf dist && poetry publish --build --dry-run
- name: Build and publish
if: startsWith(github.ref, 'refs/tags/')
run: |
rm -rf dist && poetry publish --build
# rm -rf dist && poetry publish --build -r test-pypi