Skip to content

Commit

Permalink
Merge pull request #1 from Expensify/master
Browse files Browse the repository at this point in the history
Merge
  • Loading branch information
tugbadogan authored Mar 14, 2021
2 parents b9a8d3f + 815d13d commit 43ad727
Show file tree
Hide file tree
Showing 118 changed files with 36,755 additions and 1,742 deletions.
18 changes: 18 additions & 0 deletions .github/actions/createOrUpdateStagingDeploy/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: 'Create or Update StagingDeployCash'
description: 'Creates a new StagingDeployCash issue if there is not one open, or updates the existing one.'
inputs:
GITHUB_TOKEN:
description: Auth token for Expensify.cash Github
required: true
NPM_VERSION:
description: The new NPM version of the StagingDeployCash issue.
required: false
NEW_PULL_REQUESTS:
description: A comma-separated list of pull request URLs to add to the open StagingDeployCash issue.
required: false
NEW_DEPLOY_BLOCKERS:
description: A comma-separated list of deploy blockers to add to the open StagingDeployCash issue.
required: false
runs:
using: 'node12'
main: './index.js'
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
const _ = require('underscore');
const core = require('@actions/core');
const github = require('@actions/github');
const moment = require('moment');
const GithubUtils = require('../../libs/GithubUtils');
const GitUtils = require('../../libs/GitUtils');

const newVersion = core.getInput('NPM_VERSION');
const octokit = github.getOctokit(core.getInput('GITHUB_TOKEN', {required: true}));
const githubUtils = new GithubUtils(octokit);

githubUtils.getStagingDeployCash()
.then(() => githubUtils.updateStagingDeployCash(
newVersion,
_.filter(
_.map(core.getInput('NEW_PULL_REQUESTS').split(','), PR => PR.trim()),
PR => !_.isEmpty(PR),
),
_.filter(
_.map(core.getInput('NEW_DEPLOY_BLOCKERS').split(','), deployBlocker => deployBlocker.trim()),
PR => !_.isEmpty(PR),
),
))
.then(({data}) => {
console.log('Successfully updated StagingDeployCash!', data.html_url);
process.exit(0);
})
.catch((err) => {
// Unable to find the open StagingDeployCash
if (err && err.code === 404) {
console.log('No open StagingDeployCash found, creating a new one.');

// Fetch all the StagingDeployCash issues
return octokit.issues.listForRepo({
log: console,
owner: GithubUtils.GITHUB_OWNER,
repo: GithubUtils.EXPENSIFY_CASH_REPO,
labels: GithubUtils.STAGING_DEPLOY_CASH_LABEL,
state: 'closed',
});
}

// Unexpected error!
console.error('Unexpected error occurred finding the StagingDeployCash!'
+ ' There may have been more than one open StagingDeployCash found,'
+ ' or there was some other problem with the Github API request.', err);
core.setFailed(err);
})
.then((githubResponse) => {
if (!githubResponse || !githubResponse.data || _.isEmpty(githubResponse.data)) {
console.error('Failed fetching data from Github!', githubResponse);
throw new Error('Failed fetching data from Github');
}

// Parse the tag from the most recent StagingDeployCash
const lastTag = githubUtils.getStagingDeployCashData(githubResponse.data[0]).tag;
console.log('Found tag of previous StagingDeployCash:', lastTag);

// Find the list of PRs merged between the last StagingDeployCash and the new version
return GitUtils.getPullRequestsMergedBetween(lastTag, newVersion);
})
.then(PRNumbers => githubUtils.createNewStagingDeployCash(
`Deploy Checklist: Expensify.cash ${moment().format('YYYY-MM-DD')}`,
newVersion,
_.map(PRNumbers, GithubUtils.getPullRequestURLFromNumber),
))
.then(({data}) => console.log('Successfully created new StagingDeployCash!', data.html_url))
.catch((err) => {
console.error('An error occurred!', err);
core.setFailed(err);
});
Loading

0 comments on commit 43ad727

Please sign in to comment.