Update Version Badge #12
This file contains 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: Update Version Badge | |
on: | |
schedule: | |
- cron: '15 0 * * *' # This runs the workflow at 12:15 AM UTC every day | |
workflow_dispatch: # Allows manual triggering | |
jobs: | |
update-badge: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Extract version from manifest.json | |
id: get_version | |
run: | | |
VERSION=$(jq -r '.version' webflash/manifest.json | grep -oE '[0-9]+\.[0-9]+\.[0-9]+') | |
echo "::set-output name=version::$VERSION" | |
- name: Get current badge version from README | |
id: get_current_badge_version | |
run: | | |
CURRENT_VERSION=$(grep -oP 'Version-\K[0-9]+\.[0-9]+\.[0-9]+' README.md) | |
echo "::set-output name=current_version::$CURRENT_VERSION" | |
- name: Check if version has changed | |
id: version_check | |
run: | | |
if [ "${{ steps.get_version.outputs.version }}" == "${{ steps.get_current_badge_version.outputs.current_version }}" ]; then | |
echo "Version has not changed. Exiting." | |
exit 0 | |
fi | |
- name: Update README with new badge | |
run: | | |
VERSION=${{ steps.get_version.outputs.version }} | |
BADGE_URL="https://img.shields.io/badge/Version-${VERSION}-brightgreen.svg" | |
sed -i "s|!\[Firmware Version\](.*)|![Firmware Version](${BADGE_URL})|" README.md | |
- name: Commit changes | |
run: | | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git add README.md | |
git commit -m "Update firmware version badge to ${{ steps.get_version.outputs.version }}" | |
git push | |
if: steps.version_check.outputs.result != '0' | |