diff --git a/.github/actions/createOrUpdateStagingDeploy/index.js b/.github/actions/createOrUpdateStagingDeploy/index.js index 00be81386a33..5fc7ffa6c9bc 100644 --- a/.github/actions/createOrUpdateStagingDeploy/index.js +++ b/.github/actions/createOrUpdateStagingDeploy/index.js @@ -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]) )); } diff --git a/.github/actions/getReleasePullRequestList/action.yml b/.github/actions/getDeployPullRequestList/action.yml similarity index 67% rename from .github/actions/getReleasePullRequestList/action.yml rename to .github/actions/getDeployPullRequestList/action.yml index b1c436e3a460..98dce92c2bcc 100644 --- a/.github/actions/getReleasePullRequestList/action.yml +++ b/.github/actions/getDeployPullRequestList/action.yml @@ -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' diff --git a/.github/actions/getDeployPullRequestList/getDeployPullRequestList.js b/.github/actions/getDeployPullRequestList/getDeployPullRequestList.js new file mode 100644 index 000000000000..41f1250d9b04 --- /dev/null +++ b/.github/actions/getDeployPullRequestList/getDeployPullRequestList.js @@ -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)); diff --git a/.github/actions/getReleasePullRequestList/index.js b/.github/actions/getDeployPullRequestList/index.js similarity index 99% rename from .github/actions/getReleasePullRequestList/index.js rename to .github/actions/getDeployPullRequestList/index.js index cf1a30f951e5..6072f2ff469d 100644 --- a/.github/actions/getReleasePullRequestList/index.js +++ b/.github/actions/getDeployPullRequestList/index.js @@ -5,7 +5,7 @@ module.exports = /******/ (() => { // webpackBootstrap /******/ var __webpack_modules__ = ({ -/***/ 4365: +/***/ 6062: /***/ ((__unused_webpack_module, __unused_webpack_exports, __nccwpck_require__) => { const _ = __nccwpck_require__(4987); @@ -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)); @@ -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]) )); } @@ -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); /******/ })() ; diff --git a/.github/actions/getReleasePullRequestList/getReleasePullRequestList.js b/.github/actions/getReleasePullRequestList/getReleasePullRequestList.js deleted file mode 100644 index 9c3169dee14e..000000000000 --- a/.github/actions/getReleasePullRequestList/getReleasePullRequestList.js +++ /dev/null @@ -1,38 +0,0 @@ -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}); - -console.log('Fetching release list from github...'); -octokit.repos.listReleases({ - owner: github.context.repo.owner, - repo: github.context.repo.repo, -}) - .catch(githubError => core.setFailed(githubError)) - .then(({data}) => { - const tags = _.pluck(data, 'tag_name'); - 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]}`); - } - - 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 Release Tag: ${inputTag}`); - console.log(`Prior Release Tag: ${priorTag}`); - - return GitUtils.getPullRequestsMergedBetween(priorTag, inputTag); - }) - .then(pullRequestList => core.setOutput('PR_LIST', pullRequestList)) - .catch(error => core.setFailed(error)); diff --git a/.github/actions/markPullRequestsAsDeployed/index.js b/.github/actions/markPullRequestsAsDeployed/index.js index eaffa177a2f4..eb24d24e90c5 100644 --- a/.github/actions/markPullRequestsAsDeployed/index.js +++ b/.github/actions/markPullRequestsAsDeployed/index.js @@ -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); @@ -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}`; diff --git a/.github/actions/markPullRequestsAsDeployed/markPullRequestsAsDeployed.js b/.github/actions/markPullRequestsAsDeployed/markPullRequestsAsDeployed.js index 59cbbdbdb13f..3449a4341088 100644 --- a/.github/actions/markPullRequestsAsDeployed/markPullRequestsAsDeployed.js +++ b/.github/actions/markPullRequestsAsDeployed/markPullRequestsAsDeployed.js @@ -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); @@ -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}`; diff --git a/.github/libs/GitUtils.js b/.github/libs/GitUtils.js index d1af2ab3440a..6c7110c07074 100644 --- a/.github/libs/GitUtils.js +++ b/.github/libs/GitUtils.js @@ -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]) )); } diff --git a/.github/scripts/buildActions.sh b/.github/scripts/buildActions.sh index bf43372e5da0..af9811f7e328 100755 --- a/.github/scripts/buildActions.sh +++ b/.github/scripts/buildActions.sh @@ -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" diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 10b7b424ff69..30108d10511c 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -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 }} diff --git a/.github/workflows/platformDeploy.yml b/.github/workflows/platformDeploy.yml index ae3eff18b447..0255fc0302a2 100644 --- a/.github/workflows/platformDeploy.yml +++ b/.github/workflows/platformDeploy.yml @@ -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 diff --git a/tests/unit/GitUtilsTest.js b/tests/unit/GitUtilsTest.js index ba579585f5a3..77845a4c31c3 100644 --- a/tests/unit/GitUtilsTest.js +++ b/tests/unit/GitUtilsTest.js @@ -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