figma-agent 0.2.2

Local font helper for Figma, Linux and macOS
name: Update

on:
  schedule:
    - cron: "0 6 * * *"
  workflow_dispatch:

concurrency:
  group: update
  cancel-in-progress: false

permissions:
  contents: write
  pull-requests: write

jobs:
  update:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
        with:
          persist-credentials: false

      - name: Resolve current and latest version
        id: ver
        run: |
          current=$(grep -oP 'UPSTREAM_PACKAGE: &str = "\K[^"]+' src/util.rs)
          latest=$(curl -fsSL https://desktop.figma.com/agent/mac/RELEASE.json | jq -r '.version')

          if [ -z "$latest" ] || [ "$latest" = "null" ]; then
            echo "::error::could not read .version from RELEASE.json"
            exit 1
          fi
          if ! printf '%s' "$latest" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then
            echo "::error::unexpected version format: $latest"
            exit 1
          fi

          echo "current=$current" >> "$GITHUB_OUTPUT"
          echo "latest=$latest" >> "$GITHUB_OUTPUT"
          if [ "$current" = "$latest" ]; then
            echo "changed=false" >> "$GITHUB_OUTPUT"
            echo "up to date: $current"
          else
            echo "changed=true" >> "$GITHUB_OUTPUT"
            echo "update available: $current -> $latest"
          fi

      - name: Apply version bump
        if: steps.ver.outputs.changed == 'true'
        run: |
          CURRENT=$(printf '%s' "${{ steps.ver.outputs.current }}" | sed 's/\./\\./g')
          LATEST="${{ steps.ver.outputs.latest }}"
          sed -i "s/${CURRENT}/${LATEST}/g" src/util.rs .github/workflows/parity.yml

      - name: Mint app token
        if: steps.ver.outputs.changed == 'true'
        id: app-token
        uses: actions/create-github-app-token@v3
        with:
          client-id: ${{ secrets.APP_CLIENT_ID }}
          private-key: ${{ secrets.APP_PRIVATE_KEY }}

      - name: Create pull request
        if: steps.ver.outputs.changed == 'true'
        uses: peter-evans/create-pull-request@v8
        with:
          token: ${{ steps.app-token.outputs.token }}
          branch: chore/upstream-${{ steps.ver.outputs.latest }}
          commit-message: "chore: bump upstream Figma agent to ${{ steps.ver.outputs.latest }}"
          title: "chore: upstream Figma agent ${{ steps.ver.outputs.latest }} available"
          labels: upstream
          body: |
            ## Summary

            A new upstream Figma desktop agent version is available.

            - Current: `${{ steps.ver.outputs.current }}`
            - Latest: `${{ steps.ver.outputs.latest }}`
            - Source: https://desktop.figma.com/agent/mac/RELEASE.json

            Version string bump only; Parity will fail until the agent is re-aligned.