Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Implementing Automated Version Release and Publish to PlatformIO #27

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 }}
56 changes: 50 additions & 6 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,66 @@
name: PlatformIO Publish Release
name: Publish to PlatformIO

on:
release:
types: [released]

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
- 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 ]; then
sed -i -E "s/(version=).*/\1${LATEST_TAG}/" library.properties
echo ✅ Successfully Modified release tag in library.json file...
elif [ $PROPS_V == $LATEST_TAG ]; then
jq ".version = \"${LATEST_TAG}\"" library.json > temp.json && mv temp.json library.json
echo ✅ Successfully Modified release tag in library.properties file...
fi
- 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)
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:
# new fine-grained PAT with contents = rw
PAT: ${{ secrets.CI_PAT }}
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 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
Loading