update-homebrew-formula #75
This file contains 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 Homebrew Formula | |
permissions: | |
contents: write | |
on: | |
workflow_dispatch: | |
repository_dispatch: | |
types: [update-homebrew-formula] | |
jobs: | |
update-formula: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Only deploy on repository_dispatch if version starts with 'v' | |
run: | | |
echo "Event name: ${{ github.event_name }}" | |
echo "Type: ${{ github.event.action }}" | |
echo "Version: ${{ github.event.client_payload.version }}" | |
if [[ "${{ github.event_name }}" == "repository_dispatch" && "${{ github.event.action }}" == "update-homebrew-formula" ]]; then | |
echo "Version: ${{ github.event.client_payload.version }}" | |
if [[ "${{ github.event.client_payload.version }}" != v* ]]; then | |
echo "Version does not start with 'v'. Stopping workflow." | |
exit 1 | |
fi | |
fi | |
shell: bash | |
- name: Checkout Homebrew repository | |
uses: actions/checkout@v4 | |
- name: Fetch the latest release from CLI repository | |
id: latest-release | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const { data } = await github.rest.repos.getLatestRelease({ | |
owner: process.env.GITHUB_REPOSITORY_OWNER, | |
repo: 'defang' | |
}); | |
return { | |
tag_name: data.tag_name, | |
tarball_url: data.tarball_url | |
}; | |
result-encoding: json | |
- name: Set environment variables for latest release | |
run: | | |
# [WORKAROUND] Even though the github-script output is supposed to be JSON, looks like we are getting a string | |
TAG_NAME=$(echo '${{ steps.latest-release.outputs.result }}' | jq -r '.tag_name') | |
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV | |
# Fixes FormulaAudit/Urls: Use /archive/ URLs for GitHub tarballs | |
echo "TARBALL_URL=https://github.com/DefangLabs/defang/archive/refs/tags/$TAG_NAME.tar.gz" >> $GITHUB_ENV | |
- name: Compute SHA256 checksum | |
run: | | |
SHA256=$(curl -L $TARBALL_URL | sha256sum | awk '{print $1}') | |
echo "SHA256=$SHA256" >> $GITHUB_ENV | |
- name: Update Homebrew formula | |
run: | | |
formula_path="Formula/defang.rb" | |
sed -i.bak "s|url \".*|url \"$TARBALL_URL\"|g" $formula_path | |
sed -i.bak "s|sha256 \".*|sha256 \"$SHA256\"|g" $formula_path | |
- name: Commit and push changes | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Action" | |
git add Formula/defang.rb | |
git commit -m "Update Homebrew formula to version $TAG_NAME" | |
git push | |
git tag "$TAG_NAME" | |
git push --tags | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |