Skip to content

Merge remote-tracking branch 'origin/main' #31

Merge remote-tracking branch 'origin/main'

Merge remote-tracking branch 'origin/main' #31

Workflow file for this run

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: 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 }}" }}'