Skip to content

Commit

Permalink
Add optional tag version input and implement tag existence check
Browse files Browse the repository at this point in the history
- Added an optional input for setting a specific version if not incrementing
- Implemented a check to verify the existence of a tag before committing and tagging changes.
  • Loading branch information
forntoh committed Oct 7, 2024
1 parent 3569f5b commit db76d2a
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 16 deletions.
82 changes: 66 additions & 16 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
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:
Expand All @@ -21,25 +24,35 @@ jobs:
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 }}
TAG_VERSION: ${{ github.event.inputs.tag_version }}
run: |
chmod +x version
./version "$PART_TO_INCREMENT"
echo "UPDATED_VERSION=$(grep "version=" library.properties | cut -d'=' -f2)" >> $GITHUB_ENV
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"
Expand All @@ -49,12 +62,25 @@ jobs:
git push origin master --force
- name: Create Tag
if: ${{ env.UPDATED_VERSION != '' }}
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
Expand Down Expand Up @@ -87,7 +113,7 @@ jobs:
core.setOutput('release_notes', releaseNotes);
- name: Create GitHub Release
if: success()
if: steps.check_tag.outputs.tag_exists == 'false'
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -96,4 +122,28 @@ jobs:
release_name: LcdMenu v${{ env.UPDATED_VERSION }}
draft: false
prerelease: false
body: ${{ steps.generate_release_notes.outputs.result }}
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');
}
1 change: 1 addition & 0 deletions .scripts/release_notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ async function generateReleaseNotes(github, context) {
pr.labels.forEach((label) => {
if (label.name === "breaking-change") {
hasBreakingChanges = true;
return;
}
if (categories[label.name]) {
categories[label.name].push(prEntry);
Expand Down

0 comments on commit db76d2a

Please sign in to comment.