-
-
Notifications
You must be signed in to change notification settings - Fork 3
141 lines (128 loc) · 5.05 KB
/
test-coverage.yml
File metadata and controls
141 lines (128 loc) · 5.05 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
name: Test Coverage
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
test:
runs-on: ubuntu-latest
permissions:
contents: write
actions: write # Explicitly added for creating releases
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9' # or your preferred Python version
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install coverage
- name: Run tests with coverage
run: |
coverage run -m unittest discover
coverage xml
coverage report
- name: Generate coverage badge
run: |
pip install coverage-badge
coverage-badge -o coverage.svg -f
- name: Upload coverage badge to README
run: |
sed -i 's|\[\!\[Coverage\]\(.*\)\]|\[\!\[Coverage\](./coverage.svg)\]|g' README.md
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "GitHub Actions"
git add coverage.svg README.md
# Commit only if there are changes
git diff --quiet && echo "No changes to commit" || git commit -m "Update coverage badge"
git push || echo "Nothing to push"
# - name: Increment version
# id: versioning
# run: |
# # Extract the current version
# CURRENT_VERSION=$(grep "__version__" moloni/__version__.py | cut -d "'" -f2)
# echo "Current version: $CURRENT_VERSION"
#
# # Initialize NEW_VERSION variable to avoid issues with uninitialized variables
# NEW_VERSION=""
#
# # Retrieve the last commit message
# # Check if the current commit is a merge commit
# if git rev-parse -q --verify MERGE_HEAD; then
# # Get the commit message of the latest non-merge commit
# COMMIT_MSG=$(git log --no-merges -1 --format=%B)
# else
# # Get the commit message of the current commit
# COMMIT_MSG=$(git log -1 --format=%B $GITHUB_SHA)
# fi
#
# echo "Commit Message: $COMMIT_MSG"
# # Check if the commit message specifies a version
# if echo "$COMMIT_MSG" | grep -q "version:"; then
# NEW_VERSION=$(echo "$COMMIT_MSG" | grep -oP "(?<=version: )\d+\.\d+\.\d+")
# echo "Using specified version: $NEW_VERSION"
# else
# IFS='.' read -ra VERSION_PARTS <<< "$CURRENT_VERSION"
# MAJOR_VERSION=${VERSION_PARTS[0]}
# MINOR_VERSION=${VERSION_PARTS[1]}
# PATCH_VERSION=${VERSION_PARTS[2]}
#
# echo "Parsed version: MAJOR_VERSION=$MAJOR_VERSION, MINOR_VERSION=$MINOR_VERSION, PATCH_VERSION=$PATCH_VERSION"
#
# # Increment the patch version
# PATCH_VERSION=$((PATCH_VERSION + 1))
# NEW_VERSION="${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}"
# echo "Incremented version: $NEW_VERSION"
# fi
#
# # Ensure NEW_VERSION is not empty before proceeding
# if [ -z "$NEW_VERSION" ]; then
# echo "Error: NEW_VERSION is empty. Exiting."
# exit 1
# fi
#
# # Update the version in the version file
# echo "__version__ = '$NEW_VERSION'" > moloni/__version__.py
#
# # Configure git and commit the change
# git config --local user.email "github-actions[bot]@users.noreply.github.com"
# git config --local user.name "GitHub Actions"
# git add moloni/__version__.py
# git commit -m "Bump version to $NEW_VERSION"
# git push || echo "Nothing to push"
#
# # Set the new version as an output for the next steps
# echo "new_version=$NEW_VERSION" >> $GITHUB_ENV
# # Set the new version as an output for the next steps
# echo "new_version=$NEW_VERSION" >> $GITHUB_ENV
- name: Increment version
uses: saleweaver/version_increment_action@v1
with:
file_path: 'moloni/__version__.py'
version_key: '__version__' # key to search for in the file, holding the version
github_token: ${{ secrets.GITHUB_TOKEN }}
base_branch: 'main'
- name: Create a new GitHub release
if: env.new_version != ''
uses: actions/create-release@v1
with:
tag_name: "v${{ env.new_version }}"
release_name: "v${{ env.new_version }}"
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Trigger release workflow
if: env.new_version != ''
run: |
curl -X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
https://api.github.com/repos/${{ github.repository }}/dispatches \
-d '{"event_type": "release_created", "client_payload": { "version": "${{ env.new_version }}" }}'