Update Repos Formula #13
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: Update Repos Formula | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Release version (e.g., v0.0.6)' | |
| required: true | |
| type: string | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| update-formula: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| fetch-depth: 0 | |
| - name: Download and calculate main SHA256 | |
| id: calculate-sha | |
| run: | | |
| VERSION="${{ github.event.inputs.version }}" | |
| # Ensure version starts with 'v' for the tag | |
| if [[ ! "$VERSION" =~ ^v ]]; then | |
| VERSION="v${VERSION}" | |
| fi | |
| # Remove 'v' prefix for the filename | |
| VERSION_NO_V="${VERSION#v}" | |
| URL="https://github.com/codcod/repos/releases/download/${VERSION}/repos-${VERSION_NO_V}-universal-apple-darwin.tar.gz" | |
| echo "Downloading ${URL}" | |
| # Download with error checking | |
| if ! curl -L "${URL}" -o repos.tar.gz -f; then | |
| echo "❌ Failed to download release ${VERSION}" | |
| echo "❌ URL: ${URL}" | |
| echo "❌ This release may not exist. Please check:" | |
| echo " https://github.com/codcod/repos/releases" | |
| exit 1 | |
| fi | |
| # Check file size (should be more than 100 bytes for a real binary) | |
| FILE_SIZE=$(stat -c%s repos.tar.gz) | |
| if [ "$FILE_SIZE" -lt 100 ]; then | |
| echo "❌ Downloaded file is too small (${FILE_SIZE} bytes)" | |
| echo "❌ This suggests the release doesn't exist or the URL is incorrect" | |
| echo "❌ URL: ${URL}" | |
| exit 1 | |
| fi | |
| SHA256=$(shasum -a 256 repos.tar.gz | cut -d' ' -f1) | |
| echo "✅ Successfully downloaded ${FILE_SIZE} bytes" | |
| echo "SHA256: ${SHA256}" | |
| echo "url=${URL}" >> $GITHUB_OUTPUT | |
| echo "sha256=${SHA256}" >> $GITHUB_OUTPUT | |
| echo "version=${VERSION}" >> $GITHUB_OUTPUT | |
| - name: Update repos.rb formula | |
| run: | | |
| URL="${{ steps.calculate-sha.outputs.url }}" | |
| SHA256="${{ steps.calculate-sha.outputs.sha256 }}" | |
| VERSION="${{ steps.calculate-sha.outputs.version }}" | |
| # Update the URL line | |
| sed -i "s|url \".*\"|url \"${URL}\"|" repos.rb | |
| # Update the SHA256 line | |
| sed -i "s|sha256 \".*\"|sha256 \"${SHA256}\"|" repos.rb | |
| echo "Updated repos.rb with:" | |
| echo " URL: ${URL}" | |
| echo " SHA256: ${SHA256}" | |
| - name: Verify formula syntax | |
| run: | | |
| # Simple Ruby syntax check | |
| ruby -c repos.rb | |
| # Check if the formula can be parsed | |
| echo "Formula syntax is valid" | |
| - name: Create branch and push changes | |
| run: | | |
| # Configure git | |
| git config --global user.name "github-actions[bot]" | |
| git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
| # Create branch name | |
| BRANCH_NAME="update-repos-${{ steps.calculate-sha.outputs.version }}" | |
| # Delete branch if it exists locally | |
| git branch -D "$BRANCH_NAME" 2>/dev/null || true | |
| # Delete branch if it exists remotely | |
| git push origin --delete "$BRANCH_NAME" 2>/dev/null || true | |
| # Create and switch to new branch | |
| git checkout -b "$BRANCH_NAME" | |
| # Add and commit changes | |
| git add repos.rb | |
| git commit -m "Update repos formula to ${{ steps.calculate-sha.outputs.version }}" | |
| # Push the branch (force push to handle any conflicts) | |
| git push --force origin "$BRANCH_NAME" | |
| echo "✅ Branch pushed successfully!" | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Create Pull Request | |
| run: | | |
| BRANCH_NAME="update-repos-${{ steps.calculate-sha.outputs.version }}" | |
| # Try to create PR using GitHub CLI | |
| gh pr create \ | |
| --title "Update repos formula to ${{ steps.calculate-sha.outputs.version }}" \ | |
| --body "This PR updates the repos formula to version \`${{ steps.calculate-sha.outputs.version }}\`. | |
| ## Changes | |
| - **Updated URL to:** \`${{ steps.calculate-sha.outputs.url }}\` | |
| - **Updated SHA256 to:** \`${{ steps.calculate-sha.outputs.sha256 }}\` | |
| The formula has been validated with Ruby syntax check. | |
| **Auto-generated by GitHub Actions** 🤖" \ | |
| --head "$BRANCH_NAME" \ | |
| --base main | |
| echo "✅ Pull request created successfully!" | |
| echo "🔗 View at: https://github.com/codcod/homebrew-taps/pulls" | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |