Skip to content

Commit

Permalink
Merge branch 'main' of github.com:Expensify/App into cdanwards/violat…
Browse files Browse the repository at this point in the history
…ions/required-confirmation-list
  • Loading branch information
cdanwards committed Nov 20, 2023
2 parents ddb4e64 + 9772a22 commit 917fa3e
Show file tree
Hide file tree
Showing 78 changed files with 907 additions and 885 deletions.
4 changes: 2 additions & 2 deletions .github/actions/composite/setupGitForOSBotifyApp/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ runs:
shell: bash
run: |
if [[ -f .github/workflows/OSBotify-private-key.asc.gpg ]]; then
echo "::set-output name=key_exists::true"
echo "key_exists=true" >> "$GITHUB_OUTPUT"
fi
- name: Checkout
uses: actions/checkout@v4
if: steps.key_check.outputs.key_exists != 'true'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ inputs:
GITHUB_TOKEN:
description: Auth token for New Expensify Github
required: true
NPM_VERSION:
description: The new NPM version of the StagingDeployCash issue.
required: false

runs:
using: 'node20'
main: './index.js'
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const fs = require('fs');
const format = require('date-fns/format');
const _ = require('underscore');
const core = require('@actions/core');
Expand All @@ -6,8 +7,8 @@ const GithubUtils = require('../../../libs/GithubUtils');
const GitUtils = require('../../../libs/GitUtils');

async function run() {
const newVersion = core.getInput('NPM_VERSION');
console.log('New version found from action input:', newVersion);
// Note: require('package.json').version does not work because ncc will resolve that to a plain string at compile time
const newVersionTag = JSON.parse(fs.readFileSync('package.json')).version;

try {
// Start by fetching the list of recent StagingDeployCash issues, along with the list of open deploy blockers
Expand Down Expand Up @@ -35,14 +36,12 @@ async function run() {
const currentChecklistData = shouldCreateNewDeployChecklist ? {} : GithubUtils.getStagingDeployCashData(mostRecentChecklist);

// Find the list of PRs merged between the current checklist and the previous checklist
// Note that any time we're creating a new checklist we MUST have `NPM_VERSION` passed in as an input
const newTag = newVersion || _.get(currentChecklistData, 'tag');
const mergedPRs = await GitUtils.getPullRequestsMergedBetween(previousChecklistData.tag, newTag);
const mergedPRs = await GitUtils.getPullRequestsMergedBetween(previousChecklistData.tag, newVersionTag);

// Next, we generate the checklist body
let checklistBody = '';
if (shouldCreateNewDeployChecklist) {
checklistBody = await GithubUtils.generateStagingDeployCashBody(newTag, _.map(mergedPRs, GithubUtils.getPullRequestURLFromNumber));
checklistBody = await GithubUtils.generateStagingDeployCashBody(newVersionTag, _.map(mergedPRs, GithubUtils.getPullRequestURLFromNumber));
} else {
// Generate the updated PR list, preserving the previous state of `isVerified` for existing PRs
const PRList = _.reduce(
Expand Down Expand Up @@ -94,9 +93,9 @@ async function run() {
});
}

const didVersionChange = newVersion ? newVersion !== currentChecklistData.tag : false;
const didVersionChange = newVersionTag !== currentChecklistData.tag;
checklistBody = await GithubUtils.generateStagingDeployCashBody(
newTag,
newVersionTag,
_.pluck(PRList, 'url'),
_.pluck(_.where(PRList, {isVerified: true}), 'url'),
_.pluck(deployBlockers, 'url'),
Expand Down
55 changes: 28 additions & 27 deletions .github/actions/javascript/createOrUpdateStagingDeploy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/***/ 3926:
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {

const fs = __nccwpck_require__(7147);
const format = __nccwpck_require__(2168);
const _ = __nccwpck_require__(5067);
const core = __nccwpck_require__(2186);
Expand All @@ -15,8 +16,8 @@ const GithubUtils = __nccwpck_require__(7999);
const GitUtils = __nccwpck_require__(669);

async function run() {
const newVersion = core.getInput('NPM_VERSION');
console.log('New version found from action input:', newVersion);
// Note: require('package.json').version does not work because ncc will resolve that to a plain string at compile time
const newVersionTag = JSON.parse(fs.readFileSync('package.json')).version;

try {
// Start by fetching the list of recent StagingDeployCash issues, along with the list of open deploy blockers
Expand Down Expand Up @@ -44,14 +45,12 @@ async function run() {
const currentChecklistData = shouldCreateNewDeployChecklist ? {} : GithubUtils.getStagingDeployCashData(mostRecentChecklist);

// Find the list of PRs merged between the current checklist and the previous checklist
// Note that any time we're creating a new checklist we MUST have `NPM_VERSION` passed in as an input
const newTag = newVersion || _.get(currentChecklistData, 'tag');
const mergedPRs = await GitUtils.getPullRequestsMergedBetween(previousChecklistData.tag, newTag);
const mergedPRs = await GitUtils.getPullRequestsMergedBetween(previousChecklistData.tag, newVersionTag);

// Next, we generate the checklist body
let checklistBody = '';
if (shouldCreateNewDeployChecklist) {
checklistBody = await GithubUtils.generateStagingDeployCashBody(newTag, _.map(mergedPRs, GithubUtils.getPullRequestURLFromNumber));
checklistBody = await GithubUtils.generateStagingDeployCashBody(newVersionTag, _.map(mergedPRs, GithubUtils.getPullRequestURLFromNumber));
} else {
// Generate the updated PR list, preserving the previous state of `isVerified` for existing PRs
const PRList = _.reduce(
Expand Down Expand Up @@ -103,9 +102,9 @@ async function run() {
});
}

const didVersionChange = newVersion ? newVersion !== currentChecklistData.tag : false;
const didVersionChange = newVersionTag !== currentChecklistData.tag;
checklistBody = await GithubUtils.generateStagingDeployCashBody(
newTag,
newVersionTag,
_.pluck(PRList, 'url'),
_.pluck(_.where(PRList, {isVerified: true}), 'url'),
_.pluck(deployBlockers, 'url'),
Expand Down Expand Up @@ -191,26 +190,27 @@ const {getPreviousVersion, SEMANTIC_VERSION_LEVELS} = __nccwpck_require__(8007);

/**
* @param {String} tag
* @param {String} [shallowExcludeTag] when fetching the given tag, exclude all history reachable by the shallowExcludeTag (used to make fetch much faster)
*/
function fetchTag(tag) {
const previousPatchVersion = getPreviousVersion(tag, SEMANTIC_VERSION_LEVELS.PATCH);
function fetchTag(tag, shallowExcludeTag = '') {
let shouldRetry = true;
let needsRepack = false;
while (shouldRetry) {
try {
let command = '';
if (needsRepack) {
// We have seen some scenarios where this fixes the git fetch.
// Why? Who knows... https://github.com/Expensify/App/pull/31459
execSync('git repack -d');
command = 'git repack -d';
console.log(`Running command: ${command}`);
execSync(command);
}

let command = `git fetch origin tag ${tag} --no-tags`;
command = `git fetch origin tag ${tag} --no-tags`;

// Exclude commits reachable from the previous patch version (i.e: previous checklist),
// so that we don't have to fetch the full history
// Note that this condition would only ever _not_ be true in the 1.0.0-0 edge case
if (previousPatchVersion !== tag) {
command += ` --shallow-exclude=${previousPatchVersion}`;
// Note that this condition is only ever NOT true in the 1.0.0-0 edge case
if (shallowExcludeTag && shallowExcludeTag !== tag) {
command += ` --shallow-exclude=${shallowExcludeTag}`;
}

console.log(`Running command: ${command}`);
Expand All @@ -237,8 +237,10 @@ function fetchTag(tag) {
* @returns {Promise<Array<Object<{commit: String, subject: String, authorName: String}>>>}
*/
function getCommitHistoryAsJSON(fromTag, toTag) {
fetchTag(fromTag);
fetchTag(toTag);
// Fetch tags, exclude commits reachable from the previous patch version (i.e: previous checklist), so that we don't have to fetch the full history
const previousPatchVersion = getPreviousVersion(fromTag, SEMANTIC_VERSION_LEVELS.PATCH);
fetchTag(fromTag, previousPatchVersion);
fetchTag(toTag, previousPatchVersion);

console.log('Getting pull requests merged between the following tags:', fromTag, toTag);
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -315,16 +317,15 @@ function getValidMergedPRs(commits) {
* @param {String} toTag
* @returns {Promise<Array<Number>>} – Pull request numbers
*/
function getPullRequestsMergedBetween(fromTag, toTag) {
async function getPullRequestsMergedBetween(fromTag, toTag) {
console.log(`Looking for commits made between ${fromTag} and ${toTag}...`);
return getCommitHistoryAsJSON(fromTag, toTag).then((commitList) => {
console.log(`Commits made between ${fromTag} and ${toTag}:`, commitList);
const commitList = await getCommitHistoryAsJSON(fromTag, toTag);
console.log(`Commits made between ${fromTag} and ${toTag}:`, commitList);

// Find which commit messages correspond to merged PR's
const pullRequestNumbers = getValidMergedPRs(commitList);
console.log(`List of pull requests merged between ${fromTag} and ${toTag}`, pullRequestNumbers);
return _.map(pullRequestNumbers, (prNum) => Number.parseInt(prNum, 10));
});
// Find which commit messages correspond to merged PR's
const pullRequestNumbers = getValidMergedPRs(commitList).sort((a, b) => a - b);
console.log(`List of pull requests merged between ${fromTag} and ${toTag}`, pullRequestNumbers);
return pullRequestNumbers;
}

module.exports = {
Expand Down
40 changes: 21 additions & 19 deletions .github/actions/javascript/getDeployPullRequestList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,26 +133,27 @@ const {getPreviousVersion, SEMANTIC_VERSION_LEVELS} = __nccwpck_require__(8007);

/**
* @param {String} tag
* @param {String} [shallowExcludeTag] when fetching the given tag, exclude all history reachable by the shallowExcludeTag (used to make fetch much faster)
*/
function fetchTag(tag) {
const previousPatchVersion = getPreviousVersion(tag, SEMANTIC_VERSION_LEVELS.PATCH);
function fetchTag(tag, shallowExcludeTag = '') {
let shouldRetry = true;
let needsRepack = false;
while (shouldRetry) {
try {
let command = '';
if (needsRepack) {
// We have seen some scenarios where this fixes the git fetch.
// Why? Who knows... https://github.com/Expensify/App/pull/31459
execSync('git repack -d');
command = 'git repack -d';
console.log(`Running command: ${command}`);
execSync(command);
}

let command = `git fetch origin tag ${tag} --no-tags`;
command = `git fetch origin tag ${tag} --no-tags`;

// Exclude commits reachable from the previous patch version (i.e: previous checklist),
// so that we don't have to fetch the full history
// Note that this condition would only ever _not_ be true in the 1.0.0-0 edge case
if (previousPatchVersion !== tag) {
command += ` --shallow-exclude=${previousPatchVersion}`;
// Note that this condition is only ever NOT true in the 1.0.0-0 edge case
if (shallowExcludeTag && shallowExcludeTag !== tag) {
command += ` --shallow-exclude=${shallowExcludeTag}`;
}

console.log(`Running command: ${command}`);
Expand All @@ -179,8 +180,10 @@ function fetchTag(tag) {
* @returns {Promise<Array<Object<{commit: String, subject: String, authorName: String}>>>}
*/
function getCommitHistoryAsJSON(fromTag, toTag) {
fetchTag(fromTag);
fetchTag(toTag);
// Fetch tags, exclude commits reachable from the previous patch version (i.e: previous checklist), so that we don't have to fetch the full history
const previousPatchVersion = getPreviousVersion(fromTag, SEMANTIC_VERSION_LEVELS.PATCH);
fetchTag(fromTag, previousPatchVersion);
fetchTag(toTag, previousPatchVersion);

console.log('Getting pull requests merged between the following tags:', fromTag, toTag);
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -257,16 +260,15 @@ function getValidMergedPRs(commits) {
* @param {String} toTag
* @returns {Promise<Array<Number>>} – Pull request numbers
*/
function getPullRequestsMergedBetween(fromTag, toTag) {
async function getPullRequestsMergedBetween(fromTag, toTag) {
console.log(`Looking for commits made between ${fromTag} and ${toTag}...`);
return getCommitHistoryAsJSON(fromTag, toTag).then((commitList) => {
console.log(`Commits made between ${fromTag} and ${toTag}:`, commitList);
const commitList = await getCommitHistoryAsJSON(fromTag, toTag);
console.log(`Commits made between ${fromTag} and ${toTag}:`, commitList);

// Find which commit messages correspond to merged PR's
const pullRequestNumbers = getValidMergedPRs(commitList);
console.log(`List of pull requests merged between ${fromTag} and ${toTag}`, pullRequestNumbers);
return _.map(pullRequestNumbers, (prNum) => Number.parseInt(prNum, 10));
});
// Find which commit messages correspond to merged PR's
const pullRequestNumbers = getValidMergedPRs(commitList).sort((a, b) => a - b);
console.log(`List of pull requests merged between ${fromTag} and ${toTag}`, pullRequestNumbers);
return pullRequestNumbers;
}

module.exports = {
Expand Down
40 changes: 21 additions & 19 deletions .github/libs/GitUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,27 @@ const {getPreviousVersion, SEMANTIC_VERSION_LEVELS} = require('../libs/versionUp

/**
* @param {String} tag
* @param {String} [shallowExcludeTag] when fetching the given tag, exclude all history reachable by the shallowExcludeTag (used to make fetch much faster)
*/
function fetchTag(tag) {
const previousPatchVersion = getPreviousVersion(tag, SEMANTIC_VERSION_LEVELS.PATCH);
function fetchTag(tag, shallowExcludeTag = '') {
let shouldRetry = true;
let needsRepack = false;
while (shouldRetry) {
try {
let command = '';
if (needsRepack) {
// We have seen some scenarios where this fixes the git fetch.
// Why? Who knows... https://github.com/Expensify/App/pull/31459
execSync('git repack -d');
command = 'git repack -d';
console.log(`Running command: ${command}`);
execSync(command);
}

let command = `git fetch origin tag ${tag} --no-tags`;
command = `git fetch origin tag ${tag} --no-tags`;

// Exclude commits reachable from the previous patch version (i.e: previous checklist),
// so that we don't have to fetch the full history
// Note that this condition would only ever _not_ be true in the 1.0.0-0 edge case
if (previousPatchVersion !== tag) {
command += ` --shallow-exclude=${previousPatchVersion}`;
// Note that this condition is only ever NOT true in the 1.0.0-0 edge case
if (shallowExcludeTag && shallowExcludeTag !== tag) {
command += ` --shallow-exclude=${shallowExcludeTag}`;
}

console.log(`Running command: ${command}`);
Expand All @@ -52,8 +53,10 @@ function fetchTag(tag) {
* @returns {Promise<Array<Object<{commit: String, subject: String, authorName: String}>>>}
*/
function getCommitHistoryAsJSON(fromTag, toTag) {
fetchTag(fromTag);
fetchTag(toTag);
// Fetch tags, exclude commits reachable from the previous patch version (i.e: previous checklist), so that we don't have to fetch the full history
const previousPatchVersion = getPreviousVersion(fromTag, SEMANTIC_VERSION_LEVELS.PATCH);
fetchTag(fromTag, previousPatchVersion);
fetchTag(toTag, previousPatchVersion);

console.log('Getting pull requests merged between the following tags:', fromTag, toTag);
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -130,16 +133,15 @@ function getValidMergedPRs(commits) {
* @param {String} toTag
* @returns {Promise<Array<Number>>} – Pull request numbers
*/
function getPullRequestsMergedBetween(fromTag, toTag) {
async function getPullRequestsMergedBetween(fromTag, toTag) {
console.log(`Looking for commits made between ${fromTag} and ${toTag}...`);
return getCommitHistoryAsJSON(fromTag, toTag).then((commitList) => {
console.log(`Commits made between ${fromTag} and ${toTag}:`, commitList);
const commitList = await getCommitHistoryAsJSON(fromTag, toTag);
console.log(`Commits made between ${fromTag} and ${toTag}:`, commitList);

// Find which commit messages correspond to merged PR's
const pullRequestNumbers = getValidMergedPRs(commitList);
console.log(`List of pull requests merged between ${fromTag} and ${toTag}`, pullRequestNumbers);
return _.map(pullRequestNumbers, (prNum) => Number.parseInt(prNum, 10));
});
// Find which commit messages correspond to merged PR's
const pullRequestNumbers = getValidMergedPRs(commitList).sort((a, b) => a - b);
console.log(`List of pull requests merged between ${fromTag} and ${toTag}`, pullRequestNumbers);
return pullRequestNumbers;
}

module.exports = {
Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/createDeployChecklist.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Create or update deploy checklist

on:
workflow_call:
workflow_dispatch:

jobs:
createChecklist:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node
uses: ./.github/actions/composite/setupNode

- name: Set up git for OSBotify
id: setupGitForOSBotify
uses: ./.github/actions/composite/setupGitForOSBotifyApp
with:
GPG_PASSPHRASE: ${{ secrets.LARGE_SECRET_PASSPHRASE }}
OS_BOTIFY_APP_ID: ${{ secrets.OS_BOTIFY_APP_ID }}
OS_BOTIFY_PRIVATE_KEY: ${{ secrets.OS_BOTIFY_PRIVATE_KEY }}

- name: Create or update deploy checklist
uses: ./.github/actions/javascript/createOrUpdateStagingDeploy
with:
GITHUB_TOKEN: ${{ steps.setupGitForOSBotify.outputs.OS_BOTIFY_API_TOKEN }}
Loading

0 comments on commit 917fa3e

Please sign in to comment.