Repository: SAP/terraform-exporter-btp
Pull request #347: chore: Add Homebrew build action
Author: login: vipinvkmenon
Labels: name: internal
description: Internal tasks
name: ignore-for-release
description: All things not to be mentioned in release notes
Created: 2025-03-26T12:16:47Z | Merged: 2025-03-26T15:24:38Z

## Purpose
<!-- Describe the intention of the changes being proposed. What problem does it solve or functionality does it add? -->
- Brew build action: Will run against latest release
- update-brew-formula scrit creats the brew formula file
- Finally creates PR for the new generated formula
- To add/install run `brew tap SAP/terraform-exporter-btp https://github.com/SAP/terraform-exporter-btp`
-  Until its merged go to location where homebrew clones the repo (`/usr/local/Homebrew/Library/Taps/sap/homebrew-terraform-exporter-btp`) and checkout the `rel-check2` branch
-  Run `brew install sap/terraform-exporter-btp/btptf`

## Does this introduce a breaking change?
<!-- Mark one with an "x". -->
```
[ ] Yes
[x] No
```

## Pull Request Type

What kind of change does this Pull Request introduce?
<!-- Please check the one that applies to this PR using "X". -->
```
[ ] Bugfix
[ ] Feature
[ ] Refactoring (no functional changes, no api changes)
[ ] Documentation content changes
[x] Other... Please describe: Added Hoebrew build action
```



Diff:
diff --git a/.github/scripts/update-btptf-brew-formula.sh b/.github/scripts/update-btptf-brew-formula.sh
new file mode 100755
index 00000000..706e1754
--- /dev/null
+++ b/.github/scripts/update-btptf-brew-formula.sh
@@ -0,0 +1,92 @@
+#!/usr/bin/env bash
+
+tag=${1}
+darwin_sha_amd64=${2}
+darwin_sha_arm64=${3}
+linux_sha_amd64=${4}
+linux_sha_arm64=${5}
+
+if [ -z "${tag}" ]; then
+  echo "release tag is not provided"
+  exit 1
+fi
+
+if [ -z "${darwin_sha_amd64}" ]; then
+  echo "darwin amd64 binary sha256sum is not provided"
+  exit 1
+fi
+
+if [ -z "${darwin_sha_arm64}" ]; then
+  echo "darwin arm64 binary sha256sum is not provided"
+  exit 1
+fi
+
+if [ -z "${linux_sha_amd64}" ]; then
+  echo "linux amd64 binary sha256sum is not provided"
+  exit 1
+fi
+
+if [ -z "${linux_sha_arm64}" ]; then
+  echo "linux arm64 binary sha256sum is not provided"
+  exit 1
+fi
+
+echo $tag
+echo $darwin_sha_amd64
+echo $darwin_sha_arm64
+echo $linux_sha_amd64
+echo $linux_sha_arm64
+
+# Remove the 'v' prefix from the tag if it exists
+version=${tag#v}
+
+# Get the current organization from the environment variable
+org=${GITHUB_REPOSITORY_OWNER}
+
+cat > btptf.rb << EOF
+# typed: true
+# frozen_string_literal: true
+
+# Btptf is a formula for installing BTPTFExporter CLI
+class Btptf < Formula
+  desc "Command-line tool for Exporting SAP BTP Resources to Terraform"
+  homepage "https://sap.github.io/terraform-exporter-btp/"
+  version "$version"
+
+  if OS.mac?
+    if Hardware::CPU.arm?
+      url "https://github.com/SAP/terraform-exporter-btp/releases/download/$tag/btptf_${version}_darwin_arm64"
+      sha256 "$darwin_sha_arm64"
+    else
+      url url "https://github.com/SAP/terraform-exporter-btp/releases/download/$tag/btptf_${version}_darwin_amd64"
+      sha256 "$darwin_sha_amd64"
+    end
+  elsif OS.linux?
+    if Hardware::CPU.arm?
+      url "https://github.com/SAP/terraform-exporter-btp/releases/download/$tag/btptf_${version}_linux_arm64"
+      sha256 "$linux_sha_arm64"
+    else
+      url "https://github.com/SAP/terraform-exporter-btp/releases/download/$tag/btptf_${version}_linux_amd64"
+      sha256 "$linux_sha_amd64"
+      depends_on arch: :x86_64
+    end
+  end
+
+  def install
+    bin.install stable.url.split("/")[-1] => "btptf"
+  end
+
+  def caveats
+    <<~EOS
+      [HINT]
+      Please ensure you have Terraform or OpenTofu installed.
+      Run:
+         btptf --help for more information.
+    EOS
+  end
+
+  test do
+     system "#{bin}/btptf", "--version"
+  end
+end
+EOF
\ No newline at end of file
diff --git a/.github/workflows/update-brew-formula.yaml b/.github/workflows/update-brew-formula.yaml
old mode 100644
new mode 100755
index cf5dc6e7..e1693318
--- a/.github/workflows/update-brew-formula.yaml
+++ b/.github/workflows/update-brew-formula.yaml
@@ -5,11 +5,50 @@ jobs:
   update-btptf-formula:
     runs-on: ubuntu-latest
     steps:
-      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # pin@v4.2.2
+      - uses: actions/checkout@v4
+        with:
+          fetch-depth: 0 # fetch full history
+          filter: tree:0
       - uses: robinraju/release-downloader@v1
         with:
           latest: true
           fileName: '*'
-          out-file-path: 'downloaded-assets'
-      - name: List Contents
-        run: ls -l
+          out-file-path: ${{ runner.temp }}/downloaded-assets
+      - id: latest-release
+        name: latest-release
+        run: |
+          LATEST_TAG=$(git describe --tags --abbrev=0 --match "v*")
+          echo "LATEST_TAG=$LATEST_TAG" >> "$GITHUB_OUTPUT"
+      - name: Extract SHA from release
+        id: extract-sha
+        run: |
+          echo "Event '${{ github.event.action }}'"
+          echo "BTP Terraform binary hash:"
+          tag=$(echo ${{ steps.latest-release.outputs.LATEST_TAG }} | cut -c 2-) 
+          darwin_amd64_sha="btptf_${tag}_darwin_amd64.sha256"
+          echo $darwin_amd64_sha $(cat ${{ runner.temp }}/downloaded-assets/$darwin_amd64_sha)
+          echo "DARWIN_AMD64_SHA=$(cat ${{ runner.temp }}/downloaded-assets/$darwin_amd64_sha)" >> "$GITHUB_OUTPUT"
+
+          darwin_arm_sha="btptf_${tag}_darwin_arm64.sha256"
+          echo $darwin_arm_sha $(cat ${{ runner.temp }}/downloaded-assets/$darwin_arm_sha)
+          echo "DARWIN_ARM_SHA=$(cat ${{ runner.temp }}/downloaded-assets/$darwin_arm_sha)" >> "$GITHUB_OUTPUT"
+
+          linux_amd64_sha="btptf_${tag}_linux_amd64.sha256"
+          echo $linux_amd64_sha $(cat ${{ runner.temp }}/downloaded-assets/$linux_amd64_sha)
+          echo "LINUX_AMD64_SHA=$(cat ${{ runner.temp }}/downloaded-assets/$linux_amd64_sha)" >> "$GITHUB_OUTPUT"
+
+          linux_arm_sha="btptf_${tag}_linux_arm64.sha256"
+          echo $linux_arm_sha $(cat ${{ runner.temp }}/downloaded-assets/$linux_arm_sha)
+          echo "LINUX_ARM_SHA=$(cat ${{ runner.temp }}/downloaded-assets/$linux_arm_sha)" >> "$GITHUB_OUTPUT"
+      - name: Run update script
+        run:  ./.github/scripts/update-btptf-brew-formula.sh ${{ steps.latest-release.outputs.LATEST_TAG }} ${{ steps.extract-sha.outputs.DARWIN_AMD64_SHA }} ${{ steps.extract-sha.outputs.DARWIN_ARM_SHA }} ${{ steps.extract-sha.outputs.LINUX_AMD64_SHA }} ${{ steps.extract-sha.outputs.LINUX_ARM_SHA }}
+      - name: btptf.rb Contents
+        run: cat btptf.rb
+      - name: Create Pull Request
+        uses: peter-evans/create-pull-request@v7 
+        with:
+          add-paths: btptf.rb
+          branch: update_${{ github.event.repository.updated_at }}_${{ steps.latest-release.outputs.LATEST_TAG }}
+          delete-branch: true
+          title: "chore: Update to ${{ steps.latest-release.outputs.LATEST_TAG }}"
+          body: This PR updates btptf.rb to ${{ steps.latest-release.outputs.LATEST_TAG }}
diff --git a/btptf.rb b/btptf.rb
new file mode 100644
index 00000000..84336992
--- /dev/null
+++ b/btptf.rb
@@ -0,0 +1,46 @@
+# typed: true
+# frozen_string_literal: true
+
+# Btptf is a formula for installing BTPTFExporter CLI
+class Btptf < Formula
+    desc "Command-line tool for Exporting SAP BTP Resources to Terraform"
+    homepage "https://sap.github.io/terraform-exporter-btp/"
+    version "1.0.0-rc1"
+  
+    if OS.mac?
+      if Hardware::CPU.arm?
+        url "https://github.com/SAP/terraform-exporter-btp/releases/download/v1.0.0-rc1/btptf_1.0.0-rc1_darwin_arm64"
+        sha256 "dcd0bad837211cea2cf81c94ccc2c5e4457365f6e7ef661523af15faa1aa3416"
+      else
+        url url "https://github.com/SAP/terraform-exporter-btp/releases/download/v1.0.0-rc1/btptf_1.0.0-rc1_darwin_amd64"
+        sha256 "ec5fc58d89050fa4cb4cc4f95a9e77a5375ff9efe053422ea7f831a6d43762a8"
+      end
+    elsif OS.linux?
+      if Hardware::CPU.arm?
+        url "https://github.com/SAP/terraform-exporter-btp/releases/download/v1.0.0-rc1/btptf_1.0.0-rc1_linux_arm64"
+        sha256 "b74ac46699640f1c54620385af445b36cdb21e1ebf32eaa1a092676d8ea32522"
+      else
+        url "https://github.com/SAP/terraform-exporter-btp/releases/download/v1.0.0-rc1/btptf_1.0.0-rc1_linux_amd64"
+        sha256 "63943bee3514411184146335afb890f015571a6b66a3d005501af524f0126f76"
+        depends_on arch: :x86_64
+      end
+    end
+  
+    def install
+      bin.install stable.url.split("/")[-1] => "btptf"
+    end
+  
+    def caveats
+      <<~EOS
+        [HINT]
+        Please ensure you have Terraform or OpenTofu installed.
+        Run:
+           btptf --help for more information.
+      EOS
+    end
+  
+    test do
+       system "#{bin}/btptf", "--version"
+    end
+  end
+  
\ No newline at end of file


Reviews:
user: login: lechnerc77
state: CHANGES_REQUESTED
author_association: MEMBER
submitted_at: 2025-03-26T12:51:54Z
user: login: vipinvkmenon
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-03-26T13:17:50Z
user: login: vipinvkmenon
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-03-26T13:18:01Z
user: login: lechnerc77
state: APPROVED
author_association: MEMBER
submitted_at: 2025-03-26T15:24:30Z

Review comments:
diff_hunk: @@ -0,0 +1,92 @@
+#!/usr/bin/env bash
+
+tag=${1}
+darwin_sha_amd64=${2}
+darwin_sha_arm64=${3}
+linux_sha_amd64=${4}
+linux_sha_arm64=${5}
+
+if [ -z "${tag}" ]; then
+  echo "release tag is not provided"
+  exit 1
+fi
+
+if [ -z "${darwin_sha_amd64}" ]; then
+  echo "darwin amd64 binary sha256sum is not provided"
+  exit 1
+fi
+
+if [ -z "${darwin_sha_arm64}" ]; then
+  echo "darwin arm64 binary sha256sum is not provided"
+  exit 1
+fi
+
+if [ -z "${linux_sha_amd64}" ]; then
+  echo "linux amd64 binary sha256sum is not provided"
+  exit 1
+fi
+
+if [ -z "${linux_sha_arm64}" ]; then
+  echo "linux arm64 binary sha256sum is not provided"
+  exit 1
+fi
+
+echo $tag
+echo $darwin_sha_amd64
+echo $darwin_sha_arm64
+echo $linux_sha_amd64
+echo $linux_sha_arm64
+
+# Remove the 'v' prefix from the tag if it exists
+version=${tag#v}
+
+# Get the current organization from the environment variable
+org=${GITHUB_REPOSITORY_OWNER}
+
+cat > btptf.rb << EOF
+# typed: true
+# frozen_string_literal: true
+
+# InstallBtptf is a formula for installing BTPTFExporter CLI
+class InstallBtptf < Formula
+  desc "Command-line tool for Exporting BTP Resources to Terraform"
path: .github/scripts/update-btptf-brew-formula.sh
user: login: lechnerc77
body: **SAP** BTP
created_at: 2025-03-26T12:47:04Z
author_association: MEMBER
diff_hunk: @@ -0,0 +1,92 @@
+#!/usr/bin/env bash
+
+tag=${1}
+darwin_sha_amd64=${2}
+darwin_sha_arm64=${3}
+linux_sha_amd64=${4}
+linux_sha_arm64=${5}
+
+if [ -z "${tag}" ]; then
+  echo "release tag is not provided"
+  exit 1
+fi
+
+if [ -z "${darwin_sha_amd64}" ]; then
+  echo "darwin amd64 binary sha256sum is not provided"
+  exit 1
+fi
+
+if [ -z "${darwin_sha_arm64}" ]; then
+  echo "darwin arm64 binary sha256sum is not provided"
+  exit 1
+fi
+
+if [ -z "${linux_sha_amd64}" ]; then
+  echo "linux amd64 binary sha256sum is not provided"
+  exit 1
+fi
+
+if [ -z "${linux_sha_arm64}" ]; then
+  echo "linux arm64 binary sha256sum is not provided"
+  exit 1
+fi
+
+echo $tag
+echo $darwin_sha_amd64
+echo $darwin_sha_arm64
+echo $linux_sha_amd64
+echo $linux_sha_arm64
+
+# Remove the 'v' prefix from the tag if it exists
+version=${tag#v}
+
+# Get the current organization from the environment variable
+org=${GITHUB_REPOSITORY_OWNER}
+
+cat > btptf.rb << EOF
+# typed: true
+# frozen_string_literal: true
+
+# InstallBtptf is a formula for installing BTPTFExporter CLI
+class InstallBtptf < Formula
+  desc "Command-line tool for Exporting BTP Resources to Terraform"
+  homepage "https://sap.github.io/terraform-exporter-btp/"
+  version "$version"
+
+  if OS.mac?
+    if Hardware::CPU.arm?
+      url "https://github.com/SAP/terraform-exporter-btp/releases/download/$tag/btptf_${version}_darwin_arm64"
+      sha256 "$darwin_sha_arm64"
+    else
+      url url "https://github.com/SAP/terraform-exporter-btp/releases/download/$tag/btptf_${version}_darwin_amd64"
+      sha256 "$darwin_sha_amd64"
+    end
+  elsif OS.linux?
+    if Hardware::CPU.arm?
+      url "https://github.com/SAP/terraform-exporter-btp/releases/download/$tag/btptf_${version}_linux_arm64"
+      sha256 "$linux_sha_arm64"
+    else
+      url "https://github.com/SAP/terraform-exporter-btp/releases/download/$tag/btptf_${version}_linux_amd64"
+      sha256 "$linux_sha_amd64"
+      depends_on arch: :x86_64
+    end
+  end
+
+  def install
+    bin.install stable.url.split("/")[-1] => "btptf"
+  end
+
+  def caveats
+    <<~EOS
+      [HINT]
+      Please ensure you have Terraform installed.
path: .github/scripts/update-btptf-brew-formula.sh
user: login: lechnerc77
body: Terraform or OpenTofu
created_at: 2025-03-26T12:47:36Z
author_association: MEMBER
diff_hunk: @@ -6,10 +6,49 @@ jobs:
     runs-on: ubuntu-latest
     steps:
       - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # pin@v4.2.2
path: .github/workflows/update-brew-formula.yaml
user: login: lechnerc77
body: Why the pin?
created_at: 2025-03-26T12:48:12Z
author_association: MEMBER
diff_hunk: @@ -0,0 +1,46 @@
+# typed: true
path: btptf.rb
user: login: lechnerc77
body: Is this a file we would commit?
created_at: 2025-03-26T12:51:49Z
author_association: MEMBER
diff_hunk: @@ -0,0 +1,46 @@
+# typed: true
path: btptf.rb
user: login: vipinvkmenon
body: Ideally, the GH action should generate this file and create the PR. For the first commit, I manually added the file so that it can be tested as well.
created_at: 2025-03-26T13:17:50Z
author_association: MEMBER
diff_hunk: @@ -6,10 +6,49 @@ jobs:
     runs-on: ubuntu-latest
     steps:
       - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # pin@v4.2.2
path: .github/workflows/update-brew-formula.yaml
user: login: vipinvkmenon
body: Removing
created_at: 2025-03-26T13:18:00Z
author_association: MEMBER

PR comments:
user: login: lechnerc77
created_at: 2025-03-26T12:53:04Z
body: Partially adresses #48 i.e., for the MacOS channel (and Linux if brew is used there)
author_association: MEMBER
user: login: sonarqubecloud[bot]
created_at: 2025-03-26T13:37:20Z
body: ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=SAP_terraform-exporter-btp&pullRequest=347) **Quality Gate passed**  
Issues  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=SAP_terraform-exporter-btp&pullRequest=347&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=SAP_terraform-exporter-btp&pullRequest=347&issueStatuses=ACCEPTED)

Measures  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=SAP_terraform-exporter-btp&pullRequest=347&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=SAP_terraform-exporter-btp&pullRequest=347&metric=new_coverage&view=list)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=SAP_terraform-exporter-btp&pullRequest=347&metric=new_duplicated_lines_density&view=list)  
  
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=SAP_terraform-exporter-btp&pullRequest=347)


author_association: NONE