Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: test formula on bump #20

Merged
merged 24 commits into from
Feb 19, 2025
2 changes: 1 addition & 1 deletion .github/scripts/update-formula/cli/gen.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -e
set -eu
# Purpose: generate a forumla for "CycloneDX-gomod"

UF_REPO='CycloneDX/cyclonedx-cli'
Expand Down
12 changes: 6 additions & 6 deletions .github/scripts/update-formula/cli/template.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
class CyclonedxCli < Formula
desc "CycloneDX CLI tool for SBOM analysis, merging, diffs and format conversions."
desc "CLI tool for CycloneDX 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
url "https://github.com/CycloneDX/cyclonedx-cli/releases/download/v%VERSION%/cyclonedx-osx-x64", using: :nounzip
sha256 "%SHA256SUM_osx-x64%"

def install
Expand All @@ -25,23 +25,23 @@ def install

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
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
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
url "https://github.com/CycloneDX/cyclonedx-cli/releases/download/v%VERSION%/cyclonedx-linux-x64", using: :nounzip
sha256 "%SHA256SUM_linux-x64%"

def install
Expand All @@ -51,6 +51,6 @@ def install
end

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

UF_REPO='CycloneDX/cyclonedx-gomod'
Expand Down
10 changes: 5 additions & 5 deletions .github/scripts/update-formula/gomod/template.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
class CyclonedxGomod < Formula
desc "Creates CycloneDX Software Bill of Materials (SBOM) from Go modules."
desc "Creates CycloneDX Software Bill of Materials (SBOM) from Go modules"
homepage "https://cyclonedx.org"
version "%VERSION%"
license "Apache-2.0"

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

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"
Expand Down Expand Up @@ -42,10 +45,7 @@ def install
end
end

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

test do
system "#{bin}/cyclonedx-gomod" "version"
system bin/"cyclonedx-gomod", "version"
end
end
96 changes: 85 additions & 11 deletions .github/workflows/update-formula.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# docs: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions

name: Update a formula

on:
Expand All @@ -15,39 +17,111 @@ on:
required: true
type: string

permissions:
contents: write # push commits
pull-requests: write # create pullrequests
concurrency:
group: '${{ github.workflow }}-${{ github.event.inputs.subject }}'
cancel-in-progress: true

env:
UF_SUBJECT: ${{ github.event.inputs.subject }}
UF_VERSION: ${{ github.event.inputs.version }}
ARTIFACT_FORMULA: formula
ARTIFACT_FORMULA_FIXED: formula_fixed

jobs:
update:
name: "update formula: ${{ github.event.inputs.subject }} ${{ github.event.inputs.version }}"
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
.github/scripts/update-formula/"$UF_SUBJECT"/gen.sh
"${UF_VERSION}"
> Formula/cyclonedx-"${UF_SUBJECT}".rb
> Formula/cyclonedx-"$UF_SUBJECT".rb
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Artifact Formula
# https://github.com/actions/upload-artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.ARTIFACT_FORMULA }}
path: Formula/cyclonedx-${{ env.UF_SUBJECT }}.rb
if-no-files-found: error
retention-days: 3
fix-test:
# https://docs.brew.sh/Adding-Software-to-Homebrew#testing-and-auditing-the-formula
needs: [ "update" ]
name: "Fix & Test Formula"
runs-on: macos-latest
timeout-minutes: 10
env:
HOMEBREW_NO_AUTO_UPDATE: '1'
HOMEBREW_NO_INSTALL_FROM_API: '1'
TAP_TESTING: 'local/testing'
steps:
- run: brew developer on
- name: Fetch Formula
# https://github.com/actions/download-artifact
uses: actions/download-artifact@v4
with:
name: ${{ env.ARTIFACT_FORMULA }}
- name: brew tap formula
run: |
set -eux
brew tap-new "$TAP_TESTING" --no-git
ln -s "$PWD/cyclonedx-${UF_SUBJECT}.rb" "$(brew --repo "$TAP_TESTING")"/Formula/
- name: Audit & fix Formula
run: brew audit --fix --stric --online "${TAP_TESTING}/cyclonedx-${UF_SUBJECT}"
- name: Artifact fixed Formula
# `brew audit` might fail, but still fix. in this case, we should modify the template accordingly
if: ${{ ! cancelled() }}
# https://github.com/actions/upload-artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.ARTIFACT_FORMULA_FIXED }}
path: cyclonedx-${{ env.UF_SUBJECT }}.rb
if-no-files-found: error
retention-days: 3
- name: Test Formula
run: |
set -eux
FORMULA="${TAP_TESTING}/cyclonedx-${UF_SUBJECT}"
brew install --build-from-source "$FORMULA"
brew deps "$FORMULA"
brew test --verbose "$FORMULA"
brew uninstall "$FORMULA"
pullrequest:
name: "Commit/PR Formula"
permissions:
contents: write # push commits
pull-requests: write # create pullrequests
needs: [ "fix-test" ]
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
# see https://github.com/actions/checkout
uses: actions/checkout@v4
- name: Fetch fixed Formula
# https://github.com/actions/download-artifact
uses: actions/download-artifact@v4
with:
name: ${{ env.ARTIFACT_FORMULA_FIXED }}
path: Formula
- name: Commit & Push
run: |
BRANCH_NAME="update-formula/${UF_SUBJECT}-${UF_VERSION}"
set -eux
BRANCH_NAME='${{ github.ref_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 -s -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"
run: gh pr create --fill-verbose --label "$UF_SUBJECT" -B '${{ github.ref_name }}'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}