From 22a9724a8429faf8f47fe4bdc30f28393373d6a7 Mon Sep 17 00:00:00 2001 From: Jan Kowalleck Date: Sun, 27 Oct 2024 12:17:30 +0100 Subject: [PATCH] chore: automate formula updates Signed-off-by: Jan Kowalleck --- .github/scripts/update-formula/cli/gen.sh | 29 ++++++++++ .../scripts/update-formula/cli/template.rb | 56 +++++++++++++++++++ .github/scripts/update-formula/gomod/gen.sh | 29 ++++++++++ .../scripts/update-formula/gomod/template.rb | 51 +++++++++++++++++ .github/workflows/update-formula.yml | 53 ++++++++++++++++++ CODEOWNERS | 3 + 6 files changed, 221 insertions(+) create mode 100755 .github/scripts/update-formula/cli/gen.sh create mode 100644 .github/scripts/update-formula/cli/template.rb create mode 100755 .github/scripts/update-formula/gomod/gen.sh create mode 100644 .github/scripts/update-formula/gomod/template.rb create mode 100644 .github/workflows/update-formula.yml create mode 100644 CODEOWNERS diff --git a/.github/scripts/update-formula/cli/gen.sh b/.github/scripts/update-formula/cli/gen.sh new file mode 100755 index 0000000..8678f52 --- /dev/null +++ b/.github/scripts/update-formula/cli/gen.sh @@ -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}" diff --git a/.github/scripts/update-formula/cli/template.rb b/.github/scripts/update-formula/cli/template.rb new file mode 100644 index 0000000..cf08fd4 --- /dev/null +++ b/.github/scripts/update-formula/cli/template.rb @@ -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 diff --git a/.github/scripts/update-formula/gomod/gen.sh b/.github/scripts/update-formula/gomod/gen.sh new file mode 100755 index 0000000..76202a6 --- /dev/null +++ b/.github/scripts/update-formula/gomod/gen.sh @@ -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}" diff --git a/.github/scripts/update-formula/gomod/template.rb b/.github/scripts/update-formula/gomod/template.rb new file mode 100644 index 0000000..e5f3f75 --- /dev/null +++ b/.github/scripts/update-formula/gomod/template.rb @@ -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 diff --git a/.github/workflows/update-formula.yml b/.github/workflows/update-formula.yml new file mode 100644 index 0000000..bd479ea --- /dev/null +++ b/.github/workflows/update-formula.yml @@ -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 "formula-updater@bot.local" + 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 }} diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 0000000..330376d --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1,3 @@ +# all maintainers are default-reviewers of new pull requests. +# see https://github.com/orgs/CycloneDX/teams/maintainers +* @CycloneDX/maintainers