Fix for publishing test artifacts #8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Versioning & Release | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
check-tests: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Download Test Result Artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: TESTS_PASSED | |
path: . # Current directory | |
- name: Read Test Result | |
id: read_test_result | |
run: echo "TESTS_PASSED=$(cat test_result.txt)" >> $GITHUB_ENV | |
- name: Read Commit Message | |
id: commit_msg | |
run: echo "COMMIT_MSG=$(git log -1 --pretty=%B)" >> $GITHUB_ENV | |
- name: Skip Release if Tests Failed (Unless Forced) | |
if: env.TESTS_PASSED == 'failure' && !contains(env.COMMIT_MSG, 'FORCE-RELEASE') | |
run: | | |
echo "Tests failed. Skipping release." | |
exit 1 | |
versioning: | |
needs: check-tests | |
runs-on: ubuntu-latest | |
if: success() # Only runs if check-tests job passes | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
- name: Read Current Version | |
id: get_version | |
run: | | |
VERSION=$(grep '^__version__ =' cli_monitor.py | cut -d '"' -f2) | |
echo "CURRENT_VERSION=$VERSION" >> $GITHUB_ENV | |
- name: Determine Version Increment | |
id: version_bump | |
run: | | |
CURRENT_VERSION=${{ env.CURRENT_VERSION }} | |
MAJOR=$(echo $CURRENT_VERSION | cut -d. -f1) | |
MINOR=$(echo $CURRENT_VERSION | cut -d. -f2) | |
PATCH=$(echo $CURRENT_VERSION | cut -d. -f3) | |
COMMIT_MSG=$(git log -1 --pretty=%B) | |
if [[ "$COMMIT_MSG" == *"MAJOR"* ]]; then | |
MAJOR=$((MAJOR + 1)) | |
MINOR=0 | |
PATCH=0 | |
elif [[ "$COMMIT_MSG" == *"MINOR"* ]]; then | |
MINOR=$((MINOR + 1)) | |
PATCH=0 | |
elif [[ "$COMMIT_MSG" == *"PATCH"* ]]; then | |
PATCH=$((PATCH + 1)) | |
fi | |
NEW_VERSION="$MAJOR.$MINOR.$PATCH" | |
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV | |
echo "Version updated to $NEW_VERSION" | |
- name: Update Version in `cli_monitor.py` | |
run: sed -i "s/^__version__ = .*/__version__ = \"${{ env.NEW_VERSION }}\"/" cli_monitor.py | |
- name: Commit & Push Version Update | |
env: | |
GH_PAT: ${{ secrets.GH_PAT }} | |
run: | | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions@users.noreply.github.com" | |
git add cli_monitor.py | |
git commit -m "chore: bump version to ${{ env.NEW_VERSION }}" | |
git push https://Dimos082:${GH_PAT}@github.com/Dimos082/cli-monitor.git | |
- name: Create GitHub Release | |
uses: softprops/action-gh-release@v2 | |
with: | |
tag_name: v${{ env.NEW_VERSION }} | |
name: Release v${{ env.NEW_VERSION }} | |
body: "Automated release for version ${{ env.NEW_VERSION }}" | |
draft: false | |
prerelease: false | |
files: cli_monitor.py |