-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: generate homebrew formula on publish
Note: This will not work until we cut another release, since the formula relies on a fix in a prior commit to work properly.
- Loading branch information
Showing
10 changed files
with
187 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,18 +2,31 @@ import { | |
spawn as _spawn, | ||
ChildProcess, | ||
} from "child_process" | ||
import { writeFileSync } from "fs" | ||
import { | ||
writeFileSync, | ||
} from "fs" | ||
import { | ||
ensureDir, | ||
pathExists, | ||
readFile, | ||
remove, | ||
writeFile, | ||
} from "fs-extra" | ||
import * as handlebars from "handlebars" | ||
import { | ||
join, | ||
relative, | ||
} from "path" | ||
import { generateDocs } from "./src/docs/generate" | ||
import { getUrlChecksum } from "./support/support-util" | ||
import execa = require("execa") | ||
|
||
const gulp = require("gulp") | ||
const cached = require("gulp-cached") | ||
const checkLicense = require("gulp-license-check") | ||
// const debug = require("gulp-debug") | ||
// const exec = require("gulp-exec") | ||
const packageJson = require("./package.json") | ||
const pegjs = require("gulp-pegjs") | ||
const sourcemaps = require("gulp-sourcemaps") | ||
const gulpTslint = require("gulp-tslint") | ||
|
@@ -29,7 +42,8 @@ const tsSources = "src/**/*.ts" | |
const testTsSources = "test/**/*.ts" | ||
const pegjsSources = "src/*.pegjs" | ||
|
||
const licenseHeaderPath = "static/license-header.txt" | ||
const tmpDir = join(__dirname, "tmp") | ||
const licenseHeaderPath = "support/license-header.txt" | ||
|
||
const destDir = "build" | ||
|
||
|
@@ -180,6 +194,62 @@ gulp.task("tslint-tests", () => | |
.pipe(gulpTslint.report()), | ||
) | ||
|
||
/** | ||
* Updates our Homebrew tap with the current released package version. Should be run after relasing to NPM. | ||
*/ | ||
gulp.task("update-brew", async () => { | ||
// clone the homebrew-garden tap repo | ||
const brewRepoDir = join(tmpDir, "homebrew-garden") | ||
if (await pathExists(brewRepoDir)) { | ||
await remove(brewRepoDir) | ||
} | ||
await execa("git", ["clone", "[email protected]:garden-io/homebrew-garden.git"], { cwd: tmpDir }) | ||
|
||
// read the existing formula | ||
const formulaDir = join(brewRepoDir, "Formula") | ||
await ensureDir(formulaDir) | ||
const formulaPath = join(formulaDir, "garden-cli.rb") | ||
const existingFormula = await pathExists(formulaPath) ? (await readFile(formulaPath)).toString() : "" | ||
|
||
// compile the formula handlebars template | ||
const templatePath = join(__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") | ||
|
||
const formula = template({ | ||
version, | ||
homepage: metadata.homepage || packageJson.homepage, | ||
description: metadata.description, | ||
tarballUrl, | ||
sha256, | ||
}) | ||
|
||
if (formula === existingFormula) { | ||
console.log("No changes to formula") | ||
} else { | ||
await writeFile(formulaPath, formula) | ||
|
||
// check if the formula is OK | ||
await execa("brew", ["audit", formulaPath]) | ||
|
||
for (const args of [ | ||
["add", formulaPath], | ||
["commit", "-m", `update to ${version}`], | ||
["tag", version], | ||
["push", "--tags"], | ||
]) { | ||
await execa("git", args, { cwd: brewRepoDir }) | ||
} | ||
} | ||
}) | ||
|
||
gulp.task("watch-code", () => { | ||
const verify = (path) => { | ||
try { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require "language/node" | ||
|
||
class GardenCli < Formula | ||
desc "{{description}}" | ||
homepage "{{{homepage}}}" | ||
url "{{{tarballUrl}}}" | ||
sha256 "{{sha256}}" | ||
|
||
depends_on "node" | ||
depends_on "rsync" | ||
depends_on "watchman" | ||
depends_on "python" => :build | ||
|
||
def install | ||
system "npm", "install", *Language::Node.std_npm_install_args(libexec) | ||
bin.install_symlink Dir["#{libexec}/bin/*"] | ||
end | ||
|
||
test do | ||
# add a meaningful test here | ||
end | ||
end |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import Axios from "axios" | ||
import { createHash } from "crypto" | ||
|
||
export async function getUrlChecksum(url: string, algorithm = "sha256") { | ||
const response = await Axios({ | ||
method: "GET", | ||
url, | ||
responseType: "stream", | ||
}) | ||
|
||
return new Promise((resolve, reject) => { | ||
const hash = createHash(algorithm) | ||
|
||
response.data.on("data", (chunk) => { | ||
hash.update(chunk) | ||
}) | ||
|
||
response.data.on("end", () => { | ||
resolve(hash.digest("hex")) | ||
}) | ||
|
||
response.data.on("error", reject) | ||
}) | ||
} |