forked from LiamBindle/PyVESC
-
Notifications
You must be signed in to change notification settings - Fork 0
169 lines (156 loc) · 6.06 KB
/
Copy pathpython-package.yml
File metadata and controls
169 lines (156 loc) · 6.06 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
name: pyvesc-pypi
on:
push:
tags:
- 'v*'
pull_request:
branches:
- main
workflow_dispatch:
env:
SETUP_FILE: setup.py
TAG_FILE: version.txt
IS_RELEASE: is_release.txt
MATRIX_VERSION_PUBLISHING: "3.10"
SOURCE_CODE_PATH: pyvesc_fix/__init__.py
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.3", "3.4", "3.5", "3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Get Latest Tag
id: get_latest_tag
run: |
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 "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 -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 -e "\n\n\n\n\n\n\n\n\n"
- name: Check if Latest Tag is a Release
id: is_release
run: |
latest_tag="$(cat ${{env.TAG_FILE}})"
is_release="false"
latest_updated_tag=$(git tag --list "v*" | sort -rV | head -n 1)
if [[ $latest_updated_tag == $latest_tag ]]; then
is_release="true"
fi
echo "$is_release" > ${{env.IS_RELEASE}}
echo -e "\n\n\n\n\n\n\n\n\n"
echo "Is_release = $is_release"
echo "env.Is_release = ${{env.is_release}}"
echo "cat env.Is_release = $(cat ${{env.is_release}})"
echo -e "\n\n\n\n\n\n\n\n\n"
- name: Increment Tag Version
id: increment_tag
run: |
is_release="$(cat ${{env.IS_RELEASE}})"
latest_tag="$(cat ${{env.TAG_FILE}})"
echo "ls = $(ls)"
echo "is_release = $is_release"
echo "latest_tag = $latest_tag"
if [[ $is_release == "true" ]]; then
# Parse the latest tag and increment the version component you want
# Example: Convert "v1.2.3" to "v1.2.4"
new_tag="${latest_tag/v/}" # Remove the leading "v"
echo "new_tag = $new_tag"
IFS='.' read -ra version <<< "$new_tag"
echo "declare -p version = $(declare -p $version)"
echo "declare -p version[0] = $(declare -p ${version[0]})"
echo "declare -p version[1] = $(declare -p ${version[1]})"
echo "declare -p version[2] = $(declare -p ${version[2]})"
echo "version[2]+1 = $(expr "${version[2]}" + 1)"
echo "version[*] = ${version[*]}"
echo "version = ${version}"
echo "#version = ${#version}"
echo "version[0] = ${version[0]}"
echo "version[1] = ${version[1]}"
echo "version[2] = ${version[2]}"
version[2]=$(expr "${version[2]}" + 1) # Increment the third version component
echo "Version = ${version[*]}"
new_tag="v${version[0]}.${version[1]}.${version[2]}"
echo "New Tag: $new_tag"
echo "$new_tag" > ${{env.TAG_FILE}}
else
echo "Latest tag is not a release. Skipping tag increment."
fi
echo -e "\n\n\n\n\n\n\n\n\n"
echo "new_tag = $new_tag"
echo "env.new_tag = ${{env.TAG_FILE}}"
echo "env.is_release = $(cat ${{env.IS_RELEASE}})"
echo "cat env.new_tag = $(cat ${{env.TAG_FILE}})"
echo "cat env.is_release = $(cat ${{env.IS_RELEASE}})"
echo -e "\n\n\n\n\n\n\n\n\n"
- name: Update module version in source code and builder file
run: |
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 dependencies
run: |
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.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: |
# pytest
- name: building the package
run: |
pip install build
python -m build
- name: Update author
run: |
git config --local user.name "${{secrets.USER_NAME_E}}"
git config --local user.email "${{secrets.USER_EMAIL_E}}"
# Add the following steps if you want to publish to PyPI
- name: Build and publish to PyPI
if: matrix.python-version == env.MATRIX_VERSION_PUBLISHING
run: |
python -m build
pip install twine
twine upload --verbose dist/*
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}