action.js

const fs = require('fs')
const path = require('path')
const yaml = require('js-yaml')

/**
 * Initialize every action by beginning the promise chain
 * @param {object} event
 */
module.exports.init = (event, servicesDir) => {
  if (!fs.existsSync(servicesDir)) {
    return Promise.reject(new Error(`Missing/invalid services dir: '${servicesDir}'`))
  }

  // Load all services yaml definitions
  const services = yaml.safeLoad(fs.readFileSync(path.join(servicesDir, process.env.SERVICE_NAME + '.yml'), 'utf8'))

  // Set current service definition on event (from SERVICE_NAME environment variable)
  event.service = services[process.env.SERVICE_NAME] || {}

  // Default event builds to empty object
  event.builds = {}

  // Default event deploys to empty object
  event.deploys = {}

  // Add the empty "parsed" key to the event object
  event.parsed = {}

  // Debug log for event being processed
  console.log('Event: ', JSON.stringify(event, null, 2))

  // Return a resolved promise and pass the event
  return Promise.resolve(event)
}