Skip to content

Commit

Permalink
add homebrew release
Browse files Browse the repository at this point in the history
  • Loading branch information
Roy Razon committed Jan 14, 2024
1 parent d9a32fa commit 6436b12
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 1 deletion.
28 changes: 28 additions & 0 deletions .github/workflows/gh-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,31 @@ jobs:
prerelease: ${{ !startsWith(github.ref, 'refs/tags/') }}
files: |
packages/cli/dist/preevy-v*.tar.gz
- uses: actions/create-github-app-token@v1
# if: startsWith(github.ref, 'refs/tags/')
id: app-token
with:
app-id: ${{ secrets.PREEVY_AUTOMATION_APP_ID }}
private-key: ${{ secrets.PREEVY_AUTOMATION_PRIVATE_KEY }}

- uses: actions/checkout@v4
name: Checkout homebrew repo
# if: startsWith(github.ref, 'refs/tags/')
with:
token: ${{ steps.app-token.outputs.token }}
repository: livecycle/homebrew-preevy
path: homebrew

- name: Update Homebrew formula
# if: startsWith(github.ref, 'refs/tags/')
working-directory: packages/cli
run: |
version="$(jq -r .version package.json)"
node scripts/homebrew.mjs > ../../homebrew/Formula/preevy.rb
cd ../../homebrew
git config user.name "GitHub Actions"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add Formula/preevy.rb
git commit -m "Update Preevy formula for version ${version}"
git push
3 changes: 2 additions & 1 deletion packages/cli/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/dist
node_modules
node_modules
/scripts
95 changes: 95 additions & 0 deletions packages/cli/scripts/homebrew.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import fs from 'fs'
import path from 'path'
import os from 'os'

const distDir = 'dist'
const matrix = {
darwin: ['x64', 'arm64'],
linux: ['x64', 'arm64'],
}

const url = ({ os, arch, version }) => `https://github.com/livecycle/preevy/releases/download/v${version}/preevy-v${version}-${os}-${arch}.tar.gz`

const template = ctx => `# This file is automatically generated by https://github.com/livecycle/preevy/blob/main/packages/cli/scripts/homebrew.js
# Do not update this file directly; Please update the template instead
class Preevy < Formula
desc "Quickly deploy preview environments to your cloud provider or Kubernetes cluster"
homepage "https://preevy.dev"
url "${ ctx.darwin.x64.url }"
sha256 "${ ctx.darwin.x64.sha }"
license "Apache-2.0"
version "${ ctx.version }"
on_macos do
on_arm do
url "${ ctx.darwin.arm64.url }"
sha256 "${ ctx.darwin.arm64.sha }"
end
end
on_linux do
url "${ ctx.linux.x64.url }"
sha256 "${ ctx.linux.x64.sha }"
on_arm do
url "${ ctx.linux.arm64.url }"
sha256 "${ ctx.linux.arm64.sha }"
end
end
def install
inreplace "bin/preevy", /^CLIENT_HOME=/, "export PREEVY_OCLIF_CLIENT_HOME=#{lib/"client"}\nCLIENT_HOME="
libexec.install Dir["*"]
bin.install_symlink libexec/"bin/preevy"
end
test do
system bin/"preevy", "version"
end
end
`

const manifestFiles = fs.readdirSync(distDir)
.filter(file => file.endsWith('-buildmanifest'))
.map(file => path.join(distDir, file))

const manifestFilename = ({ os, arch }) => manifestFiles.find(file => file.includes(`-${os}-${arch}-`))

const readManifest = ({ os, arch }) => {
const filename = manifestFilename({ os, arch })
if (!filename) {
throw new Error(`Missing ${os} ${arch} build manifest`)
}
const manifest = JSON.parse(fs.readFileSync(filename, 'utf8'))
const requiredProp = (prop) => {
if (!manifest[prop]) {
throw new Error(`Missing ${prop} in manifest: ${filename}`)
}
return manifest[prop]
}
return { sha: requiredProp('sha256gz'), version: requiredProp('version') }
}

const main = async () => {
const context = {}
Object.entries(matrix).forEach(([os, archs]) => {
context[os] = context[os] ?? {}
archs.forEach(arch => {
const { sha, version } = readManifest({ os, arch })
context.version = version
context[os][arch] = {
sha,
url: url({ os, arch, version })
}
})
})

process.stdout.write(template(context))
process.stdout.write(os.EOL)
}

main().catch(err => {
console.error(err)
process.exit(1)
})


0 comments on commit 6436b12

Please sign in to comment.