Repository navigation
ci: Auto-regenerate Nextion2Text output on HMI changes #4
Workflow file for this run
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: Generate Nextion2Text | |
| # yamllint disable-line rule:truthy | |
| on: | |
| pull_request: | |
| paths: | |
| - 'hmi/**.hmi' | |
| - 'hmi/dev/nextion2text/**' | |
| - 'hmi/dev/scripts/generate_nextion_txt.sh' | |
| - '.github/workflows/generate_nextion_txt.yml' | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| # =========================================================================== | |
| # Generation — executes pull request code, so it stays read-only | |
| # =========================================================================== | |
| generate: | |
| name: Regenerate text dumps from HMI | |
| permissions: | |
| contents: read | |
| runs-on: ubuntu-latest | |
| outputs: | |
| changed: ${{ steps.drift.outputs.changed }} | |
| steps: | |
| - name: Check out pull request head | |
| uses: actions/checkout@v7 | |
| with: | |
| fetch-depth: '0' | |
| repository: >- | |
| ${{ github.event.pull_request.head.repo.full_name || github.repository }} | |
| ref: ${{ github.event.pull_request.head.sha || github.ref }} | |
| # Invoked through bash: the exec bit does not survive every Windows clone. | |
| - name: Regenerate text dumps | |
| run: bash hmi/dev/scripts/generate_nextion_txt.sh | |
| # status, not diff: a new panel or page is untracked and invisible to diff. | |
| - name: Detect drift | |
| id: drift | |
| run: | | |
| if [ -z "$(git status --porcelain -- hmi/dev/nextion2text)" ]; then | |
| echo "changed=false" >> "$GITHUB_OUTPUT" | |
| echo "Nextion2Text output is up to date." | |
| else | |
| echo "changed=true" >> "$GITHUB_OUTPUT" | |
| git --no-pager status --short -- hmi/dev/nextion2text | |
| fi | |
| - name: Upload regenerated output | |
| if: steps.drift.outputs.changed == 'true' | |
| uses: actions/upload-artifact@v5 | |
| with: | |
| name: nextion2text | |
| path: hmi/dev/nextion2text | |
| retention-days: 1 | |
| # =========================================================================== | |
| # Write-back — never executes pull request code, so it may hold write access | |
| # =========================================================================== | |
| commit: | |
| name: Commit regenerated output | |
| needs: generate | |
| if: >- | |
| needs.generate.outputs.changed == 'true' && | |
| github.event_name == 'pull_request' && | |
| github.event.pull_request.head.repo.full_name == github.repository | |
| permissions: | |
| contents: write | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check out pull request branch | |
| uses: actions/checkout@v7 | |
| with: | |
| fetch-depth: '0' | |
| ref: ${{ github.head_ref }} | |
| # Wipe first so pages removed from the HMI disappear from the tree. | |
| - name: Drop the previous output | |
| run: rm -rf hmi/dev/nextion2text | |
| - name: Download regenerated output | |
| uses: actions/download-artifact@v6 | |
| with: | |
| name: nextion2text | |
| path: hmi/dev/nextion2text | |
| - name: Commit regenerated output | |
| uses: stefanzweifel/git-auto-commit-action@v7 | |
| with: | |
| commit_message: "chore: Regenerate Nextion2Text output" | |
| file_pattern: 'hmi/dev/nextion2text' | |
| # =========================================================================== | |
| # Fork pull requests get a read-only token, so drift must be fixed by hand | |
| # =========================================================================== | |
| report: | |
| name: Report uncommittable drift | |
| needs: generate | |
| if: >- | |
| needs.generate.outputs.changed == 'true' && | |
| (github.event_name != 'pull_request' || | |
| github.event.pull_request.head.repo.full_name != github.repository) | |
| permissions: | |
| contents: read | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Report drift | |
| run: | | |
| echo "::error::Nextion2Text output is out of date. Run" \ | |
| "hmi/dev/scripts/generate_nextion_txt.sh and commit the result." | |
| exit 1 | |
| ... |