Skip to content

Commit

Permalink
Automate formula build and asset upload
Browse files Browse the repository at this point in the history
  • Loading branch information
tautschnig committed Sep 20, 2024
1 parent 92f1547 commit 649fd5e
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 3 deletions.
78 changes: 78 additions & 0 deletions .github/workflows/add-formula.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Add CBMC formula

on:
schedule:
- cron: "0 */6 * * *" # Run this every 6 hours
workflow_dispatch: # Allow manual dispatching for a custom branch / tag.

permissions:
checks: write
contents: write
pull-requests: write

jobs:
create-formula-pr:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Obtain latest CBMC release
env:
GH_TOKEN: ${{ github.token }}
run: |
CBMC_LATEST=$(gh -R diffblue/cbmc release list | grep Latest | awk '{print $1}' | cut -f2 -d-)
echo "CBMC_LATEST: ${CBMC_LATEST}"
echo "CBMC_LATEST=${CBMC_LATEST}" >> $GITHUB_ENV
# check whether we already have the formula
if [ -e "Formula/cbmc@${CBMC_LATEST}.rb" ] ; then
echo "next_step=none" >> $GITHUB_ENV
else
CBMC_LATEST_REV=$(gh -R diffblue/cbmc release view cbmc-"${CBMC_LATEST}" --json targetCommitish | jq -r '.targetCommitish')
echo "CBMC_LATEST_REV: ${CBMC_LATEST_REV}"
echo "CBMC_LATEST_REV=${CBMC_LATEST_REV}" >> $GITHUB_ENV
echo "next_step=check_brew" >> $GITHUB_ENV
fi
- name: Set up Homebrew
if: ${{ env.next_step == 'check_brew' }}
uses: Homebrew/actions/setup-homebrew@master

- name: Check CBMC version in brew
if: ${{ env.next_step == 'check_brew' }}
run: |
brew update
CBMC_BREW=$(brew info cbmc --json | jq -r '.[0].versions.stable')
echo "CBMC_BREW: ${CBMC_BREW}"
if [ "x${CBMC_BREW}" = "x${CBMC_LATEST}" ] ; then
formula_base=$(ls Formula | tail -1)
sed '/bottle do/Q' "Formula/${formula_base}" > "Formula/cbmc@${CBMC_LATEST}.rb"
version_no_dot=$(echo "${CBMC_LATEST}" | sed 's/\.//g')
sed -i "1s/CbmcAT[[:digit:]]*/CbmcAT${version_no_dot}/" "Formula/cbmc@${CBMC_LATEST}.rb"
sed -i "5s/\".*\"/\"cbmc-${CBMC_LATEST}\"/" "Formula/cbmc@${CBMC_LATEST}.rb"
sed -i "6s/\".*\"/\"cbmc-${CBMC_LATEST_REV}\"/" "Formula/cbmc@${CBMC_LATEST}.rb"
./transform_binary.sh "${CBMC_LATEST}" >> "Formula/cbmc@${CBMC_LATEST}.rb"
sed -n '1,/end$/!p' "Formula/${formula_base}" >> "Formula/cbmc@${CBMC_LATEST}.rb"
echo "next_step=upload_and_create_pr" >> $GITHUB_ENV
else
echo "next_step=none" >> $GITHUB_ENV
fi
- name: Upload bottles
if: ${{ env.next_step == 'upload_and_create_pr' }}
uses: softprops/action-gh-release@v2
with:
name: bag-of-goodies
files: cbmc@*.tar.gz

- name: Create Pull Request
if: ${{ env.next_step == 'upload_and_create_pr' }}
uses: peter-evans/create-pull-request@v7
with:
commit-message: Add formula for CBMC ${{ env.CBMC_LATEST }}
add-paths: Formula/cbmc@*.rb
branch: cbmc-${{ env.CBMC_LATEST }}
delete-branch: true
title: 'Add formula for CBMC ${{ env.CBMC_LATEST }}'
body: >
Add brew formula for CBMC's latest release.
6 changes: 3 additions & 3 deletions transform_binary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ CBMC_STRING="CbmcAT"
VERSION_PROCESSED="${VERSION//./}"
FORMULA_VERSION="${CBMC_STRING}${VERSION_PROCESSED}"

echo "bottle do"
echo " root_url \"https://github.com/diffblue/homebrew-cbmc/releases/download/bag-of-goodies\""
echo " bottle do"
echo " root_url \"https://github.com/diffblue/homebrew-cbmc/releases/download/bag-of-goodies\""
for TAG in "arm64_sonoma" "arm64_ventura" "arm64_monterey" "sonoma" "ventura" "monterey" "x86_64_linux"
do
#echo "Processing bottle for $VERSION -- $TAG"
Expand Down Expand Up @@ -46,4 +46,4 @@ do
LINE="${TAG_SPACED}\"${SHA%%[[:space:]]*}\""
echo "${LINE}"
done
echo end
echo " end"

0 comments on commit 649fd5e

Please sign in to comment.