-
Notifications
You must be signed in to change notification settings - Fork 108
89 lines (74 loc) · 2.7 KB
/
paig-common-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
name: paig-common-ci
on:
push:
branches: [ "main" ]
paths:
- 'paig-common/**'
pull_request:
branches: [ "main" ]
paths:
- 'paig-common/**'
permissions:
contents: read
jobs:
build_and_test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4 # Ensure the repo is checked out
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Set sanitized branch name
run: |
# Get branch name and sanitize it
BRANCH_NAME="${GITHUB_REF_NAME//[^a-zA-Z0-9-]/-}" # Replace invalid characters with '-'
# Remove leading and trailing hyphens
BRANCH_NAME="${BRANCH_NAME##-}" # Trim leading hyphens
BRANCH_NAME="${BRANCH_NAME%%-}" # Trim trailing hyphens
echo "SANITIZED_BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_ENV
- name: Install dependencies
run: |
python3 -m pip install virtualenv
virtualenv -p python3 venv && . venv/bin/activate
pip install twine build pytest pytest-cov
pip install -r paig-common/requirements.txt
- name: Test with pytest
run: |
filepath=$PWD
. venv/bin/activate && cd paig-common/src
python3 -m pytest --cov="." --cov-report term --cov-report xml:$filepath/coverage-${{ env.SANITIZED_BRANCH_NAME }}.xml --junitxml=$filepath/junit-${{ env.SANITIZED_BRANCH_NAME }}.xml tests
- name: Upload coverage report
uses: actions/upload-artifact@v4
with:
name: coverage-report-${{ env.SANITIZED_BRANCH_NAME }}
path: coverage-${{ env.SANITIZED_BRANCH_NAME }}.xml
- name: Upload test results
uses: actions/upload-artifact@v4
with:
name: junit-results-${{ env.SANITIZED_BRANCH_NAME }}
path: junit-${{ env.SANITIZED_BRANCH_NAME }}.xml
- name: Set build version to dev
id: version
run: |
FILE=paig-common/src/paig_common/VERSION
VERSION=$(awk -F= '{gsub(/^[ \t]+|[ \t]+$/, "", $2); gsub(/^['\''"]+|['\''"]+$/, "", $2); print $2}' $FILE)
DEV_VERSION="${VERSION}+${SANITIZED_BRANCH_NAME}$(date +%Y%m%d%H%M%S)"
echo "__version__ = '${DEV_VERSION}'" > $FILE
- name: Build the wheel
run: |
. venv/bin/activate
cd paig-common
python3 -m build -w
cd ..
- name: Install created package
run: |
rm -rf venv
virtualenv -p python3 venv && . venv/bin/activate
cd paig-common
pip install dist/*.whl
- name: Upload python package
uses: actions/upload-artifact@v4
with:
name: paig-common-${{ env.SANITIZED_BRANCH_NAME }}-build
path: paig-common/dist/*.whl