Skip to content

Commit

Permalink
Port release/ci-book to js (also full release/common module)
Browse files Browse the repository at this point in the history
  • Loading branch information
fasterthanlime committed Jul 11, 2016
1 parent 661f116 commit 430af4a
Show file tree
Hide file tree
Showing 4 changed files with 178 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ book:
tags:
- dropsy
script:
- release/rube.sh release/ci-book.rb
- release/ci-book.js

# Unit tests
test:
Expand Down
15 changes: 15 additions & 0 deletions release/ci-book.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env node

// generate latest documentation for itch using gitbook
// and deploy it to google cloud storage.

const $ = require('./common')

$.show_versions(['npm', 'gsutil'])
$($.npm_dep('gitbook', 'gitbook-cli'))

$.cd('docs', function () {
$($.npm('install'))
$($.sh('gitbook build'))
$($.gcp(`_book/* gs://docs.itch.ovh/itch/${$.build_ref_name()}`))
})
20 changes: 0 additions & 20 deletions release/ci-book.rb

This file was deleted.

166 changes: 162 additions & 4 deletions release/common.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
// base functions useful throughout CI scripts

const child_process = require('child_process')
const fs = require('fs')
const ospath = require('path')
const colors = require('colors')

const $ = {}
const $ = function (val) {
if (!val) {
throw new Error('Exit code assertion failed, bailing out')
}
}

$.HOMEPAGE =
$.HOMEPAGE = 'https://itch.io/app'
Expand Down Expand Up @@ -56,8 +62,8 @@ $.putln = function (s) {

$.show_versions = function (names) {
names.forEach(function (name) {
const v = $.($.VERSION_SPECS[name]).trim()
$.putln `★ ${name} ${v}`.yellow
const v = $.get_output($.VERSION_SPECS[name]).trim()
$.putln(`★ ${name} ${v}`.yellow)
})
return true
}
Expand All @@ -67,7 +73,8 @@ $.say = function (cmd) {
return true
}

function system (cmd) {
function system (cmd, opts = {}) {
const {quiet = true} = opts
try {
child_process.execSync(cmd, {
stdio: 'inherit'
Expand Down Expand Up @@ -121,5 +128,156 @@ $.gothub = function (args) {
return $.sh `gothub`
}

$.go_dep = function (cmd, pkg) {
if (system(`which ${cmd} > /dev/null`)) {
$.putln(`★ got ${cmd}`.yellow)
return true
} else {
$.putln(`☁ installing ${cmd}`.yellow)
return $.go(`get ${pkg}`)
}
}

$.gem_dep = function (cmd, pkg) {
if (system(`which ${cmd} > /dev/null`)) {
$.putln(`★ got ${cmd}`.yellow)
return true
} else {
$.putln(`☁ installing ${cmd}`.yellow)
return $.gem(`install ${pkg}`)
}
}

$.npm_dep = function (cmd, pkg) {
if (system(`which ${cmd} > /dev/null`)) {
$.putln(`★ got ${cmd}`.yellow)
return true
} else {
$.putln(`☁ installing ${cmd}`.yellow)
return $.npm(`install -g ${pkg}`)
}
}

$.ensure = $

$.retry = function (cb) {
var tries = 0
while (tries < $.RETRY_COUNT) {
if (tries > 0) {
$.say(`Command failed, waiting 30s then trying ${$.RETRY_COUNT - tries} more time(s).`)
// naughty, but don't want to pull in node-sleep (native modules)
// or turn everything into async (babel-cli = huge)
system('sleep 30')
}
if (cb()) {
// cmd returned truthy value, was successful
return
}
tries++
}
throw new Exception(`Tried ${RETRY_COUNT} times, bailing out`)
}

$.get_output = function (cmd) {
const out = child_process.execSync(cmd, {
encoding: 'utf8'
})
// console.log('cmd = ', cmd)
// console.log('out = ', out)
return out
}

$.prompt = function (msg) {
process.stdout.write(`${msg} (y/n)`)
var s = 'n'
fs.readSync(process.stdin, s, 0, 1, 0)
process.stdout.write('\n')

if (s !== 'y') {
$.say('Bailing out...')
process.exit(0)
}
}

$.cd = function (dir, cb) {
const original_wd = ospath.resolve(__dirname, '..')
var e
var ret

$.putln(`☞ entering ${dir}`)
process.chdir(dir)
try {
ret = cb()
} catch (err) {
e = err
} finally {
$.putln(`☜ leaving ${dir}`)
process.chdir(original_wd)
}

if (e) {
throw e
}
return ret
}

// environment variables etc.

$.build_ref_name = function () {
const v = process.env.CI_BUILD_REF_NAME
if (!v) {
throw new Error('No build ref!')
}
return v
}

$.build_tag = function () {
const v = process.env.CI_BUILD_TAG
if (!v) {
throw new Error('No build tag!')
}
return v
}

$.build_version = function () {
return $.build_tag().replace(/^v/, '').replace(/-.+$/, '')
}

$.app_name = function () {
if (/-canary$/.test($.build_tag())) {
return 'kitch'
} else {
return 'itch'
}
}

$.channel_name = function () {
if (/-canary$/.test($.build_tag())) {
return 'canary'
} else {
return 'stable'
}
}

$.to_deb_arch = function (arch) {
switch (arch) {
case '386': return 'i386'
case 'amd64': return 'amd64'
default: throw new Error(`Unsupported arch ${arch}`)
}
}

$.to_rpm_arch = function (arch) {
switch (arch) {
case '386': return 'i386'
case 'amd64': return 'x86_64'
default: throw new Error(`Unsupported arch ${arch}`)
}
}

$.build_time = function () {
return $.BUILD_TIME
}

module.exports = $

0 comments on commit 430af4a

Please sign in to comment.