Build and Release #9
This file contains hidden or 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: Build and Release | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: "Release version (e.g. 1.2.3 or 1.2.3-beta1)" | |
| required: true | |
| push: | |
| tags: | |
| - 'v*' # optional: trigger on tag pushes | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Set version variable | |
| id: vars | |
| run: | | |
| VERSION="${{ github.event.inputs.version }}" | |
| if [ -z "$VERSION" ]; then | |
| VERSION="${GITHUB_REF#refs/tags/v}" | |
| fi | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| if [[ "$VERSION" == *beta* ]]; then | |
| echo "prerelease=true" >> $GITHUB_OUTPUT | |
| echo "latest=false" >> $GITHUB_OUTPUT | |
| else | |
| echo "prerelease=false" >> $GITHUB_OUTPUT | |
| echo "latest=true" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Update manifest.json | |
| run: | | |
| sed -i 's/"version": *".*"/"version": "${{ steps.vars.outputs.version }}"/' custom_components/lednetwf_ble/manifest.json | |
| - name: Commit updated manifest.json to main | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git add custom_components/lednetwf_ble/manifest.json | |
| # Only commit if there are changes | |
| if git diff --staged --quiet; then | |
| echo "No changes to commit - version already up to date" | |
| else | |
| git commit -m "Bump version to ${{ steps.vars.outputs.version }}" | |
| git push origin HEAD:main | |
| fi | |
| - name: Create ZIP | |
| run: | | |
| mkdir -p dist/lednetwf | |
| cp -r custom_components/lednetwf_ble/* dist/lednetwf/ | |
| cd dist/lednetwf | |
| zip -r ../lednetwf.zip . | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: v${{ steps.vars.outputs.version }} | |
| name: Release ${{ steps.vars.outputs.version }} | |
| draft: false | |
| prerelease: ${{ steps.vars.outputs.prerelease }} | |
| make_latest: ${{ steps.vars.outputs.latest }} | |
| files: dist/lednetwf.zip | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |