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

Feat/follow deploy #1

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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 dist/index.js

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,18 @@ const getBearerToken = () => fetch('https://auth.scalingo.com/v1/tokens/exchange
})
.then((res) => res.json());

const getDeploymentInfo = (deploymentID) => fetch(`${apiUrl}/v1/apps/${appName}/deployments/${deploymentID}`, {
method: 'POST',
body: null,
headers: {
Authorization: `Bearer ${bearerToken}`,
'Content-Type': 'application/json',
},
})
.then((res) => res.json());

module.exports = {
createDeployment,
getBearerToken,
getDeploymentInfo,
};
18 changes: 16 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const core = require('@actions/core');
const github = require('@actions/github');
const { createDeployment, getBearerToken } = require('./api');
const { createDeployment, getBearerToken, getDeploymentInfo } = require('./api');
const { branch } = require('./constants');

const getBranchToDeploy = () => {
Expand Down Expand Up @@ -28,7 +28,21 @@ const main = async () => {
const { token } = await getBearerToken();
const targetBranch = getBranchToDeploy();

await createDeployment(token, targetBranch);
const deployments = await createDeployment(token, targetBranch);

if (deployments){
let deploymentInfo;
do {
deploymentInfo = await getDeploymentInfo(deployments.deployment.id)
if (deploymentInfo) {
let deployStatus = deploymentInfo.deployment.status
if (deployStatus !== 'success' && deployStatus !== 'failed') {
await new Promise(resolve => setTimeout(resolve, 5000));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Du coup ici je ferais plutôt un setInterval que tu viens clear quand c'est succeeded ou failed

}
}
} while (deploymentInfo.deployment.status !== "success" && deploymentInfo.deployment.status !== "error");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je mettrais un timeout quand même au pour pas cramer les quotas de ta GHA si jamais le déploiement dure trop longtemps

}

} catch (err) {
core.error(err);
}
Expand Down