-
Notifications
You must be signed in to change notification settings - Fork 0
92 lines (86 loc) · 2.63 KB
/
cicd.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
name: Publish
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.10.13
- name: Install dependencies
uses: py-actions/py-dependency-install@v4
- name: Test with pytest and coverage
run: |
coverage run --source=snapshooter -m pytest
coverage xml
coverage html
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4.0.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: jeromerg/snapshooter
publish:
name: Publish
runs-on: ubuntu-latest
# only run on push event (not on pull_request event)
if: github.event_name == 'push'
permissions:
id-token: write
contents: write
steps:
- name: Configure Git
run: |
git config --global user.name 'github-actions'
git config --global user.email 'github-actions@github.com'
- name: Checkout files
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.10.13
- name: Set Version
run: |
# read snapshooter/__init__.py
# ... and extract __version__ = '0.1.0'
VERSION=$(grep -oP '__version__ = "\K[^"]+' snapshooter/__init__.py)
# extract major, minor, build
MAJOR=$(echo $VERSION | cut -d. -f1)
MINOR=$(echo $VERSION | cut -d. -f2)
BUILD=$(echo $VERSION | cut -d. -f3)
# replace build with github run number
VERSION=$MAJOR.$MINOR.$GITHUB_RUN_NUMBER
# path the version in __init__.py
sed -i "s/__version__ = .*/__version__ = '$VERSION'/" snapshooter/__init__.py
# export the version to subsequent steps
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "VERSION=$VERSION"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Prepare distribution
run: |
python setup.py sdist bdist_wheel
- name: Publish Release to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
- name: Create and Push Tag
run: |
TAG="v$VERSION"
git tag $TAG
git push origin $TAG
- name: Publish Release to GitHub
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.VERSION }}
release_name: Release ${{ env.VERSION }}
draft: false
prerelease: false