dotstate 0.3.4

A modern, secure, and user-friendly dotfile manager built with Rust
Documentation
name: Bump Homebrew Tap

on:
  workflow_run:
    workflows: ["Release"]
    types:
      - completed

permissions:
  contents: write  # Need write access to push to tap repo

jobs:
  bump-tap:
    runs-on: ubuntu-latest
    if: ${{ github.event.workflow_run.conclusion == 'success' }}
    steps:
      - name: Extract version
        id: v
        if: ${{ github.event.workflow_run.conclusion == 'success' }}
        run: |
          TAG="${{ github.event.workflow_run.head_branch }}"   # e.g. v0.1.2
          VER="${TAG#v}"
          echo "tag=$TAG" >> $GITHUB_OUTPUT
          echo "ver=$VER" >> $GITHUB_OUTPUT

      - name: Download binary artifacts and compute sha256
        id: sha
        run: |
          TAG="${{ steps.v.outputs.tag }}"
          REPO="${{ github.repository }}"

          # Download both macOS binaries (Intel and Apple Silicon)
          curl -L "https://github.com/${REPO}/releases/download/${TAG}/dotstate-x86_64-apple-darwin.tar.gz" -o binary-intel.tar.gz
          curl -L "https://github.com/${REPO}/releases/download/${TAG}/dotstate-aarch64-apple-darwin.tar.gz" -o binary-arm.tar.gz

          # Compute SHA256 for both
          SHA_INTEL=$(sha256sum binary-intel.tar.gz | awk '{print $1}')
          SHA_ARM=$(sha256sum binary-arm.tar.gz | awk '{print $1}')

          echo "sha_intel=$SHA_INTEL" >> $GITHUB_OUTPUT
          echo "sha_arm=$SHA_ARM" >> $GITHUB_OUTPUT

          # URLs for both architectures
          echo "url_intel=https://github.com/${REPO}/releases/download/${TAG}/dotstate-x86_64-apple-darwin.tar.gz" >> $GITHUB_OUTPUT
          echo "url_arm=https://github.com/${REPO}/releases/download/${TAG}/dotstate-aarch64-apple-darwin.tar.gz" >> $GITHUB_OUTPUT

      - name: Checkout tap repo
        uses: actions/checkout@v4
        with:
          repository: serkanyersen/homebrew-dotstate
          token: ${{ secrets.HOMEBREW_TAP_TOKEN }}
          path: tap

      - name: Update formula
        env:
          URL_INTEL: ${{ steps.sha.outputs.url_intel }}
          URL_ARM: ${{ steps.sha.outputs.url_arm }}
          SHA_INTEL: ${{ steps.sha.outputs.sha_intel }}
          SHA_ARM: ${{ steps.sha.outputs.sha_arm }}
        run: |
          # Use Python to update the formula more reliably
          python3 << 'EOF'
          import os
          import re

          formula_path = "tap/Formula/dotstate.rb"
          url_intel = os.environ['URL_INTEL']
          url_arm = os.environ['URL_ARM']
          sha_intel = os.environ['SHA_INTEL']
          sha_arm = os.environ['SHA_ARM']

          with open(formula_path, 'r') as f:
              content = f.read()

          # Update Intel URL - match url line within the if block
          content = re.sub(
              r'(if Hardware::CPU\.intel\?\s*\n\s+url ")[^"]+(")',
              r'\g<1>' + url_intel + r'\g<2>',
              content,
              flags=re.MULTILINE
          )

          # Update Intel SHA256 - match sha256 line after Intel URL
          content = re.sub(
              r'(if Hardware::CPU\.intel\?\s*\n\s+url "[^"]+"\s*\n\s+sha256 ")[^"]+(")',
              r'\g<1>' + sha_intel + r'\g<2>',
              content,
              flags=re.MULTILINE
          )

          # Update ARM URL - match url line within the else block
          content = re.sub(
              r'(else\s*\n\s+url ")[^"]+(")',
              r'\g<1>' + url_arm + r'\g<2>',
              content,
              flags=re.MULTILINE
          )

          # Update ARM SHA256 - match sha256 line after ARM URL
          content = re.sub(
              r'(else\s*\n\s+url "[^"]+"\s*\n\s+sha256 ")[^"]+(")',
              r'\g<1>' + sha_arm + r'\g<2>',
              content,
              flags=re.MULTILINE
          )

          with open(formula_path, 'w') as f:
              f.write(content)
          EOF

      - name: Commit and push
        run: |
          cd tap
          git config user.name "github-actions[bot]"
          git config user.email "github-actions[bot]@users.noreply.github.com"
          git add Formula/dotstate.rb
          git commit -m "dotstate ${{ steps.v.outputs.tag }}" || exit 0
          git push