Skip to content

Commit

Permalink
Merge pull request #470 from garden-io/zeit-osx
Browse files Browse the repository at this point in the history
chore(release): package using zeit/pkg for macOS
  • Loading branch information
eysi09 authored Jan 23, 2019
2 parents 5df54f7 + 7c912b6 commit 4f5855d
Show file tree
Hide file tree
Showing 7 changed files with 260 additions and 109 deletions.
35 changes: 0 additions & 35 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -288,35 +288,6 @@ jobs:
paths:
# Save the built output for future
- dashboard/build/
release-service-npm:
<<: *node-config
steps:
- checkout
- npm_install
- *attach-workspace
- include_dashboard
- run:
name: Authenticate with registry
command: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc
- run:
name: Publish package
command: |
cd garden-service
VERSION=$(cat package.json | jq -r .version)
VERSION_LOCK=$(cat package-lock.json | jq -r .version)
[ "$VERSION" == "$VERSION_LOCK" ] || (echo "package.json and package-lock.json contain different versions refusing to release"; exit 1)
# package.json contains 0.8 and our tagging convention is v0.8
[ "v$VERSION" == "$CIRCLE_TAG" ] || (echo "package.json and CIRCLE_TAG contain different versions refusing to release"; exit 1)
# If version number is a pre-release set npm tag to --tag=beta so it is not installed when you install latest
NPM_EXTRA=""
if [[ "$CIRCLE_TAG" == *"rc"* ]]; then
echo "$CIRCLE_TAG contains rc setting release to --tag=beta";
NPM_EXTRA="--tag=beta"
fi
npm publish $NPM_EXTRA
release-service-pkg:
<<: *node-config
steps:
Expand Down Expand Up @@ -402,9 +373,3 @@ workflows:
requires:
- build-service
- build-dashboard
- release-service-npm:
<<: *only-tags
context: npm
requires:
- build-service
- build-dashboard
14 changes: 13 additions & 1 deletion garden-service/bin/build-pkg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ rsync -r --exclude=.garden --exclude=.git static tmp/dist
echo "-> Building executables..."
cd dist
# note: using the npm package is still preferred on macOS, because it needs the native fsevents library
pkg --target node10-linux-x64,node10-win-x64 ../tmp/dist
pkg --target node10-macos-x64,node10-linux-x64,node10-win-x64 ../tmp/dist

echo "-> Preparing packages..."

Expand All @@ -34,6 +34,18 @@ tar -czf garden-${version}-linux-amd64.tar.gz linux-amd64
echo " -> cleaning up tmp files"
rm -rf linux-amd64

echo " -> macos-amd64"
rm -rf macos-amd64
mkdir macos-amd64
mv garden-cli-macos macos-amd64/garden
cp -r ../tmp/dist/static macos-amd64
# need to include the .node binary for fsevents
cp ../lib/fsevents/node-v64-darwin-x64/fse.node macos-amd64
echo " -> tar"
tar -czf garden-${version}-macos-amd64.tar.gz macos-amd64
echo " -> cleaning up tmp files"
rm -rf macos-amd64

echo " -> windows-amd64"
rm -rf windows-amd64
mkdir windows-amd64
Expand Down
Binary file not shown.
43 changes: 28 additions & 15 deletions gulpfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import * as execa from "execa"
import { writeFile, readFile, ensureDir, pathExists, remove } from "fs-extra"
import { getUrlChecksum } from "./support/support-util"
import * as handlebars from "handlebars"
import { isString, clone, extend } from "lodash"
import { isString, clone, extend, find } from "lodash"

const Octokit = require("@octokit/rest")
const gulp = require("gulp")
const checkLicense = require("gulp-license-check")

Expand Down Expand Up @@ -69,8 +70,7 @@ gulp.task("check-licenses", () =>
*/
gulp.task("update-brew", async () => {
// clone the homebrew-garden tap repo
const packageJson = require(join(__dirname, "garden-service", "/package.json"))

console.log("Pulling the homebrew repo")
await ensureDir(tmpDir)
const brewRepoDir = resolve(tmpDir, "homebrew-garden")
if (await pathExists(brewRepoDir)) {
Expand All @@ -79,41 +79,54 @@ gulp.task("update-brew", async () => {
await execa("git", ["clone", "[email protected]:garden-io/homebrew-garden.git"], { cwd: tmpDir })

// read the existing formula
console.log("Reading currently published formula")
const formulaDir = resolve(brewRepoDir, "Formula")
await ensureDir(formulaDir)
const formulaPath = resolve(formulaDir, "garden-cli.rb")
const existingFormula = await pathExists(formulaPath) ? (await readFile(formulaPath)).toString() : ""

// compile the formula handlebars template
const templatePath = resolve(__dirname, "support", "homebrew-formula.rb")
const templateString = (await readFile(templatePath)).toString()
const template = handlebars.compile(templateString)

// get the metadata from npm
const metadataJson = await execa.stdout("npm", ["view", "garden-cli", "--json"])
const metadata = JSON.parse(metadataJson)
const version = metadata["dist-tags"].latest
const tarballUrl = metadata.dist.tarball
const sha256 = metadata.dist.shasum.length === 64
? metadata.dist.shasum
: await getUrlChecksum(tarballUrl, "sha256")
// get the metadata from GitHub
console.log("Preparing formula")
const octokit = new Octokit()
const repoName = "garden-io/garden"

// note: this excludes pre-releases
const latestRelease = await octokit.request(`GET /repos/${repoName}/releases/latest`)

const version = latestRelease.data.tag_name.slice(1)
const releaseId = latestRelease.data.id

const assets = await octokit.request(`GET /repos/${repoName}/releases/${releaseId}/assets`)

const tarballUrl = find(assets.data, a => a.name.includes("macos")).browser_download_url
const sha256 = await getUrlChecksum(tarballUrl, "sha256")

const formula = template({
version,
homepage: metadata.homepage || packageJson.homepage,
description: metadata.description,
homepage: "https://garden.io",
// using a hard-coded description here because Homebrew limits to 80 characters
description: "Development engine for Kubernetes",
tarballUrl,
sha256,
})

const formulaPath = resolve(formulaDir, "garden-cli.rb")
const existingFormula = await pathExists(formulaPath) ? (await readFile(formulaPath)).toString() : ""

if (formula === existingFormula) {
console.log("No changes to formula")
} else {
console.log("Writing new formula to " + formulaPath)
await writeFile(formulaPath, formula)

// check if the formula is OK
console.log("Auditing formula")
await execa("brew", ["audit", formulaPath])

console.log("Pushing to git")
for (const args of [
["add", formulaPath],
["commit", "-m", `update to ${version}`],
Expand Down
Loading

0 comments on commit 4f5855d

Please sign in to comment.