Publish Library to PIO Registry #39
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: Publish Library to PIO Registry | |
on: | |
workflow_dispatch: | |
inputs: | |
part_to_increment: | |
description: "Part to increment (1 for major, 2 for minor, 3 for patch)" | |
required: true | |
jobs: | |
publish: | |
name: Prepare Release | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.x" | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install click | |
pip install --upgrade platformio | |
- name: Login to PlatformIO | |
run: | | |
pio account login -u "${{ secrets.PIO_USERNAME }}" -p "${{ secrets.PIO_PASSWORD }}" | |
- name: Update Version | |
env: | |
PART_TO_INCREMENT: ${{ github.event.inputs.part_to_increment }} | |
run: | | |
chmod +x version | |
./version "$PART_TO_INCREMENT" | |
echo "UPDATED_VERSION=$(grep "version=" library.properties | cut -d'=' -f2)" >> $GITHUB_ENV | |
- name: Commit changes | |
env: | |
GH_TOKEN: ${{ secrets.GH_PAT }} | |
run: | | |
git config --global user.name "${{ github.actor }}" | |
git config --global user.email "${{ github.actor }}@users.noreply.github.com" | |
git add . | |
git commit -m "Update version to $UPDATED_VERSION" | |
git push https://x-access-token:${GH_TOKEN}@github.com/${{ github.repository }}.git master --force | |
- name: Create Tag | |
if: ${{ env.UPDATED_VERSION != '' }} | |
env: | |
GH_TOKEN: ${{ secrets.GH_PAT }} | |
run: | | |
git tag -a "${{ env.UPDATED_VERSION }}" -m "Tagging version ${{ env.UPDATED_VERSION }}" | |
git push https://x-access-token:${GH_TOKEN}@github.com/${{ github.repository }}.git "${{ env.UPDATED_VERSION }}" --force | |
- name: Publish to PlatformIO | |
id: publish | |
run: yes y | pio pkg publish | |
continue-on-error: true | |
- name: Revert push and delete tag if publish fails | |
if: failure() | |
env: | |
GH_TOKEN: ${{ secrets.GH_PAT }} | |
run: | | |
git reset --hard HEAD~1 | |
git push https://x-access-token:${GH_TOKEN}@github.com/${{ github.repository }}.git +HEAD --force | |
git tag -d ${{ env.UPDATED_VERSION }} | |
- name: Create GitHub Release | |
if: success() | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ github.ref_name }} | |
release_name: LcdMenu v${{ github.ref_name }} | |
draft: true | |
prerelease: false |