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

Added Homebrew Tap Capability #520

Merged
merged 6 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
174 changes: 141 additions & 33 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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few trailing spaces on lines in this file (in VS Code, use cmd+k, cmd+z to trim)

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,61 @@ 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
- name: Create homebrew-files dir
run: mkdir homebrew-files

# Copy the awk script and template to the homebrew-files dir.
# These will be used later to build the homebrew recipe file.
- name: Copy homebrew artifacts to homebrew-files dir
run: cp ./kitops/build/homebrew/*.* ./homebrew-files
amisevsk marked this conversation as resolved.
Show resolved Hide resolved

- 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
popd
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 @@ -178,11 +211,11 @@ jobs:
echo "Creating release for ${TAG_NAME}"
release_args=(
${TAG_NAME}
./dist/*.*
./dist/*.*
brett-hodges marked this conversation as resolved.
Show resolved Hide resolved
--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 +227,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: |
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}"
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
brett-hodges marked this conversation as resolved.
Show resolved Hide resolved


# 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
Comment on lines +285 to +294
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm taking it on faith that this does whatever it is supposed to -- awk is a write-only language :D

Consider add comments describing what each step does?

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: 21 additions & 1 deletion .goreleaser.darwin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ 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
Expand All @@ -39,6 +42,23 @@ archives:
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 if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
brett-hodges marked this conversation as resolved.
Show resolved Hide resolved
files:
- LICENSE
- README.md

git:
ignore_tags:
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