Sync and release #49
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
| # Sync generated/lvgl_python.c, lv_conf.h, and lvgl from PyDevices/lvgl-bindings on GitHub, | |
| # commit the next version to main and publish its GitHub Release. | |
| # | |
| # Run from the GitHub Actions tab (workflow_dispatch) or without cloning this repo: | |
| # gh workflow run sync-and-release.yml --repo PyDevices/lvgl-python | |
| # gh workflow run sync-and-release.yml --repo PyDevices/lvgl-python -f lvgl_bindings_ref=abc1234 | |
| # | |
| # Prerequisite: commit regenerated generated/lvgl_python.c (and lv_conf.h if changed) to | |
| # lvgl-bindings first — sync reads from GitHub, not your local machine. | |
| name: Sync and release | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| lvgl_bindings_ref: | |
| description: lvgl-bindings branch, tag, or commit SHA | |
| type: string | |
| default: main | |
| skip_publish: | |
| description: Sync and commit only; do not create a release tag | |
| type: boolean | |
| default: false | |
| permissions: | |
| contents: write | |
| jobs: | |
| sync-and-release: | |
| runs-on: ubuntu-latest | |
| if: github.repository == 'PyDevices/lvgl-python' | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| submodules: recursive | |
| - name: Resolve lvgl-bindings ref | |
| id: lvgl_bindings_ref | |
| run: | | |
| REF="${{ inputs.lvgl_bindings_ref }}" | |
| if [[ -z "$REF" ]]; then | |
| REF="main" | |
| fi | |
| echo "ref=${REF}" >> "$GITHUB_OUTPUT" | |
| echo "Syncing from lvgl-bindings @ ${REF}" | |
| - name: Sync from lvgl-bindings | |
| run: ./scripts/sync_from_lvgl_bindings.sh --ref "${{ steps.lvgl_bindings_ref.outputs.ref }}" | |
| - name: Commit versioned sync | |
| id: commit | |
| env: | |
| LV_BINDINGS_REF: ${{ steps.lvgl_bindings_ref.outputs.ref }} | |
| run: | | |
| set -euo pipefail | |
| git config user.name 'github-actions[bot]' | |
| git config user.email 'github-actions[bot]@users.noreply.github.com' | |
| # Stage first: a newly synced file (e.g. fs_driver.py on its first | |
| # sync) is untracked, and `git diff` alone would miss it. | |
| git add generated/lvgl_python.c generated/lvgl.pyi lv_conf.h display_driver.py fs_driver.py lvgl | |
| if git diff --cached --quiet; then | |
| echo "changed=false" >> "$GITHUB_OUTPUT" | |
| echo "Already in sync with lvgl-bindings ${LV_BINDINGS_REF}." | |
| else | |
| git fetch --tags origin | |
| VERSION="$(./scripts/next_release_version.sh)" | |
| printf '%s\n' "$VERSION" > VERSION | |
| git add VERSION generated/lvgl_python.c generated/lvgl.pyi lv_conf.h display_driver.py fs_driver.py lvgl | |
| git commit -m "Sync bindings and LVGL from lvgl-bindings ${LV_BINDINGS_REF}." | |
| git push origin HEAD:main | |
| echo "changed=true" >> "$GITHUB_OUTPUT" | |
| echo "version=${VERSION}" >> "$GITHUB_OUTPUT" | |
| echo "Committed and pushed sync from lvgl-bindings ${LV_BINDINGS_REF}." | |
| fi | |
| # Not GITHUB_TOKEN: a Release created with it does not trigger | |
| # `on: release` workflows, so publish-release-packages.yml would never | |
| # run and nothing would reach TestPyPI. An App installation token does | |
| # trigger them. | |
| - name: Mint an installation token for this repository | |
| id: app-token | |
| if: inputs.skip_publish != true && steps.commit.outputs.changed == 'true' | |
| uses: actions/create-github-app-token@v2 | |
| with: | |
| app-id: ${{ secrets.PYDEVICES_APP_ID }} | |
| private-key: ${{ secrets.PYDEVICES_APP_PRIVATE_KEY }} | |
| owner: PyDevices | |
| repositories: lvgl-python | |
| - name: Publish GitHub Release | |
| if: inputs.skip_publish != true && steps.commit.outputs.changed == 'true' | |
| env: | |
| GH_TOKEN: ${{ steps.app-token.outputs.token }} | |
| VERSION: ${{ steps.commit.outputs.version }} | |
| run: | | |
| set -euo pipefail | |
| gh release create "v${VERSION}" \ | |
| --repo "${{ github.repository }}" \ | |
| --target "$(git rev-parse HEAD)" \ | |
| --title "v${VERSION}" \ | |
| --generate-notes | |
| echo "Published GitHub Release v${VERSION}" | |
| - name: No release tag | |
| if: inputs.skip_publish != true && steps.commit.outputs.changed != 'true' | |
| run: echo "No changes after sync — GitHub Release skipped." | |
| - name: Skipped publish | |
| if: inputs.skip_publish == true | |
| run: echo "skip_publish=true — no GitHub Release was published." |