0.0.1 #3
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: Update Formula | |
| on: | |
| release: | |
| types: | |
| - published | |
| - edited | |
| jobs: | |
| check-assets: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| has_darwin_amd64: ${{ steps.check.outputs.has_darwin_amd64 }} | |
| has_darwin_arm64: ${{ steps.check.outputs.has_darwin_arm64 }} | |
| has_linux_arm64: ${{ steps.check.outputs.has_linux_arm64 }} | |
| has_linux_amd64: ${{ steps.check.outputs.has_linux_amd64 }} | |
| steps: | |
| - name: Check available assets | |
| id: check | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| VERSION: ${{ github.event.release.tag_name }} | |
| run: | | |
| gh release view "${VERSION}" --repo "${{ github.repository }}" --json assets --jq '.assets[].name' > assets.txt | |
| cat assets.txt | |
| grep -q "pinc-${VERSION}-darwin-amd64.tar.gz" assets.txt \ | |
| && echo "has_darwin_amd64=true" >> $GITHUB_OUTPUT \ | |
| || echo "has_darwin_amd64=false" >> $GITHUB_OUTPUT | |
| grep -q "pinc-${VERSION}-darwin-arm64.tar.gz" assets.txt \ | |
| && echo "has_darwin_arm64=true" >> $GITHUB_OUTPUT \ | |
| || echo "has_darwin_arm64=false" >> $GITHUB_OUTPUT | |
| grep -q "pinc-${VERSION}-linux-amd64.tar.gz" assets.txt \ | |
| && echo "has_linux_amd64=true" >> $GITHUB_OUTPUT \ | |
| || echo "has_linux_amd64=false" >> $GITHUB_OUTPUT | |
| grep -q "pinc-${VERSION}-linux-arm64.tar.gz" assets.txt \ | |
| && echo "has_linux_arm64=true" >> $GITHUB_OUTPUT \ | |
| || echo "has_linux_arm64=false" >> $GITHUB_OUTPUT | |
| update-formula: | |
| needs: check-assets | |
| runs-on: ubuntu-latest | |
| env: | |
| VERSION: ${{ github.event.release.tag_name }} | |
| BASE_URL: 'https://github.com/${{ github.repository }}/releases/download/${{ github.event.release.tag_name }}' | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| - name: Download assets | |
| run: | | |
| gh release download "${VERSION}" \ | |
| --repo "${{ github.repository }}" \ | |
| --pattern "*.tar.gz" || true | |
| - name: Compute SHA256s | |
| id: sha256 | |
| run: | | |
| for PLATFORM in darwin-amd64 darwin-arm64 linux-amd64 linux-arm64; do | |
| FILE="pinc-${VERSION}-${PLATFORM}.tar.gz" | |
| if [ -f "${FILE}" ]; then | |
| SHA=$(sha256sum "${FILE}" | awk '{print $1}') | |
| echo "${PLATFORM//-/_}=${SHA}" >> $GITHUB_OUTPUT | |
| fi | |
| done | |
| - name: Update formula | |
| run: | | |
| BOTTLE_LINES="" | |
| if [ "${{ needs.check-assets.outputs.has_darwin_arm64 }}" == "true" ]; then | |
| BOTTLE_LINES="${BOTTLE_LINES} sha256 cellar: :any_skip_relocation, arm64_sequoia: \"${{ steps.sha256.outputs.darwin_arm64 }}\"\n" | |
| fi | |
| if [ "${{ needs.check-assets.outputs.has_darwin_amd64 }}" == "true" ]; then | |
| BOTTLE_LINES="${BOTTLE_LINES} sha256 cellar: :any_skip_relocation, sequoia: \"${{ steps.sha256.outputs.darwin_amd64 }}\"\n" | |
| fi | |
| if [ "${{ needs.check-assets.outputs.has_linux_amd64 }}" == "true" ]; then | |
| BOTTLE_LINES="${BOTTLE_LINES} sha256 cellar: :any_skip_relocation, x86_64_linux: \"${{ steps.sha256.outputs.linux_amd64 }}\"\n" | |
| fi | |
| if [ "${{ needs.check-assets.outputs.has_linux_arm64 }}" == "true" ]; then | |
| BOTTLE_LINES="${BOTTLE_LINES} sha256 cellar: :any_skip_relocation, arm64_linux: \"${{ steps.sha256.outputs.linux_arm64 }}\"\n" | |
| fi | |
| sed \ | |
| -e "s|{{BASE_URL}}|${BASE_URL}|g" \ | |
| -e "s|{{BOTTLE_LINES}}|$(printf "${BOTTLE_LINES}")|g" \ | |
| .github/workflows/templates/pinc.rb.template > Formula/pinc.rb | |
| - name: Commit and push formula | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add Formula/pinc.rb | |
| git commit -m "pinc ${VERSION}" | |
| git push |