Skip to content

Publish Library to PIO Registry #51

Publish Library to PIO Registry

Publish Library to PIO Registry #51

Workflow file for this run

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
tag_version:
description: "Version to update if not incrementing"
required: false
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: Update Version
env:
PART_TO_INCREMENT: ${{ github.event.inputs.part_to_increment }}
TAG_VERSION: ${{ github.event.inputs.tag_version }}
run: |
if [ -n "$TAG_VERSION" ]; then
UPDATED_VERSION=$TAG_VERSION
else
chmod +x version
./version "$PART_TO_INCREMENT"
UPDATED_VERSION=$(grep "version=" library.properties | cut -d'=' -f2)
fi
echo "UPDATED_VERSION=$UPDATED_VERSION" >> $GITHUB_ENV
- name: Check if tag exists
id: check_tag
uses: actions/github-script@v6
with:
script: |
const tag = '${{ env.UPDATED_VERSION }}';
const { data: tags } = await github.rest.repos.listTags({
owner: context.repo.owner,
repo: context.repo.repo
});
const tagExists = tags.some(t => t.name === tag);
core.setOutput('tag_exists', tagExists);
- name: Commit changes
if: steps.check_tag.outputs.tag_exists == 'false'
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git remote set-url origin https://x-access-token:${{ secrets.GH_PAT }}@github.com/forntoh/LcdMenu.git
git add .
git commit -m "Update version to $UPDATED_VERSION"
git push origin master --force
- name: Create Tag
if: steps.check_tag.outputs.tag_exists == 'false'
run: |
git tag -a "${{ env.UPDATED_VERSION }}" -m "Tagging version ${{ env.UPDATED_VERSION }}"
git push origin "${{ env.UPDATED_VERSION }}"
- name: Install dependencies
if: steps.check_tag.outputs.tag_exists == 'false'
run: |
python -m pip install --upgrade pip
pip install click
pip install --upgrade platformio
- name: Login to PlatformIO
if: steps.check_tag.outputs.tag_exists == 'false'
run: |
pio account login -u "${{ secrets.PIO_USERNAME }}" -p "${{ secrets.PIO_PASSWORD }}"
- name: Publish to PlatformIO
if: steps.check_tag.outputs.tag_exists == 'false'
id: publish
run: yes y | pio pkg publish
continue-on-error: true
- name: Revert push and delete tag if publish fails
if: failure()
run: |
git reset --hard HEAD~1
git push origin +HEAD
git tag -d ${{ env.UPDATED_VERSION }}
git push origin :refs/tags/${{ env.UPDATED_VERSION }}
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: "14"
- name: Install @actions/github
run: npm install @actions/github
- name: Generate Release Notes
id: generate_release_notes
uses: actions/github-script@v6
env:
CURRENT_TAG: ${{ env.UPDATED_VERSION }}
with:
script: |
const generateReleaseNotes = require('.scripts/release_notes.js');
const releaseNotes = await generateReleaseNotes(github, context);
core.setOutput('release_notes', releaseNotes);
- name: Create GitHub Release
if: steps.check_tag.outputs.tag_exists == 'false'
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.UPDATED_VERSION }}
release_name: LcdMenu v${{ env.UPDATED_VERSION }}
draft: false
prerelease: false
body: ${{ steps.generate_release_notes.outputs.release_notes }}
- name: Update GitHub Release
if: steps.check_tag.outputs.tag_exists == 'true'
uses: actions/github-script@v6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
script: |
const { data: releases } = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo
});
const release = releases.find(r => r.tag_name === '${{ env.UPDATED_VERSION }}');
if (release) {
console.log('Updating release notes for release', release.id);
await github.rest.repos.updateRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: release.id,
body: `${{ steps.generate_release_notes.outputs.release_notes }}`
});
} else {
console.log('Release not found');
}