Skip to content

Commit

Permalink
ci: Implementing Automated Version Release and Publish to PlatformIO (#…
Browse files Browse the repository at this point in the history
…27)

* ci: Implementing Automated Version Release and Publish to PlatformIO
docs: Assuring conventional commits

- This PR changed:
[prlint.yml]: Validates every PR against Conventional Commits to guarantee a healthy release and publish.
[release.yml]: Automates releasing a new version including all the necessary steps using semantic-release action.  Must pass prlint and tests CIs.
[publish.yml]: Automates publishing the new released version to PlatformIO registry and update versions in library.json and library.properties files.  Depends on [release.yml].
[CONTRIBUTING.md]: Added note for new contributors about conventional commit message.

resolves issue #5

* fix(ci): Library Release Versions Manipulation Improvement and Refactoring Pushing New Release Versions
  • Loading branch information
mohammedelgammal authored Jan 29, 2025
1 parent 4eace4c commit 3b5b048
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 9 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/prlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Pull Request Message Validation
on: pull_request

jobs:
prlint:
runs-on: ubuntu-latest
steps:
- name: Validate Pull Request
uses: amannn/action-semantic-pull-request@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
63 changes: 57 additions & 6 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,73 @@
name: PlatformIO Publish Release
name: Publish to PlatformIO

on:
release:
types: [released]
workflow_call:

jobs:
release:
pio-publish:
runs-on: ubuntu-latest
env:
PLATFORMIO_AUTH_TOKEN: ${{ secrets.PLATFORMIO_AUTH_TOKEN }}
name: Publish a new Release to PlatformIO
steps:
- uses: actions/checkout@v4
with:
fetch-tags: true
- uses: actions/setup-python@v5
with:
python-version: '3.9'
python-version: "3.9"
- name: Install PlatformIO Core
run: |
python -m pip install --upgrade pip
pip install platformio
- name: Publish Release
- name: Install jq for handling JSON data
run: |
sudo apt update
sudo apt install -y jq
- name: Update Library Metadata and Configurations
run: |
LATEST_TAG=$(git describe --tags --abbrev=0)
LIB_V=$(jq -r .version library.json)
PROPS_V=$(cat library.properties | grep -oP version=\K.*)
if [ $LIB_V = $LATEST_TAG ] || [ $PROPS_V = $LATEST_TAG ]; then
exit 1
fi
set -e
sed -i -E "s/(version=).*/\1${LATEST_TAG}/" library.properties
echo ✅ Successfully Modified release tag in library.json file...
jq ".version = \"${LATEST_TAG}\"" library.json > temp.json && mv temp.json library.json
echo ✅ Successfully Modified release tag in library.properties file...
- name: Publish to PlatformIO
env:
PLATFORMIO_AUTH_TOKEN: ${{ secrets.PLATFORMIO_AUTH_TOKEN }}
run: |
pio package publish --no-interactive --type library
echo 👍 Successfully published to PlatformIO
update-lib-versions:
runs-on: ubuntu-latest
name: Update versions in library.json and library.properties
needs: pio-publish
steps:
- uses: actions/checkout@v4
with:
fetch-tags: true
- name: Update library versions
run: |
LATEST_TAG=$(git describe --tags --abbrev=0)
set -e
sed -i -E "s/(version=).*/\1${LATEST_TAG}/" library.properties
jq ".version = \"${LATEST_TAG}\"" library.json > temp.json && mv temp.json library.json
- name: Push to main branch using PAT
env:
PAT: ${{ secrets.CI_PAT }} # new fine-grained PAT with contents = rw
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "[email protected]"
git remote set-url origin https://x-access-token:${{ env.PAT }}@github.com/${{ github.repository }}
git stash
git pull origin main
git stash pop
git add library.json library.properties
git commit -m "Automated update: Update library.json library.properties"
git push
35 changes: 35 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Version Release

on:
workflow_run:
workflows: ["PlatformIO Unit Tests"]
types:
- completed

jobs:
gh-release:
name: Release a new Version
runs-on: ubuntu-latest
permissions:
contents: write
issues: write
pull-requests: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: latest
- name: GitHub Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
npm init -y
npm install --save-dev \
semantic-release \
@semantic-release/commit-analyzer \
@semantic-release/release-notes-generator \
@semantic-release/git \
@semantic-release/changelog \
@semantic-release/github
npx [email protected]
echo 👍 Successfully released a new version
3 changes: 1 addition & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
key: ${{ runner.os }}-pio
- uses: actions/setup-python@v4
with:
python-version: '3.9'
python-version: "3.9"
- name: Install PlatformIO Core
run: |
python -m pip install --upgrade pip
Expand All @@ -30,4 +30,3 @@ jobs:
run: platformio run -e arduino_uno -t build_test.cpp
- name: Run Build Test for ESP32 Dev Module
run: platformio run -e esp32dev -t build_test.cpp

12 changes: 12 additions & 0 deletions .releaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"branches": [
"main"
],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/git",
"@semantic-release/changelog",
"@semantic-release/github"
]
}
4 changes: 3 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ Open an issue on the repository and provide the following information:

## Code Convention

- Don't include C++ standard library functions, because it does not compile for AVR boards (C std libs still works).
- Don't include C++ standard library functions, because it does not compile for AVR boards (C std libs still works).

- **Note:** All commits and pull requests must follow the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/). Please ensure your messages are properly formatted.

## Testing

Expand Down

0 comments on commit 3b5b048

Please sign in to comment.