Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into feat-32317-group_chats
Browse files Browse the repository at this point in the history
  • Loading branch information
waterim committed Mar 28, 2024
2 parents 416d935 + 469b112 commit bfdef65
Show file tree
Hide file tree
Showing 153 changed files with 2,866 additions and 4,049 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,59 @@ const GitHubUtils = require('../../../libs/GithubUtils');
const {promiseDoWhile} = require('../../../libs/promiseWhile');

function run() {
console.info('[awaitStagingDeploys] run()');
console.info('[awaitStagingDeploys] ActionUtils', ActionUtils);
console.info('[awaitStagingDeploys] GitHubUtils', GitHubUtils);
console.info('[awaitStagingDeploys] promiseDoWhile', promiseDoWhile);

const tag = ActionUtils.getStringInput('TAG', {required: false});
console.info('[awaitStagingDeploys] run() tag', tag);

let currentStagingDeploys = [];

console.info('[awaitStagingDeploys] run() _.throttle', _.throttle);

const throttleFunc = () =>
Promise.all([
// These are active deploys
GitHubUtils.octokit.actions.listWorkflowRuns({
owner: CONST.GITHUB_OWNER,
repo: CONST.APP_REPO,
workflow_id: 'platformDeploy.yml',
event: 'push',
branch: tag,
}),

// These have the potential to become active deploys, so we need to wait for them to finish as well (unless we're looking for a specific tag)
// In this context, we'll refer to unresolved preDeploy workflow runs as staging deploys as well
!tag &&
GitHubUtils.octokit.actions.listWorkflowRuns({
owner: CONST.GITHUB_OWNER,
repo: CONST.APP_REPO,
workflow_id: 'preDeploy.yml',
}),
])
.then((responses) => {
const workflowRuns = responses[0].data.workflow_runs;
if (!tag) {
workflowRuns.push(...responses[1].data.workflow_runs);
}
return workflowRuns;
})
.then((workflowRuns) => (currentStagingDeploys = _.filter(workflowRuns, (workflowRun) => workflowRun.status !== 'completed')))
.then(() =>
console.log(
_.isEmpty(currentStagingDeploys)
? 'No current staging deploys found'
: `Found ${currentStagingDeploys.length} staging deploy${currentStagingDeploys.length > 1 ? 's' : ''} still running...`,
),
);
console.info('[awaitStagingDeploys] run() throttleFunc', throttleFunc);

return promiseDoWhile(
() => !_.isEmpty(currentStagingDeploys),
_.throttle(
() =>
Promise.all([
// These are active deploys
GitHubUtils.octokit.actions.listWorkflowRuns({
owner: CONST.GITHUB_OWNER,
repo: CONST.APP_REPO,
workflow_id: 'platformDeploy.yml',
event: 'push',
branch: tag,
}),

// These have the potential to become active deploys, so we need to wait for them to finish as well (unless we're looking for a specific tag)
// In this context, we'll refer to unresolved preDeploy workflow runs as staging deploys as well
!tag &&
GitHubUtils.octokit.actions.listWorkflowRuns({
owner: CONST.GITHUB_OWNER,
repo: CONST.APP_REPO,
workflow_id: 'preDeploy.yml',
}),
])
.then((responses) => {
const workflowRuns = responses[0].data.workflow_runs;
if (!tag) {
workflowRuns.push(...responses[1].data.workflow_runs);
}
return workflowRuns;
})
.then((workflowRuns) => (currentStagingDeploys = _.filter(workflowRuns, (workflowRun) => workflowRun.status !== 'completed')))
.then(() =>
console.log(
_.isEmpty(currentStagingDeploys)
? 'No current staging deploys found'
: `Found ${currentStagingDeploys.length} staging deploy${currentStagingDeploys.length > 1 ? 's' : ''} still running...`,
),
),
throttleFunc,

// Poll every 60 seconds instead of every 10 seconds
GitHubUtils.POLL_RATE * 6,
Expand Down
96 changes: 59 additions & 37 deletions .github/actions/javascript/awaitStagingDeploys/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,46 +14,59 @@ const GitHubUtils = __nccwpck_require__(9296);
const {promiseDoWhile} = __nccwpck_require__(4502);

function run() {
console.info('[awaitStagingDeploys] run()');
console.info('[awaitStagingDeploys] ActionUtils', ActionUtils);
console.info('[awaitStagingDeploys] GitHubUtils', GitHubUtils);
console.info('[awaitStagingDeploys] promiseDoWhile', promiseDoWhile);

const tag = ActionUtils.getStringInput('TAG', {required: false});
console.info('[awaitStagingDeploys] run() tag', tag);

let currentStagingDeploys = [];

console.info('[awaitStagingDeploys] run() _.throttle', _.throttle);

const throttleFunc = () =>
Promise.all([
// These are active deploys
GitHubUtils.octokit.actions.listWorkflowRuns({
owner: CONST.GITHUB_OWNER,
repo: CONST.APP_REPO,
workflow_id: 'platformDeploy.yml',
event: 'push',
branch: tag,
}),

// These have the potential to become active deploys, so we need to wait for them to finish as well (unless we're looking for a specific tag)
// In this context, we'll refer to unresolved preDeploy workflow runs as staging deploys as well
!tag &&
GitHubUtils.octokit.actions.listWorkflowRuns({
owner: CONST.GITHUB_OWNER,
repo: CONST.APP_REPO,
workflow_id: 'preDeploy.yml',
}),
])
.then((responses) => {
const workflowRuns = responses[0].data.workflow_runs;
if (!tag) {
workflowRuns.push(...responses[1].data.workflow_runs);
}
return workflowRuns;
})
.then((workflowRuns) => (currentStagingDeploys = _.filter(workflowRuns, (workflowRun) => workflowRun.status !== 'completed')))
.then(() =>
console.log(
_.isEmpty(currentStagingDeploys)
? 'No current staging deploys found'
: `Found ${currentStagingDeploys.length} staging deploy${currentStagingDeploys.length > 1 ? 's' : ''} still running...`,
),
);
console.info('[awaitStagingDeploys] run() throttleFunc', throttleFunc);

return promiseDoWhile(
() => !_.isEmpty(currentStagingDeploys),
_.throttle(
() =>
Promise.all([
// These are active deploys
GitHubUtils.octokit.actions.listWorkflowRuns({
owner: CONST.GITHUB_OWNER,
repo: CONST.APP_REPO,
workflow_id: 'platformDeploy.yml',
event: 'push',
branch: tag,
}),

// These have the potential to become active deploys, so we need to wait for them to finish as well (unless we're looking for a specific tag)
// In this context, we'll refer to unresolved preDeploy workflow runs as staging deploys as well
!tag &&
GitHubUtils.octokit.actions.listWorkflowRuns({
owner: CONST.GITHUB_OWNER,
repo: CONST.APP_REPO,
workflow_id: 'preDeploy.yml',
}),
])
.then((responses) => {
const workflowRuns = responses[0].data.workflow_runs;
if (!tag) {
workflowRuns.push(...responses[1].data.workflow_runs);
}
return workflowRuns;
})
.then((workflowRuns) => (currentStagingDeploys = _.filter(workflowRuns, (workflowRun) => workflowRun.status !== 'completed')))
.then(() =>
console.log(
_.isEmpty(currentStagingDeploys)
? 'No current staging deploys found'
: `Found ${currentStagingDeploys.length} staging deploy${currentStagingDeploys.length > 1 ? 's' : ''} still running...`,
),
),
throttleFunc,

// Poll every 60 seconds instead of every 10 seconds
GitHubUtils.POLL_RATE * 6,
Expand Down Expand Up @@ -151,12 +164,16 @@ module.exports = CONST;
* @returns {Promise}
*/
function promiseWhile(condition, action) {
console.info('[promiseWhile] promiseWhile()');

return new Promise((resolve, reject) => {
const loop = function () {
if (!condition()) {
resolve();
} else {
Promise.resolve(action()).then(loop).catch(reject);
const actionResult = action();
console.info('[promiseWhile] promiseWhile() actionResult', actionResult);
Promise.resolve(actionResult).then(loop).catch(reject);
}
};
loop();
Expand All @@ -171,8 +188,13 @@ function promiseWhile(condition, action) {
* @returns {Promise}
*/
function promiseDoWhile(condition, action) {
console.info('[promiseWhile] promiseDoWhile()');

return new Promise((resolve, reject) => {
action()
console.info('[promiseWhile] promiseDoWhile() condition', condition);
const actionResult = action();
console.info('[promiseWhile] promiseDoWhile() actionResult', actionResult);
actionResult
.then(() => promiseWhile(condition, action))
.then(() => resolve())
.catch(reject);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
const _ = require('underscore');
const core = require('@actions/core');
const GithubUtils = require('../../../libs/GithubUtils');
import * as core from '@actions/core';
import GithubUtils from '@github/libs/GithubUtils';

const run = function () {
const run = function (): Promise<void> {
const artifactName = core.getInput('ARTIFACT_NAME', {required: true});

return GithubUtils.getArtifactByName(artifactName)
.then((artifact) => {
if (_.isUndefined(artifact)) {
if (artifact === undefined) {
console.log(`No artifact found with the name ${artifactName}`);
core.setOutput('ARTIFACT_FOUND', false);
return;
Expand All @@ -16,9 +15,9 @@ const run = function () {
console.log('Artifact info', artifact);
core.setOutput('ARTIFACT_FOUND', true);
core.setOutput('ARTIFACT_ID', artifact.id);
core.setOutput('ARTIFACT_WORKFLOW_ID', artifact.workflow_run.id);
core.setOutput('ARTIFACT_WORKFLOW_ID', artifact.workflow_run?.id);
})
.catch((error) => {
.catch((error: Error) => {
console.error('A problem occurred while trying to communicate with the GitHub API', error);
core.setFailed(error);
});
Expand All @@ -28,4 +27,4 @@ if (require.main === module) {
run();
}

module.exports = run;
export default run;
Loading

0 comments on commit bfdef65

Please sign in to comment.