Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[No QA] Fix bugs found with staging deploy comments #2479

Merged
merged 9 commits into from
Apr 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/createOrUpdateStagingDeploy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const exec = promisify(__nccwpck_require__(3129).exec);
function getPullRequestsMergedBetween(fromRef, toRef) {
return exec(`git log --format="%s" ${fromRef}...${toRef}`)
.then(({stdout}) => (
[...stdout.matchAll(/Merge pull request #(\d{1,6})/g)]
[...stdout.matchAll(/Merge pull request #(\d{1,6}) from (?!Expensify\/(?:master|main|version-))/g)]
.map(match => match[1])
));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ inputs:
GITHUB_TOKEN:
description: "Github token for authentication"
required: true
IS_PRODUCTION_DEPLOY:
description: "True if we are deploying to production"
required: false
outputs:
PR_LIST:
description: Array of released pull request numbers
description: Array of pull request numbers
runs:
using: 'node12'
main: './index.js'
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
const _ = require('underscore');
const core = require('@actions/core');
const github = require('@actions/github');
const GitUtils = require('../../libs/GitUtils');

const octokit = github.getOctokit(core.getInput('GITHUB_TOKEN', {required: true}));
const inputTag = core.getInput('TAG', {required: true});

const isProductionDeploy = JSON.parse(core.getInput('IS_PRODUCTION_DEPLOY', {required: false}));
const itemToFetch = isProductionDeploy ? 'release' : 'tag';

/**
* Gets either releases or tags for a GitHub repo
*
* @param {boolean} fetchReleases
* @returns {*}
*/
function getTagsOrReleases(fetchReleases) {
if (fetchReleases) {
return octokit.repos.listReleases({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
});
}

return octokit.repos.listTags({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
});
}

console.log(`Fetching ${itemToFetch} list from github...`);
getTagsOrReleases(isProductionDeploy)
.catch(githubError => core.setFailed(githubError))
.then(({data}) => {
const keyToPluck = isProductionDeploy ? 'tag_name' : 'name';
const tags = _.pluck(data, keyToPluck);
const priorTagIndex = _.indexOf(tags, inputTag) + 1;

if (priorTagIndex === 0) {
console.log(`No ${itemToFetch} was found for input tag ${inputTag}.`
+ `Comparing it to latest ${itemToFetch} ${tags[0]}`);
}

if (priorTagIndex === tags.length) {
const err = new Error('Somehow, the input tag was at the end of the paginated result, '
+ 'so we don\'t have the prior tag');
console.error(err.message);
core.setFailed(err);
return;
}

const priorTag = tags[priorTagIndex];
console.log(`Given ${itemToFetch}: ${inputTag}`);
console.log(`Prior ${itemToFetch}: ${priorTag}`);

return GitUtils.getPullRequestsMergedBetween(priorTag, inputTag);
})
.then((pullRequestList) => {
console.log(`Found the pull request list: ${pullRequestList}`);
return core.setOutput('PR_LIST', pullRequestList);
})
.catch(error => core.setFailed(error));
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports =
/******/ (() => { // webpackBootstrap
/******/ var __webpack_modules__ = ({

/***/ 4365:
/***/ 6062:
/***/ ((__unused_webpack_module, __unused_webpack_exports, __nccwpck_require__) => {

const _ = __nccwpck_require__(4987);
Expand All @@ -16,35 +16,60 @@ const GitUtils = __nccwpck_require__(669);
const octokit = github.getOctokit(core.getInput('GITHUB_TOKEN', {required: true}));
const inputTag = core.getInput('TAG', {required: true});

console.log('Fetching release list from github...');
octokit.repos.listReleases({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
})
const isProductionDeploy = JSON.parse(core.getInput('IS_PRODUCTION_DEPLOY', {required: false}));
const itemToFetch = isProductionDeploy ? 'release' : 'tag';

/**
* Gets either releases or tags for a GitHub repo
*
* @param {boolean} fetchReleases
* @returns {*}
*/
function getTagsOrReleases(fetchReleases) {
if (fetchReleases) {
return octokit.repos.listReleases({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
});
}

return octokit.repos.listTags({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
});
}

console.log(`Fetching ${itemToFetch} list from github...`);
getTagsOrReleases(isProductionDeploy)
.catch(githubError => core.setFailed(githubError))
.then(({data}) => {
const tags = _.pluck(data, 'tag_name');
const keyToPluck = isProductionDeploy ? 'tag_name' : 'name';
const tags = _.pluck(data, keyToPluck);
const priorTagIndex = _.indexOf(tags, inputTag) + 1;

if (priorTagIndex === 0) {
console.log(`No release was found for input tag ${inputTag}. Comparing it to latest release ${tags[0]}`);
console.log(`No ${itemToFetch} was found for input tag ${inputTag}.`
+ `Comparing it to latest ${itemToFetch} ${tags[0]}`);
}

if (priorTagIndex === tags.length) {
const err = new Error('Somehow, the input tag was at the end of the paginated result, '
+ "so we don't have the prior tag.");
+ 'so we don\'t have the prior tag');
console.error(err.message);
core.setFailed(err);
return;
}

const priorTag = tags[priorTagIndex];
console.log(`Given Release Tag: ${inputTag}`);
console.log(`Prior Release Tag: ${priorTag}`);
console.log(`Given ${itemToFetch}: ${inputTag}`);
console.log(`Prior ${itemToFetch}: ${priorTag}`);

return GitUtils.getPullRequestsMergedBetween(priorTag, inputTag);
})
.then(pullRequestList => core.setOutput('PR_LIST', pullRequestList))
.then((pullRequestList) => {
console.log(`Found the pull request list: ${pullRequestList}`);
return core.setOutput('PR_LIST', pullRequestList);
})
.catch(error => core.setFailed(error));


Expand All @@ -66,7 +91,7 @@ const exec = promisify(__nccwpck_require__(3129).exec);
function getPullRequestsMergedBetween(fromRef, toRef) {
return exec(`git log --format="%s" ${fromRef}...${toRef}`)
.then(({stdout}) => (
[...stdout.matchAll(/Merge pull request #(\d{1,6})/g)]
[...stdout.matchAll(/Merge pull request #(\d{1,6}) from (?!Expensify\/(?:master|main|version-))/g)]
.map(match => match[1])
));
}
Expand Down Expand Up @@ -11224,6 +11249,6 @@ module.exports = require("zlib");;
/******/ // module exports must be returned from runtime so entry inlining is disabled
/******/ // startup
/******/ // Load entry module and return exports
/******/ return __nccwpck_require__(4365);
/******/ return __nccwpck_require__(6062);
/******/ })()
;

This file was deleted.

10 changes: 3 additions & 7 deletions .github/actions/markPullRequestsAsDeployed/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ const isProd = JSON.parse(
core.getInput('IS_PRODUCTION_DEPLOY', {required: true}),
);
const token = core.getInput('GITHUB_TOKEN', {required: true});
const date = new Date();

const octokit = github.getOctokit(token);
const githubUtils = new GithubUtils(octokit);

Expand Down Expand Up @@ -47,12 +45,10 @@ const desktopResult = getDeployTableMessage(core.getInput('DESKTOP', {required:
const iOSResult = getDeployTableMessage(core.getInput('IOS', {required: true}));
const webResult = getDeployTableMessage(core.getInput('WEB', {required: true}));

const workflowURL = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}
/actions/runs/${process.env.GITHUB_RUN_ID}`;

let message = `🚀 [Deployed](${workflowURL}) 🚀 to
${isProd ? 'production' : 'staging'} on ${date.toDateString()} at ${date.toTimeString()}`;
const workflowURL = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}`
+ `/actions/runs/${process.env.GITHUB_RUN_ID}`;

let message = `🚀 [Deployed](${workflowURL}) to ${isProd ? 'production' : 'staging'} 🚀`;
message += `\n\n platform | result \n ---|--- \n🤖 android 🤖|${androidResult} \n🖥 desktop 🖥|${desktopResult}`;
message += `\n🍎 iOS 🍎|${iOSResult} \n🕸 web 🕸|${webResult}`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ const isProd = JSON.parse(
core.getInput('IS_PRODUCTION_DEPLOY', {required: true}),
);
const token = core.getInput('GITHUB_TOKEN', {required: true});
const date = new Date();

const octokit = github.getOctokit(token);
const githubUtils = new GithubUtils(octokit);

Expand Down Expand Up @@ -37,12 +35,10 @@ const desktopResult = getDeployTableMessage(core.getInput('DESKTOP', {required:
const iOSResult = getDeployTableMessage(core.getInput('IOS', {required: true}));
const webResult = getDeployTableMessage(core.getInput('WEB', {required: true}));

const workflowURL = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}
/actions/runs/${process.env.GITHUB_RUN_ID}`;

let message = `🚀 [Deployed](${workflowURL}) 🚀 to
${isProd ? 'production' : 'staging'} on ${date.toDateString()} at ${date.toTimeString()}`;
const workflowURL = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}`
+ `/actions/runs/${process.env.GITHUB_RUN_ID}`;

let message = `🚀 [Deployed](${workflowURL}) to ${isProd ? 'production' : 'staging'} 🚀`;
message += `\n\n platform | result \n ---|--- \n🤖 android 🤖|${androidResult} \n🖥 desktop 🖥|${desktopResult}`;
message += `\n🍎 iOS 🍎|${iOSResult} \n🕸 web 🕸|${webResult}`;

Expand Down
2 changes: 1 addition & 1 deletion .github/libs/GitUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const exec = promisify(require('child_process').exec);
function getPullRequestsMergedBetween(fromRef, toRef) {
return exec(`git log --format="%s" ${fromRef}...${toRef}`)
.then(({stdout}) => (
[...stdout.matchAll(/Merge pull request #(\d{1,6})/g)]
[...stdout.matchAll(/Merge pull request #(\d{1,6}) from (?!Expensify\/(?:master|main|version-))/g)]
.map(match => match[1])
));
}
Expand Down
2 changes: 1 addition & 1 deletion .github/scripts/buildActions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ declare -r GITHUB_ACTIONS=(
"$ACTIONS_DIR/checkDeployBlockers/checkDeployBlockers.js"
"$ACTIONS_DIR/createOrUpdateStagingDeploy/createOrUpdateStagingDeploy.js"
"$ACTIONS_DIR/getReleaseBody/getReleaseBody.js"
"$ACTIONS_DIR/getReleasePullRequestList/getReleasePullRequestList.js"
"$ACTIONS_DIR/getDeployPullRequestList/getDeployPullRequestList.js"
"$ACTIONS_DIR/isPullRequestMergeable/isPullRequestMergeable.js"
"$ACTIONS_DIR/isStagingDeployLocked/isStagingDeployLocked.js"
"$ACTIONS_DIR/markPullRequestsAsDeployed/markPullRequestsAsDeployed.js"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:

- name: Get Release Pull Request List
id: getReleasePRList
uses: Expensify/Expensify.cash/.github/actions/getReleasePullRequestList@main
uses: Expensify/Expensify.cash/.github/actions/getDeployPullRequestList@main
with:
TAG: ${{ env.PRODUCTION_VERSION }}
GITHUB_TOKEN: ${{ secrets.OS_BOTIFY_TOKEN }}
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/platformDeploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,11 @@ jobs:

- name: Get Release Pull Request List
id: getReleasePRList
uses: Expensify/Expensify.cash/.github/actions/getReleasePullRequestList@main
uses: Expensify/Expensify.cash/.github/actions/getDeployPullRequestList@main
with:
TAG: ${{ env.VERSION }}
GITHUB_TOKEN: ${{ secrets.OS_BOTIFY_TOKEN }}
IS_PRODUCTION_DEPLOY: ${{ env.SHOULD_DEPLOY_PRODUCTION == 'true' }}

- name: Comment on issues
uses: Expensify/Expensify.cash/.github/actions/markPullRequestsAsDeployed@main
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/GitUtilsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ const data = [
Merge pull request #1560 from Expensify/version-bump-b742a55d18e761cd7adb0849a29cfb48b3a04f99
Update version to 1.0.1-468
Merge pull request #1555 from SameeraMadushan/sameera-IsAppInstalledLogic
Merge pull request #1 from Expensify/master
Merge pull request #2 from Expensify/main
fix: set pdf width on large screens
[IS-1500] Fixed compose field alignment issue`,
result: ['1521', '1563', '1557', '1562', '1515', '1560', '1555'],
result: ['1521', '1557', '1515', '1555'],
},
{
gitLog: `Return to old hash-based deploy instrcutions
Expand Down