-
Notifications
You must be signed in to change notification settings - Fork 2
152 lines (129 loc) · 4.75 KB
/
ci-cd.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File: .github/workflows/release.yml
# This workflow handles:
# 1. For Pull Requests:
# - Runs all tests
# - Verifies documentation builds
# 2. For Pre-releases:
# - Runs all tests
# - Builds documentation
# - Deploys documentation to GitHub Pages
# - Publishes package to PyPI
# - If everything passes:
# - Updates the release to a full release (removes pre-release status)
name: Test, Docs & Publish
on:
# Run on pull requests to main branch to verify changes
pull_request:
branches:
- main
# Run when a new release is published to deploy docs and package
release:
types: [published]
permissions:
contents: write # Needed to update release status
pages: write # Needed for docs deployment
id-token: write # Needed for docs deployment
jobs:
test:
if: github.event_name == 'pull_request' || (github.event_name == 'release' && github.event.release.prerelease == true)
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8', '3.13'] # Test on limit versions (3.8 and latest)
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch full repository history, including all tags
- name: Verify available tags
run: git tag -l
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: "pip" # Enables automatic pip caching
# Cache test data
- name: Cache test data
uses: actions/cache@v4
with:
path: data/
key: snputils-test-data-${{ hashFiles('snputils/snp/io/read/__test__/conftest.py') }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install tox tox-gh-actions
- name: Run tests
run: python -m tox
build-docs:
# Only build documentation after tests have passed
needs: test
if: needs.test.result == 'success' && (github.event_name == 'pull_request' || (github.event_name == 'release' && github.event.release.prerelease == true))
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch full repository history, including all tags
- name: Verify available tags
run: git tag -l
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.13' # Ensure this is the latest Python version so the cached deps are used
cache: 'pip'
- name: Install package with docs dependencies
run: |
python -m pip install --upgrade pip
python -m pip install '.[docs]'
# Build documentation and verify it builds correctly
# DOC_ALLOW_EXEC=1 allows executing code examples in docstrings
- name: Build documentation
run: DOC_ALLOW_EXEC=1 pdoc --docformat google -o docs/ snputils
# Upload Pages artifact if this is a release
- name: Upload Pages artifact
if: github.event_name == 'release'
uses: actions/upload-pages-artifact@v3
with:
path: docs/
deploy:
needs: [test, build-docs]
if: needs.build-docs.result == 'success' && github.event_name == 'release' && github.event.release.prerelease == true
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
# Deploy documentation to GitHub Pages
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
# Build and publish to PyPI
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch full repository history, including all tags
- name: Verify available tags
run: git tag -l
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.13' # Ensure this is the latest Python version so the cached deps are used
cache: 'pip'
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
python -m pip install build
- name: Build package
run: python -m build
- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
# Update the release to a full release and mark it as latest
- name: Mark Release as Final and Latest
if: success()
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release edit ${{ github.event.release.tag_name }} --prerelease=false --latest