-
Notifications
You must be signed in to change notification settings - Fork 0
147 lines (132 loc) · 5.2 KB
/
Copy pathpython-package.yaml
File metadata and controls
147 lines (132 loc) · 5.2 KB
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
name: cont-ops-sync-pypi
# version: 1.0.2
# Version log:
# 1.0.0: Initial version
# 1.0.1: Add the xvfb library to the actions for any graphical environements
# 1.0.2: Put the tests in a container
on:
push:
tags:
- "v*.*.*"
workflow_dispatch:
env:
CWD: "./files"
SETUP_FILE: setup.py
TAG_FILE: version.txt
IS_RELEASE: is_release.txt
MATRIX_VERSION_PUBLISHING: "3.10"
SOURCE_CODE_PATH: src/main.py
LATEST_TAG: ""
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- name: Get Latest Tag
id: get_latest_tag
run: |
cd ${{env.CWD}}
echo "Getting tags"
# git fetch --tags # Make sure to fetch the tags first
echo "Updated the list"
latest_tag=$(git tag --list "v*" | sort -rV | head -n 1)
echo "Tag list: $(git tag -l)"
echo "Latest tag = $latest_tag"
if [ "$latest_tag" == "" ]; then
echo "No tags found matching 'v*'."
latest_tag="v1.0.0"
echo "Using a default tag: $latest_tag"
else
echo "Latest Tag: $latest_tag"
fi
echo "$latest_tag" > ${{env.TAG_FILE}}
echo "LATEST_TAG=$latest_tag" >> $GITHUB_ENV
echo -e "\n\n\n\n\n\n\n\n\n"
echo "new_tag = $latest_tag"
echo "env.new_tag = ${{env.tag_file}}"
echo "cat env.new_tag = $(cat ${{env.TAG_FILE}})"
echo "env.LATEST_TAG = ${{env.LATEST_TAG}}"
echo -e "\n\n\n\n\n\n\n\n\n"
- name: Update module version in source code and builder file
run: |
cd ${{env.CWD}}
latest_tag="$(cat ${{env.TAG_FILE}})"
if [ -f ${{env.SETUP_FILE}} ]
then
echo "Updating version in ${{env.SETUP_FILE}}"
echo -e "\n\n\n\n\n\n\n\n\n"
echo "Tag: $latest_tag"
latest_tag=${latest_tag/"v"/""}
echo "Tag: $latest_tag"
sed -i "s/version='.*'/version='$latest_tag'/g" ${{env.SETUP_FILE}}
sed -i "s/self.__version__ = '.*'/self.__version__ = '$latest_tag'/g" ${{env.SOURCE_CODE_PATH}}
fi
echo "Content: $(ls)"
echo "Content of file: $(cat ${{env.SETUP_FILE}})"
echo -e "\n\n\n\n\n\n\n\n\n"
- name: Install xvfb
run: sudo apt-get install xvfb
- name: Install dependencies
run: |
cd ${{env.CWD}}
python -m pip install --upgrade pip
python -m pip install flake8 pytest
lib_packages=$(find ./*/ -name "requirements.txt" -type f)
first_requirement=$(echo $lib_packages | cut -d " " -f 1)
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ ${#first_requirements} -gt 0 ]; then pip install -r $first_requirements; fi
- name: Lint with flake8
run: |
cd ${{env.CWD}}
# 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: |
cd ${{env.CWD}}
docker run -t -e DEBIAN_FRONTEND=noninteractive -v "$(pwd)":"/home" ubuntu /bin/bash -c "
echo 'Upating ubuntu version' && \
apt update && apt upgrade -y && \
echo 'Installing required dependencies' && \
apt install -y xvfb software-properties-common && \
echo 'Adding python deadsnakes repository' && \
add-apt-repository -y ppa:deadsnakes/ppa && \
apt-get update && \
echo 'Installing required python versions (${{matrix.python-version}})' && \
apt install -y python${{matrix.python-version}} python${{matrix.python-version}}-venv python3-pip python${{matrix.python-version}}-dev && \
echo 'Setting the installed python version as the default version' && \
update-alternatives --install /usr/bin/python3 python3 /usr/bin/python${{matrix.python-version}} 1 && \
update-alternatives --install /usr/bin/python python /usr/bin/python${{matrix.python-version}} 1 && \
echo 'Entering the folder containing the code' && \
cd /home && \
echo 'Installing requirements' && \
pip3 install -r requirements.txt --break-system-packages && \
echo 'Running the tests' && \
pytest -s
"
- name: building the package
run: |
cd ${{env.CWD}}
pip install build
python -m build
# Add the following steps if you want to publish to PyPI
- name: Build and publish to PyPI
if: startsWith(github.ref, 'refs/tags/') && matrix.python-version == env.MATRIX_VERSION_PUBLISHING
run: |
cd ${{env.CWD}}
python -m build
pip install twine
twine upload dist/* --verbose
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}