Add Homebrew update step to release workflow #9
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: Build and Release | |
| on: | |
| push: | |
| tags: | |
| - 'v*' | |
| jobs: | |
| build-and-release: | |
| if: "!contains(github.event.head_commit.message, '[skip ci]')" | |
| strategy: | |
| matrix: | |
| include: | |
| - os: ubuntu-latest | |
| arch: amd64 | |
| platform: linux | |
| artifact_name: todo-app | |
| - os: ubuntu-latest | |
| arch: arm64 | |
| platform: linux | |
| artifact_name: todo-app | |
| - os: macos-latest | |
| arch: amd64 | |
| platform: macos | |
| artifact_name: todo-app | |
| - os: macos-latest | |
| arch: arm64 | |
| platform: macos | |
| artifact_name: todo-app | |
| - os: windows-latest | |
| arch: amd64 | |
| platform: windows | |
| artifact_name: todo-app.exe | |
| - os: windows-latest | |
| arch: arm64 | |
| platform: windows | |
| artifact_name: todo-app.exe | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install ARM64 Cross-Compiler (Linux) | |
| if: matrix.platform == 'linux' && matrix.arch == 'arm64' | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu | |
| - uses: jwlawson/actions-setup-cmake@v2 | |
| with: | |
| cmake-version: '3.25.x' | |
| - name: Configure CMake | |
| run: | | |
| if [ "${{ matrix.platform }}" = "linux" ] && [ "${{ matrix.arch }}" = "arm64" ]; then | |
| cmake -B build -DCMAKE_BUILD_TYPE=Release \ | |
| -DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc \ | |
| -DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++ | |
| elif [ "${{ matrix.platform }}" = "macos" ] && [ "${{ matrix.arch }}" = "arm64" ]; then | |
| cmake -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_ARCHITECTURES=arm64 | |
| elif [ "${{ matrix.platform }}" = "windows" ] && [ "${{ matrix.arch }}" = "arm64" ]; then | |
| cmake -B build -DCMAKE_BUILD_TYPE=Release -A ARM64 | |
| else | |
| cmake -B build -DCMAKE_BUILD_TYPE=Release | |
| fi | |
| shell: bash | |
| - name: Build | |
| run: cmake --build build --config Release | |
| - name: Prepare Artifacts and Checksum | |
| shell: bash | |
| run: | | |
| mkdir -p out | |
| VERSION=${GITHUB_REF_NAME} | |
| ASSET_NAME="todo-app-${VERSION}-${{ matrix.platform }}-${{ matrix.arch }}" | |
| if [ "${{ matrix.platform }}" = "windows" ]; then | |
| FINAL_NAME="${ASSET_NAME}.exe" | |
| if [ -f "build/Release/${{ matrix.artifact_name }}" ]; then | |
| cp "build/Release/${{ matrix.artifact_name }}" "out/${FINAL_NAME}" | |
| else | |
| cp "build/${{ matrix.artifact_name }}" "out/${FINAL_NAME}" | |
| fi | |
| else | |
| FINAL_NAME="${ASSET_NAME}" | |
| cp build/${{ matrix.artifact_name }} out/${FINAL_NAME} | |
| chmod +x out/${FINAL_NAME} | |
| fi | |
| # Generate individual checksum | |
| cd out | |
| if command -v sha256sum >/dev/null 2>&1; then | |
| sha256sum "${FINAL_NAME}" > "${FINAL_NAME}.sha256" | |
| else | |
| shasum -a 256 "${FINAL_NAME}" > "${FINAL_NAME}.sha256" | |
| fi | |
| echo "artifact_path=out/${FINAL_NAME}" >> $GITHUB_ENV | |
| echo "checksum_path=out/${FINAL_NAME}.sha256" >> $GITHUB_ENV | |
| - name: Upload Artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ matrix.platform }}-${{ matrix.arch }} | |
| path: | | |
| ${{ env.artifact_path }} | |
| ${{ env.checksum_path }} | |
| release: | |
| needs: build-and-release | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: all-artifacts | |
| merge-multiple: true | |
| - name: Combine Checksums | |
| working-directory: all-artifacts | |
| run: | | |
| # Combine all .sha256 files into one checksums.txt | |
| cat *.sha256 > checksums.txt | |
| # Remove the individual .sha256 files to keep the release clean | |
| rm *.sha256 | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ github.ref_name }} | |
| name: "CLI Todo App ${{ github.ref_name }}" | |
| draft: false | |
| prerelease: false | |
| generate_release_notes: true | |
| files: | | |
| all-artifacts/* | |
| update-homebrew: | |
| needs: release | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Wait for Release Assets | |
| run: sleep 30 | |
| - name: Update Homebrew Formula | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }} | |
| run: | | |
| VERSION=${GITHUB_REF_NAME#v} | |
| REPO_NAME="cli-todo-app" | |
| TAP_REPO="GourangaDasSamrat/homebrew-tap" | |
| # Download prebuilt macOS binaries to calculate SHA256 | |
| wget https://github.com/GourangaDasSamrat/${REPO_NAME}/releases/download/${GITHUB_REF_NAME}/todo-app-${GITHUB_REF_NAME}-macos-arm64 | |
| wget https://github.com/GourangaDasSamrat/${REPO_NAME}/releases/download/${GITHUB_REF_NAME}/todo-app-${GITHUB_REF_NAME}-macos-amd64 | |
| ARM64_SHA=$(sha256sum todo-app-${GITHUB_REF_NAME}-macos-arm64 | awk '{print $1}') | |
| AMD64_SHA=$(sha256sum todo-app-${GITHUB_REF_NAME}-macos-amd64 | awk '{print $1}') | |
| echo "ARM64 SHA: ${ARM64_SHA}" | |
| echo "AMD64 SHA: ${AMD64_SHA}" | |
| # Clone tap repository | |
| git clone https://x-access-token:${GITHUB_TOKEN}@github.com/${TAP_REPO}.git tap | |
| cd tap | |
| # Update formula with prebuilt binaries | |
| cat > Formula/cli-todo-app.rb <<EOF | |
| class CliTodoApp < Formula | |
| desc "Feature-rich, cross-platform CLI Todo app written in modern C++" | |
| homepage "https://github.com/GourangaDasSamrat/cli-todo-app" | |
| version "${VERSION}" | |
| license "MIT" | |
| if Hardware::CPU.arm? | |
| url "https://github.com/GourangaDasSamrat/cli-todo-app/releases/download/v${VERSION}/todo-app-v${VERSION}-macos-arm64" | |
| sha256 "${ARM64_SHA}" | |
| else | |
| url "https://github.com/GourangaDasSamrat/cli-todo-app/releases/download/v${VERSION}/todo-app-v${VERSION}-macos-amd64" | |
| sha256 "${AMD64_SHA}" | |
| end | |
| def install | |
| bin.install "todo-app-v${VERSION}-macos-arm64" => "todo-app" if Hardware::CPU.arm? | |
| bin.install "todo-app-v${VERSION}-macos-amd64" => "todo-app" if Hardware::CPU.intel? | |
| end | |
| test do | |
| system "#{bin}/todo-app", "--version" | |
| end | |
| end | |
| EOF | |
| # Commit and push | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add Formula/cli-todo-app.rb | |
| git commit -m "Update cli-todo-app to v${VERSION}" | |
| git push |