Skip to content

Commit

Permalink
v0.12.0
Browse files Browse the repository at this point in the history
* feat(deploy): get commit message using `git log` with `GITHUB_REF` in Github Actions environment
* fix(createConfig): include semicolon and new line at the end of config file
  • Loading branch information
prescottprue authored Jan 31, 2020
1 parent 747a4cf commit 05ba0b0
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 19 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "firebase-ci",
"version": "0.11.1",
"version": "0.12.0",
"description": "Simplified Firebase interaction for continuous integration including deploying hosting, functions, and database/storage rules.",
"main": "lib/index.js",
"bin": {
Expand Down Expand Up @@ -36,6 +36,7 @@
"firebase-tools",
"ci",
"deploy",
"github actions",
"gitlab",
"gitlab-ci",
"firebase-functions",
Expand Down
4 changes: 3 additions & 1 deletion src/actions/createConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ export default function createConfigFile(config) {
: `{\n${parentAsString(parent)}};\n\n`
),
''
).concat(`export default { ${Object.keys(templatedData).join(', ')} }`)
).concat(
`export default { ${Object.keys(templatedData).join(', ')} };\n`
)

const folderName = path.basename(path.dirname(opts.path))

Expand Down
14 changes: 7 additions & 7 deletions src/actions/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from '../utils/ci'
import { to } from '../utils/async'

const skipPrefix = 'Skipping Firebase Deploy'
const SKIP_PREFIX = 'Skipping Firebase Deploy'

/**
* Get string including token flag and FIREBASE_TOKEN
Expand Down Expand Up @@ -75,15 +75,15 @@ export default async function deploy(opts) {
const branchName = getBranch()
if (typeof branchName === 'undefined' || (opts && opts.test)) {
const nonCiMessage = `${chalk.cyan(
skipPrefix
SKIP_PREFIX
)} - Not a supported CI environment`
warn(nonCiMessage)
return nonCiMessage
}

if (isPullRequest()) {
const pullRequestMessage = `${chalk.cyan(
skipPrefix
SKIP_PREFIX
)} - Build is a Pull Request`
info(pullRequestMessage)
return pullRequestMessage
Expand Down Expand Up @@ -112,12 +112,12 @@ export default async function deploy(opts) {

// Handle project alias not existing in .firebaserc
if (!projectName) {
const nonProjectBranch = `${skipPrefix} - Project ${chalk.cyan(
const nonProjectBranch = `${SKIP_PREFIX} - Project ${chalk.cyan(
projectKey
)} is not an alias, checking for fallback...`
info(nonProjectBranch)
if (!fallbackProjectSetting) {
const nonFallbackBranch = `${skipPrefix} - Fallback Project: ${chalk.cyan(
const nonFallbackBranch = `${SKIP_PREFIX} - Fallback Project: ${chalk.cyan(
fallbackProjectName
)} is a not an alias, exiting...`
info(nonFallbackBranch)
Expand All @@ -136,8 +136,7 @@ export default async function deploy(opts) {
)
}

const onlyString = opts && opts.only ? `--only ${opts.only}` : ''
const message = getDeployMessage()
const message = await getDeployMessage()

// Install firebase-tools and functions dependencies unless skipped by config
if (!settings.skipDependencyInstall) {
Expand All @@ -155,6 +154,7 @@ export default async function deploy(opts) {

const firebaseTokenStr = getFirebaseTokenStr()
const npxExists = commandExists.sync('npx')
const onlyString = opts && opts.only ? `--only ${opts.only}` : ''

const deployArgs = [
'deploy',
Expand Down
42 changes: 32 additions & 10 deletions src/utils/ci.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { get } from 'lodash'
import { shellescape } from './commands'
import { warn } from './logger'
import { shellescape, runCommand } from './commands'
import { warn, log } from './logger'
import { getFile } from './files'

/**
Expand Down Expand Up @@ -130,12 +130,34 @@ export function isPullRequest() {
* Get commit message from environment variables
* @returns {string} Commit message for current ref
*/
function getCommitMessage() {
return (
process.env.TRAVIS_COMMIT_MESSAGE ||
process.env.CI_COMMIT_MESSAGE ||
process.env.CI_MESSAGE
)
async function getCommitMessage() {
// Load commit message from ENV variables if not using Github Actions
if (!process.env.GITHUB_ACTIONS) {
return (
process.env.TRAVIS_COMMIT_MESSAGE ||
process.env.CI_COMMIT_MESSAGE ||
process.env.CI_MESSAGE
)
}

// Load commit message using GITHUB_SHA on Github Actions
try {
const commandResults = await runCommand({
command: 'git',
args: [
'--no-pager',
'log',
'--format=%B',
'-n',
'1',
process.env.GITHUB_SHA
]
})
return commandResults
} catch (err) {
error(`Error getting commit message through git log for SHA: ${process.env.GITHUB_SHA}`, err)
return null
}
}

/**
Expand All @@ -144,8 +166,8 @@ function getCommitMessage() {
* running shellescape. If commit message is not found then "Update" is returned
* @returns {string} Message for deploy
*/
export function getDeployMessage() {
const originalMessage = getCommitMessage()
export async function getDeployMessage() {
const originalMessage = await getCommitMessage()
const DEFAULT_DEPLOY_MESSAGE = 'Update'
// Return "Update" (default message) if no message is gathered from env vars
if (!originalMessage) {
Expand Down

0 comments on commit 05ba0b0

Please sign in to comment.