Skip to content

Commit

Permalink
Added Homebrew Tap Capability (jozu-ai#520)
Browse files Browse the repository at this point in the history
* Added Homebrew Tap Capability

- updated platform-release.yaml to include steps required for homebrew tap functionality
-updated .goreleaser.darwin.yaml to export MacOS binaries in both .zip and .tar.gz formats
- added create-homebrew-recipe.awk
- added kitops.rb.template

* Update .github/workflows/platform-release.yaml

suggestion from Angel

Co-authored-by: Angel Misevski <[email protected]>

* Update platform-release.yaml

Incorporated Angel's feedback

* Update platform-release.yaml

Fixed indention issues

* Update .goreleaser.darwin.yaml

removed i386 from supported MacOS builds

---------

Co-authored-by: Angel Misevski <[email protected]>
  • Loading branch information
brett-hodges and amisevsk authored Oct 9, 2024
1 parent 28d7d80 commit 4a7308a
Show file tree
Hide file tree
Showing 4 changed files with 226 additions and 14 deletions.
131 changes: 119 additions & 12 deletions .github/workflows/platform-release.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Release with Platform builds

on:
on:
workflow_dispatch:
inputs:
skip_signing:
Expand Down Expand Up @@ -88,6 +88,7 @@ jobs:
retention-days: 7
path: |
./dist/*.zip
./dist/*.tar.gz
build-windows:
runs-on: windows-latest
Expand Down Expand Up @@ -145,29 +146,60 @@ jobs:
retention-days: 7
path: |
./dist/*.tar.gz
# Creates a release with the artifacts from the previous steps.
# Creates a release using artifacts created in the previous steps.
# workflow_dispatch triggered versions will be draft releases.
# CLI docs are not updated for workflow_dispatch triggered versions.
release:
runs-on: ubuntu-latest
needs: [build-linux, build-macos, build-windows]
steps:
- name: Merge built artifacts
# checkout the current repository
- name: Checkout kitops
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
with:
path: kitops

# Create the homebrew-file directory to store the
# homebrew artifacts and copy the awk script and
# recipe template to it. These will be used later
# to build the homebrew recipe file.
- name: Create homebrew-files dir
run: |
mkdir homebrew-files
cp ./kitops/build/homebrew/*.* ./homebrew-files
- name: Merge build artifacts
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.3
with:
path: dist
pattern: dist-*
merge-multiple: true
- name: Create Checksums

- name: Create checksums
env:
TAG_NAME: ${{ github.ref_name}}
TAG_NAME: ${{ inputs.release_tag || github.ref_name}}
#TAG_NAME: ${{ inputs.release_tag}}
run: |
shopt -s failglob
pushd dist
shasum -a 256 kitops-* > checksums.txt
mv checksums.txt kitops_${TAG_NAME}_checksums.txt
cp kitops_${TAG_NAME}_checksums.txt ../homebrew-files/.
popd
# upload the homebrew-files directory (and its contents)
# as an artifact to be used later when generating the
# homebrew recipe and pushing it to the repository:
# 'jozu-ai/homebrew-kitops'
- name: Upload homebrew-files as a build artifact
uses: actions/upload-artifact@604373da6381bf24206979c74d06a550515601b9 # v4.4.1
with:
name: homebrew-files
if-no-files-found: error
retention-days: 7
path: ./homebrew-files

- name: Create Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -182,7 +214,7 @@ jobs:
--title "Release ${TAG_NAME}"
--generate-notes
--repo ${REPO}
)
)
if [[ "${DRAFT_RELEASE}" == "false" ]]; then
previous_release="$(gh release list --repo $REPO --limit 1 --json tagName --jq '.[] | .tagName ')"
echo "Previous release: ${previous_release}"
Expand All @@ -194,33 +226,108 @@ jobs:
fi
gh release create "${release_args[@]}"
- name: Checkout
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1

- name: Generate CLI documentation
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG_NAME: ${{ inputs.release_tag || github.ref_name}}
run: |
pushd kitops
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
PR_BRANCH="${{ github.ref_name }}-docs-update"
git fetch origin main
git branch "$PR_BRANCH"
git checkout "$PR_BRANCH"
git pull origin --ff-only "${PR_BRANCH}" || true
git config --global user.name "${GITHUB_ACTOR}"
git config --global user.email "${GITHUB_ACTOR_ID}+${GITHUB_ACTOR}@users.noreply.github.com"
(cd docs; npm pkg set version=$TAG_NAME)
./docs/src/docs/cli/generate.sh > /dev/null
git add --all
git commit -m "docs: update CLI documentation for ${{ github.ref_name }}"
git push origin "${PR_BRANCH}"
gh pr create --fill --base main --head "${PR_BRANCH}"
git checkout "${CURRENT_BRANCH}"
popd


# Generate and publish the homebrew recipe (kitops.rb) to the repository:
# 'jozu-ai/homebrew-kitops'
publish-homebrew-tap-formula:
runs-on: ubuntu-latest
needs: [release]
steps:
# checkout the homebrew-kitops repository (jozu-ai/homebrew-kitops)
- name: Checkout homebrew-kitops
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
with:
repository: jozu-ai/homebrew-kitops
ref: 'main'
path: homebrew-kitops
token: ${{ secrets.GITOPS_PAT }}

- name: Download the homebrew artifacts to build the homebrew recipe
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.3
with:
name: homebrew-files
path: homebrew-files
merge-multiple: true

- name: Create and save homebrew-metadata.txt
env:
TAG_NAME: ${{ inputs.release_tag}}
REPO: ${{ github.repository }}
run: |
shopt -s failglob
pushd homebrew-files
awk '
BEGIN { tag_name = ENVIRON["TAG_NAME"]; repo = ENVIRON["REPO"];}
/.tar.gz$/ {
print "\""$1"\"",
"\"https://github.com/" repo "/releases/download/" tag_name "/" $2 "\"",
$2,
tag_name }' kitops_${TAG_NAME}_checksums.txt |
awk '{ sub(/.tar.gz/, "", $3); print $1, $2, $3, $4 }' |
awk '{ sub(/kitops-/, "", $3); print $1, $2, $3, $4 }' |
awk '{sub(/v/, "", $4); print $1, $2, $3, $4 }' > homebrew-metadata.txt
popd
# uses the homebrew-metadata.txt file generated in the
# previous step to generate the homebrew formula (kitops.rb)
# for the homebrew tap (located at 'jozu-ai/homebrew-kitops')
- name: Create homebrew formula
run: |
pushd homebrew-files
awk -f create-homebrew-recipe.awk homebrew-metadata.txt
popd
# publish the homebrew recipe file to the homebrew tap
# located in the repository: 'jozu-ai/homebrew-kitops'
- name: Commit homebrew recipe to the homebrew tap
env:
GITHUB_TOKEN: ${{ secrets.GITOPS_PAT }}
TAG_NAME: ${{ inputs.release_tag}}
REPO: "jozu-ai/homebrew-kitops"
run: |
cp -f ./homebrew-files/homebrew-metadata.txt ./homebrew-kitops/.
cp -f ./homebrew-files/kitops.rb ./homebrew-kitops/.
pushd homebrew-kitops
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
PR_BRANCH="${{ github.ref_name }}-homebrew-tap-update"
git fetch origin main
git branch "$PR_BRANCH"
git checkout "$PR_BRANCH"
git pull origin --ff-only "${PR_BRANCH}" || true
git config --global user.name "${GITHUB_ACTOR}"
git config --global user.email "${GITHUB_ACTOR_ID}+${GITHUB_ACTOR}@users.noreply.github.com"
git add --all
git commit -m "homebrew: update Homebrew Tap Formula for ${{ github.ref_name }}"
git push origin "${PR_BRANCH}"
gh pr create --fill --base main --head "${PR_BRANCH}"
git checkout "${CURRENT_BRANCH}"
popd
docker-image-build:
runs-on: ubuntu-latest
Expand Down
22 changes: 20 additions & 2 deletions .goreleaser.darwin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,33 @@ builds:
output: true

archives:
- id: kit-macos-archive
# zip archives for Mac OS:
# - will be notorized
# - will be made available for users to install manually
- id: kit-macos-zip-archive
format: zip
builds:
- kit-macos
name_template: >-
{{ .ProjectName }}-
{{- tolower .Os }}-
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
files:
- LICENSE
- README.md
# tar.gz archives for Mac OS:
# - will not be notarized
# - will be installable via homebrew (i.e. "brew install kitops")
- id: kit-macos-targz-archive
format: tar.gz
builds:
- kit-macos
name_template: >-
{{ .ProjectName }}-
{{- tolower .Os }}-
{{- if eq .Arch "amd64" }}x86_64
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
files:
Expand Down
44 changes: 44 additions & 0 deletions build/homebrew/create-homebrew-recipe.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Usage: awk -f create-homebrew-recipe.awk homebrew-metadata.txt

BEGIN {
template = "kitops.rb.template";
recipe = "kitops.rb";
}

{
# Read relevant fields from input file
# (intended to be homebrew-metadata.txt)
shas[$3]=$1;
urls[$3]=$2;
version[$3]=$4;
}

END {
# Read a line from template, replace special fields,
# and print result to recipe file
while ((getline ln < template) > 0)
{
sub(/url @@darwin-arm64/, "url " urls["darwin-arm64"], ln);
sub(/sha256 @@darwin-arm64/, "sha256 " shas["darwin-arm64"], ln);

sub(/url @@darwin-x86_64/, "url " urls["darwin-x86_64"], ln);
sub(/sha256 @@darwin-x86_64/, "sha256 " shas["darwin-x86_64"], ln);

sub(/url @@linux-arm64/, "url " urls["linux-arm64"], ln);
sub(/sha256 @@linux-arm64/, "sha256 " shas["linux-arm64"], ln);

sub(/url @@linux-x86_64/, "url " urls["linux-x86_64"], ln);
sub(/sha256 @@linux-x86_64/, "sha256 " shas["linux-x86_64"], ln);

sub(/url @@linux-i386/, "url " urls["linux-i386"], ln);
sub(/sha256 @@linux-i386/, "sha256 " shas["linux-i386"], ln);

sub(/@@version/, version["darwin-arm64"], ln);

print(ln) > recipe;
}

# Close template and recipe fields
close(recipe);
close(template);
}
43 changes: 43 additions & 0 deletions build/homebrew/kitops.rb.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
class Kitops < Formula
desc "Packaging and versioning system for AI/ML projects"
homepage "https://KitOps.ml"
license "Apache-2.0"

on_macos do
on_arm do
url @@darwin-arm64
sha256 @@darwin-arm64
end
on_intel do
url @@darwin-x86_64
sha256 @@darwin-x86_64
end

end

on_linux do
on_arm do
url @@linux-arm64
sha256 @@linux-arm64
end
on_intel do
if Hardware::CPU.is_64_bit?
url @@linux-x86_64
sha256 @@linux-x86_64
else
url @@linux-i386
sha256 @@linux-i386
end
end
end

def install
bin.install "kit"
end

test do
expected_version = "Version: @@version"
actual_version = shell_output("#{bin}/kit version").strip
assert_match expected_version, actual_version
end
end

0 comments on commit 4a7308a

Please sign in to comment.