-
Notifications
You must be signed in to change notification settings - Fork 26
152 lines (128 loc) · 4.07 KB
/
ci.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
name: Test and Publish
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
# Build the package
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install python
uses: actions/setup-python@v3
with:
python-version: '3.9'
- name: Install poetry
uses: Gr1N/setup-poetry@v8
- name: Build package
run: poetry build
- name: Upload built package
uses: actions/upload-artifact@v3
with:
name: dist
path: dist/
retention-days: 1
# Run pytest using built package
test:
needs: build
runs-on: ubuntu-latest
strategy:
matrix:
python: ["3.8", "3.9", "3.10"]
group: [1, 2, 3, 4, 5]
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Install python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}
cache: 'pip'
cache-dependency-path: "poetry.lock"
- name: Download built package
uses: actions/download-artifact@v3
with:
name: dist
- name: Install summit and pytest
shell: bash
run: |
WHL_NAME=$(ls summit-*.whl)
pip install ${WHL_NAME}[experiments,entmoot] pytest pytest-split
- name: Run tests
shell: bash
run: PY_IGNORE_IMPORTMISMATCH=1 pytest --doctest-modules --disable-warnings --ignore=experiments --splits 5 --group ${{ matrix.group }} --splitting-algorithm least_duration
# Publish to pypi on version change
# This is based on https://github.com/coveooss/pypi-publish-with-poetry
publish:
needs: test
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Install python
uses: actions/setup-python@v2
with:
python-version: '3.9'
- name: Download built package
uses: actions/download-artifact@v3
with:
name: dist
path: dist/
- name: Install poetry
uses: Gr1N/setup-poetry@v8
- name: Install coveo-pypi-cli
run: pip install coveo-pypi-cli
- name: Determine the version for this release from the build
id: current
run: |
BUILD_VER="$(ls dist/summit-*.tar.gz)"
echo "Path: $BUILD_VER"
if [[ $BUILD_VER =~ (summit-)([^,][0-9.]{4}) ]]; then
echo "::set-output name=version::${BASH_REMATCH[2]}"
echo "Version of build: ${BASH_REMATCH[2]}"
else
echo "No version found found"
fi
- name: Get latest published version
id: published
run: |
PUB_VER="$(pypi current-version summit)"
echo "::set-output name=version::$PUB_VER"
echo "Latest published version: $PUB_VER"
- name: Publish to pypi if new version
if: (steps.current.outputs.version != steps.published.outputs.version)
shell: bash
run: |
poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }}
if [[ '${{ github.ref_name }}' == 'main' ]]; then
poetry publish
else
echo "Dry run of publishing the package"
poetry publish --dry-run
fi
- name: Tag repository
shell: bash
id: get-next-tag
if: (steps.current.outputs.version != steps.published.outputs.version)
run: |
TAG_NAME=${{ steps.current.outputs.version }}
echo "::set-output name=tag-name::$TAG_NAME"
echo "This release will be tagged as $TAG_NAME"
git config user.name "github-actions"
git config user.email "actions@users.noreply.github.com"
git tag --annotate --message="Automated tagging system" $TAG_NAME ${{ github.sha }}
- name: Push the tag
if: (steps.current.outputs.version != steps.published.outputs.version)
env:
TAG_NAME: ${{ steps.current.outputs.version }}
run: |
if [[ ${{ github.ref_name }} == 'main' ]]; then
git push origin $TAG_NAME
else
echo "If this was the main branch, I would push a new tag named $TAG_NAME"
fi