Skip to content

Commit 8f5224f

Browse files
authored
Create py2-py3-packages-ci.yml
1 parent 2058ff9 commit 8f5224f

File tree

1 file changed

+183
-0
lines changed

1 file changed

+183
-0
lines changed
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- "*"
7+
pull_request:
8+
branches:
9+
- "*"
10+
release:
11+
types: [published]
12+
13+
jobs:
14+
tests:
15+
name: Run unit tests
16+
runs-on: ubuntu-latest
17+
strategy:
18+
matrix:
19+
python-version: [2.7]
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v2
23+
- name: Set up Python ${{ matrix.python-version }}
24+
uses: actions/setup-python@v2
25+
with:
26+
python-version: ${{ matrix.python-version }}
27+
- name: Install dependencies
28+
run: |
29+
python -m pip install pip -U
30+
pip install tox codecov
31+
- name: Set TOXENV
32+
run: |
33+
python_version="${{ matrix.python-version }}"
34+
py_version="${python_version/./}"
35+
branch=(`[[ 'refs/head/master' == ${{ github.ref }} ]] && echo 'master' || echo 'dev'`)
36+
TOXENV="py$py_version-$branch"
37+
echo $TOXENV
38+
echo "TOXENV=$TOXENV" >> $GITHUB_ENV
39+
- name: Run tox
40+
run: tox
41+
- name: Upload coverage report
42+
uses: codecov/codecov-action@v1
43+
with:
44+
file: .coverage
45+
fail_ci_if_error: true
46+
verbose: true
47+
pre-commit:
48+
name: Run pre-commit
49+
runs-on: ubuntu-latest
50+
steps:
51+
- name: Checkout code
52+
uses: actions/checkout@v2
53+
- name: Set up Python 3.7
54+
uses: actions/setup-python@v2
55+
with:
56+
python-version: 3.7
57+
- name: Install dependencies
58+
run: |
59+
python -m pip install pip -U
60+
pip install tox
61+
- name: Run pre-commit
62+
env:
63+
TOXENV: pre-commit
64+
run: tox
65+
build:
66+
name: Build package
67+
runs-on: ubuntu-latest
68+
steps:
69+
- name: Checkout code
70+
uses: actions/checkout@v2
71+
- name: Set up Python 2.7
72+
uses: actions/setup-python@v2
73+
with:
74+
python-version: 2.7
75+
- name: Install dependencies
76+
run: |
77+
python -m pip install pip -U
78+
pip install tox
79+
- name: Build
80+
env:
81+
TOXENV: build
82+
run: tox
83+
check-version:
84+
name: Check version
85+
# only for PRs in master
86+
if: ${{ github.base_ref == 'master' }}
87+
runs-on: ubuntu-latest
88+
steps:
89+
- name: Checkout code
90+
uses: actions/checkout@v2
91+
- name: Check version
92+
run: |
93+
git clone https://github.com/${{ github.repository }}.git ${{ github.repository }}
94+
cd ${{ github.repository }}
95+
git checkout -qf ${{ github.head_ref }}
96+
! git diff --exit-code --quiet origin/master version.txt
97+
deploy-to-test-pypi:
98+
needs: [tests, pre-commit, build]
99+
if: ${{ github.ref == 'refs/heads/dev' && github.event_name == 'push' }}
100+
runs-on: ubuntu-latest
101+
steps:
102+
- name: Checkout code
103+
uses: actions/checkout@v2
104+
- name: Set up Python 3.7
105+
uses: actions/setup-python@v2
106+
with:
107+
python-version: 3.7
108+
- name: Install dependencies
109+
run: |
110+
python -m pip install pip -U
111+
pip install tox
112+
- name: Add id to a package version
113+
run: sed -i -E "s/^([0-9]+\.[0-9]+\.[0-9]+)$/\1.${{ github.run_number }}/" version.txt
114+
- name: Build
115+
env:
116+
TOXENV: build
117+
run: tox
118+
- name: Publish
119+
uses: pypa/gh-action-pypi-publish@v1.4.1
120+
with:
121+
user: __token__
122+
password: ${{ secrets.TEST_PYPI_TOKEN }}
123+
repository_url: https://test.pypi.org/legacy/
124+
create-gh-release:
125+
needs: [tests, pre-commit, build]
126+
if: ${{ github.ref == 'refs/heads/master' && github.event_name == 'push' }}
127+
runs-on: ubuntu-latest
128+
steps:
129+
- name: Checkout code
130+
uses: actions/checkout@v2
131+
- name: Set up Python 3.7
132+
uses: actions/setup-python@v2
133+
with:
134+
python-version: 3.7
135+
- name: Install dependencies
136+
run: |
137+
python -m pip install pip -U
138+
pip install tox
139+
- name: Build
140+
env:
141+
TOXENV: build
142+
run: tox
143+
- name: Set envs
144+
run: |
145+
version="$(cat version.txt | tr -d ' \t\n\r')"
146+
repo_owner=${{ github.repository }}
147+
index=`expr index "$repo_owner" /`
148+
repo=${repo_owner:index}
149+
echo "TAG=$version" >> $GITHUB_ENV
150+
echo "REPO=$repo" >> $GITHUB_ENV
151+
- name: Create GitHub release
152+
uses: ncipollo/release-action@v1
153+
with:
154+
token: ${{ secrets.GITHUB_TOKEN }}
155+
artifacts: "dist/*"
156+
draft: true
157+
name: ${{ env.REPO }} ${{ env.TAG }}
158+
tag: ${{ env.TAG }}
159+
commit: master
160+
deploy-to-pypi:
161+
needs: [tests, pre-commit, build]
162+
if: startsWith(github.ref, 'refs/tags/')
163+
runs-on: ubuntu-latest
164+
steps:
165+
- name: Checkout code
166+
uses: actions/checkout@v2
167+
- name: Set up Python 3.7
168+
uses: actions/setup-python@v2
169+
with:
170+
python-version: 3.7
171+
- name: Install dependencies
172+
run: |
173+
python -m pip install pip -U
174+
pip install tox
175+
- name: Build
176+
env:
177+
TOXENV: build
178+
run: tox
179+
- name: Publish
180+
uses: pypa/gh-action-pypi-publish@v1.4.1
181+
with:
182+
user: __token__
183+
password: ${{ secrets.PYPI_TOKEN }}

0 commit comments

Comments
 (0)