-
Notifications
You must be signed in to change notification settings - Fork 26
130 lines (120 loc) · 4.52 KB
/
main.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# This workflow will:
# 1. Build the docs using Sphinx and any errors in the build process are bubbled up as Github status checks
# 2. Install Python dependencies, run tests and lint with a variety of Python versions
# 3. If commit is tagged with "vX.Y.Z", create a release
# 4. When release is created, upload Package using Twine
# 5. When release is created, build docs using Sphinx and push changes to this project gh-pages branch
# For more information see:
# 1. https://github.com/ammaraskar/sphinx-action
# 2. https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
# 3. https://github.com/actions/create-release
# 4. https://github.com/grst/python-ci-versioneer
name: Test and deploy
on: [push, pull_request]
jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ammaraskar/sphinx-action@master
with:
docs-folder: "docs/"
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
# OSRM routing is too expensive to test on Github Actions.
# please test this function locally.
pytest -k 'not test_osrm_matrix'
release:
needs: [docs, build]
if: |
(github.event_name == 'push' && startsWith(github.ref, 'refs/tags')) ||
(github.event_name == 'release' && contains(github.event.action, 'published'))
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Create Release
id: create_release
uses: actions/create-release@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is automatic
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
deploy:
needs: release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Autobump version
run: |
export PATH=/home/runner/.local/bin/:$PATH
VERSION=$( echo $GITHUB_REF | /bin/sed 's#.*/v##' )
SETUP_PLACEHOLDER='__version__ = "0.dev0"'
SETUP_FILE='setup.py'
DOCS_PLACEHOLDER='__version__'
DOCS_CONF_FILE='docs/source/conf.py'
grep "$PLACEHOLDER" "$SETUP_FILE"
/bin/sed -i "s/$SETUP_PLACEHOLDER/__version__ = \"${VERSION}\"/g" "$SETUP_FILE"
grep "$PLACEHOLDER" "$DOCS_CONF_FILE"
/bin/sed -i "s/$DOCS_PLACEHOLDER/${VERSION}/" "$DOCS_CONF_FILE"
shell: bash
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install setuptools wheel
- name: Build a binary wheel and a source tarball
run: |
python setup.py sdist bdist_wheel
- name: Publish distribution to PyPi
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.PYPI_API_TOKEN }}
- uses: ammaraskar/sphinx-action@master
with:
docs-folder: "docs/"
- name: Commit documentation changes
run: |
git clone https://github.com/EL-BID/urbanpy.git --branch gh-pages --single-branch gh-pages
cp -r docs/build/html/* gh-pages/
cd gh-pages
git config --local user.email "claudio.rtega2701@gmail.com"
git config --local user.name "Claudio Ortega"
git add .
git commit -m "Update documentation" -a || true
# The above command will fail if no changes were present, so we ignore
# the return code.
- name: Push changes
uses: ad-m/github-push-action@master
with:
branch: gh-pages
directory: gh-pages
github_token: ${{ secrets.GITHUB_TOKEN }}