Skip to content

Commit

Permalink
Merge pull request #12 from jkowalleck/chore/automation-init
Browse files Browse the repository at this point in the history
chore: automate formula updates
  • Loading branch information
jkowalleck authored Oct 28, 2024
2 parents ed6276d + 22a9724 commit a9b1e2f
Show file tree
Hide file tree
Showing 6 changed files with 221 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .github/scripts/update-formula/cli/gen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash
set -e
# Purpose: generate a forumla for "CycloneDX-gomod"

UF_REPO='CycloneDX/cyclonedx-cli'
UF_VERSION="$1"

THIS_DIR="$(realpath "$(dirname "$0")" )"
TMP_DIR="$(mktemp -d "$THIS_DIR/.tmp.fu.XXXXXXXX")"

formula="$(< "$THIS_DIR/template.rb")"

gh release download \
"v${UF_VERSION}" \
--repo "$UF_REPO" \
--pattern "cyclonedx-osx-*" \
--pattern "cyclonedx-linux-*" \
--dir "$TMP_DIR" \
1>&2

for _target in 'osx-x64' 'osx-arm64' 'linux-arm64' 'linux-arm' 'linux-x64'
do
_sha256sum="$(sha256sum -b "${TMP_DIR}/cyclonedx-${_target}" | cut -f1 -d' ')"
formula=${formula//%SHA256SUM_${_target}%/$_sha256sum}
done

rm -rf "$TMP_DIR" 1>&2

echo "${formula//%VERSION%/$UF_VERSION}"
56 changes: 56 additions & 0 deletions .github/scripts/update-formula/cli/template.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
class CyclonedxCli < Formula
desc "CycloneDX CLI tool for SBOM analysis, merging, diffs and format conversions."
homepage "https://cyclonedx.org"
version "%VERSION%"
license "Apache-2.0"

on_macos do
if Hardware::CPU.intel?
url "https://github.com/CycloneDX/cyclonedx-cli/releases/download/v%VERSION%/cyclonedx-osx-x64", :using => :nounzip
sha256 "%SHA256SUM_osx-x64%"

def install
bin.install "cyclonedx-osx-x64" => "cyclonedx"
end
end
if Hardware::CPU.arm?
url "https://github.com/CycloneDX/cyclonedx-cli/releases/download/v%VERSION%/cyclonedx-osx-arm64"
sha256 "%SHA256SUM_osx-arm64%"

def install
bin.install "cyclonedx-osx-arm64" => "cyclonedx"
end
end
end

on_linux do
if Hardware::CPU.arm? && Hardware::CPU.is_64_bit?
url "https://github.com/CycloneDX/cyclonedx-cli/releases/download/v%VERSION%/cyclonedx-linux-arm64", :using => :nounzip
sha256 "%SHA256SUM_linux-arm64%"

def install
bin.install "cyclonedx-linux-arm64" => "cyclonedx"
end
end
if Hardware::CPU.arm? && !Hardware::CPU.is_64_bit?
url "https://github.com/CycloneDX/cyclonedx-cli/releases/download/v%VERSION%/cyclonedx-linux-arm", :using => :nounzip
sha256 "%SHA256SUM_linux-arm%"

def install
bin.install "cyclonedx-linux-arm" => "cyclonedx"
end
end
if Hardware::CPU.intel?
url "https://github.com/CycloneDX/cyclonedx-cli/releases/download/v%VERSION%/cyclonedx-linux-x64", :using => :nounzip
sha256 "%SHA256SUM_linux-x64%"

def install
bin.install "cyclonedx-linux-x64" => "cyclonedx"
end
end
end

test do
system "#{bin}/cyclonedx" "--version"
end
end
29 changes: 29 additions & 0 deletions .github/scripts/update-formula/gomod/gen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash
set -e
# Purpose: generate a forumla for "CycloneDX-gomod"

UF_REPO='CycloneDX/cyclonedx-gomod'
UF_VERSION="$1"

THIS_DIR="$(realpath "$(dirname "$0")" )"
TMP_DIR="$(mktemp -d "$THIS_DIR/.tmp.fu.XXXXXXXX")"

formula="$(< "$THIS_DIR/template.rb")"

gh release download \
"v${UF_VERSION}" \
--repo "$UF_REPO" \
--pattern "cyclonedx-gomod_${UF_VERSION}_darwin_*.tar.gz" \
--pattern "cyclonedx-gomod_${UF_VERSION}_linux_*.tar.gz" \
--dir "$TMP_DIR" \
1>&2

for _target in 'darwin_amd64' 'darwin_arm64' 'linux_arm64' 'linux_amd64'
do
_sha256sum="$(sha256sum -b "${TMP_DIR}/cyclonedx-gomod_${UF_VERSION}_${_target}.tar.gz" | cut -f1 -d' ')"
formula=${formula//%SHA256SUM_${_target}%/$_sha256sum}
done

rm -rf "$TMP_DIR" 1>&2

echo "${formula//%VERSION%/$UF_VERSION}"
51 changes: 51 additions & 0 deletions .github/scripts/update-formula/gomod/template.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
class CyclonedxGomod < Formula
desc "Creates CycloneDX Software Bill of Materials (SBOM) from Go modules."
homepage "https://cyclonedx.org"
version "%VERSION%"
license "Apache-2.0"

on_macos do
if Hardware::CPU.intel?
url "https://github.com/CycloneDX/cyclonedx-gomod/releases/download/v%VERSION%/cyclonedx-gomod_%VERSION%_darwin_amd64.tar.gz"
sha256 "%SHA256SUM_darwin_amd64%"

def install
bin.install "cyclonedx-gomod"
end
end
if Hardware::CPU.arm?
url "https://github.com/CycloneDX/cyclonedx-gomod/releases/download/v%VERSION%/cyclonedx-gomod_%VERSION%_darwin_arm64.tar.gz"
sha256 "%SHA256SUM_darwin_arm64%"

def install
bin.install "cyclonedx-gomod"
end
end
end

on_linux do
if Hardware::CPU.arm?
url "https://github.com/CycloneDX/cyclonedx-gomod/releases/download/v%VERSION%/cyclonedx-gomod_%VERSION%_linux_arm64.tar.gz"
sha256 "%SHA256SUM_linux_arm64%"

def install
bin.install "cyclonedx-gomod"
end
end
if Hardware::CPU.intel?
url "https://github.com/CycloneDX/cyclonedx-gomod/releases/download/v%VERSION%/cyclonedx-gomod_%VERSION%_linux_amd64.tar.gz"
sha256 "%SHA256SUM_linux_amd64%"

def install
bin.install "cyclonedx-gomod"
end
end
end

depends_on "go" => :optional
depends_on "git" => :optional

test do
system "#{bin}/cyclonedx-gomod" "version"
end
end
53 changes: 53 additions & 0 deletions .github/workflows/update-formula.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Update a formula

on:
workflow_dispatch:
inputs:
subject:
description: which formula to update?
required: true
type: choice
options:
- cli
- gomod
version:
description: which version shall be published
required: true
type: string

permissions:
contents: write # push commits
pull-requests: write # create pullrequests

jobs:
update:
name: "update formula: ${{ github.event.inputs.subject }} ${{ github.event.inputs.version }}"
runs-on: ubuntu-latest
timeout-minutes: 10
env:
UF_SUBJECT: ${{ github.event.inputs.subject }}
UF_VERSION: ${{ github.event.inputs.version }}
steps:
- name: Checkout
# see https://github.com/actions/checkout
uses: actions/checkout@v4
- name: Update Formula
run: >
.github/scripts/update-formula/"${UF_SUBJECT}"/gen.sh
"${UF_VERSION}"
> Formula/cyclonedx-"${UF_SUBJECT}".rb
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Commit & Push
run: |
BRANCH_NAME="update-formula/${UF_SUBJECT}-${UF_VERSION}"
git checkout -B "$BRANCH_NAME"
git add -A Formula
git config user.name "[BOT] Formula Updater"
git config user.email "[email protected]"
git commit -m "Update ${UF_SUBJECT}: ${UF_VERSION}"
git push -f --set-upstream origin "$BRANCH_NAME"
- name: Open PullRequest
run: gh pr create --fill-verbose --label "$UF_SUBJECT"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 3 additions & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# all maintainers are default-reviewers of new pull requests.
# see https://github.com/orgs/CycloneDX/teams/maintainers
* @CycloneDX/maintainers

0 comments on commit a9b1e2f

Please sign in to comment.