Fix rate limits in release tests (#3106)
* Fix rates limits in release tests * add authorization token to releases/latest request * fix token * add token
This commit is contained in:
parent
e69bf63498
commit
9151fb77aa
2 changed files with 18 additions and 10 deletions
24
.github/workflows/getEnvironmentVariables.js
vendored
24
.github/workflows/getEnvironmentVariables.js
vendored
|
@ -10,8 +10,12 @@ program
|
||||||
.description("Approve and merge PR if patch release")
|
.description("Approve and merge PR if patch release")
|
||||||
.option("--version <version>", "version of a project")
|
.option("--version <version>", "version of a project")
|
||||||
.option("--token <token>", "token fo login to cloud")
|
.option("--token <token>", "token fo login to cloud")
|
||||||
|
.option("--repo_token <repo_token>", "github token")
|
||||||
.action(async options => {
|
.action(async options => {
|
||||||
const isOldVersion = await checkIfOldVersion(options.version);
|
const isOldVersion = await checkIfOldVersion(
|
||||||
|
options.version,
|
||||||
|
options.repo_token,
|
||||||
|
);
|
||||||
core.setOutput("IS_OLD_VERSION", isOldVersion);
|
core.setOutput("IS_OLD_VERSION", isOldVersion);
|
||||||
|
|
||||||
if (!isPatchRelease(options.version)) {
|
if (!isPatchRelease(options.version)) {
|
||||||
|
@ -72,7 +76,7 @@ async function createEnvironment(version, token, versionBefore, snapshot) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Can't create environment- ${JSON.stringify(responseInJson)}`,
|
`Can't create environment- ${JSON.stringify(responseInJson)}`,
|
||||||
);
|
);
|
||||||
const throwErrorAfterTimeoutWhenCreatingEnv = setTimeout(function() {
|
const throwErrorAfterTimeoutWhenCreatingEnv = setTimeout(function () {
|
||||||
throw new Error("Environment didn't crated after 20 minutes");
|
throw new Error("Environment didn't crated after 20 minutes");
|
||||||
}, 1200000);
|
}, 1200000);
|
||||||
return await waitUntilTaskInProgress(
|
return await waitUntilTaskInProgress(
|
||||||
|
@ -106,7 +110,7 @@ async function updateEnvironment(environmentId, version, token) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Can't update environment- ${JSON.stringify(responseInJson)}`,
|
`Can't update environment- ${JSON.stringify(responseInJson)}`,
|
||||||
);
|
);
|
||||||
const throwErrorAfterTimeout = setTimeout(function() {
|
const throwErrorAfterTimeout = setTimeout(function () {
|
||||||
throw new Error("Environment didn't upgraded after 20 minutes");
|
throw new Error("Environment didn't upgraded after 20 minutes");
|
||||||
}, 1200000);
|
}, 1200000);
|
||||||
await waitUntilTaskInProgress(
|
await waitUntilTaskInProgress(
|
||||||
|
@ -135,7 +139,7 @@ async function waitUntilTaskInProgress(taskId, token) {
|
||||||
responseInJson.status == "IN_PROGRESS"
|
responseInJson.status == "IN_PROGRESS"
|
||||||
) {
|
) {
|
||||||
await new Promise(resolve =>
|
await new Promise(resolve =>
|
||||||
setTimeout(function() {
|
setTimeout(function () {
|
||||||
resolve(waitUntilTaskInProgress(taskId, token));
|
resolve(waitUntilTaskInProgress(taskId, token));
|
||||||
}, 10000),
|
}, 10000),
|
||||||
);
|
);
|
||||||
|
@ -176,16 +180,18 @@ async function getDomainForUpdatedEnvironment(environmentId, token) {
|
||||||
return responseInJson.domain;
|
return responseInJson.domain;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function checkIfOldVersion(version) {
|
async function checkIfOldVersion(version, token) {
|
||||||
const newestVersion = await getTheNewestVersion();
|
const newestVersion = await getTheNewestVersion(token);
|
||||||
const howManyVersionsBehind =
|
const howManyVersionsBehind =
|
||||||
getFormattedVersion(newestVersion) - getFormattedVersion(version);
|
getFormattedVersion(newestVersion) - getFormattedVersion(version);
|
||||||
//All versions besides last three are old versions
|
//All versions besides last three are old versions
|
||||||
return howManyVersionsBehind > 2 ? "true" : "false";
|
return howManyVersionsBehind > 2 ? "true" : "false";
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getTheNewestVersion() {
|
async function getTheNewestVersion(token) {
|
||||||
const octokit = new Octokit();
|
const octokit = new Octokit({
|
||||||
|
auth: token,
|
||||||
|
});
|
||||||
|
|
||||||
const response = await octokit.request(
|
const response = await octokit.request(
|
||||||
"GET /repos/{owner}/{repo}/releases/latest",
|
"GET /repos/{owner}/{repo}/releases/latest",
|
||||||
|
@ -233,7 +239,7 @@ function sortServicesByVersion(services) {
|
||||||
// This function is used to sort environments by their version
|
// This function is used to sort environments by their version
|
||||||
// It returns sorted list of services in descending order
|
// It returns sorted list of services in descending order
|
||||||
|
|
||||||
return services.sort(function(a, b) {
|
return services.sort(function (a, b) {
|
||||||
//Convert version from string to array eg. from "3.5.7" to [3, 5, 7]
|
//Convert version from string to array eg. from "3.5.7" to [3, 5, 7]
|
||||||
// Where 3 is main version, 5 is major version and 7 is patch version
|
// Where 3 is main version, 5 is major version and 7 is patch version
|
||||||
|
|
||||||
|
|
4
.github/workflows/tests-nightly.yml
vendored
4
.github/workflows/tests-nightly.yml
vendored
|
@ -158,6 +158,7 @@ jobs:
|
||||||
url: ${{ steps.get-environment-variables.outputs.url }}
|
url: ${{ steps.get-environment-variables.outputs.url }}
|
||||||
is_old_version: ${{ steps.get-environment-variables.outputs.IS_OLD_VERSION }}
|
is_old_version: ${{ steps.get-environment-variables.outputs.IS_OLD_VERSION }}
|
||||||
env:
|
env:
|
||||||
|
REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
TOKEN: ${{ secrets.CLOUD_ACCESS_TOKEN }}
|
TOKEN: ${{ secrets.CLOUD_ACCESS_TOKEN }}
|
||||||
VERSION: ${{github.event.client_payload.version}}
|
VERSION: ${{github.event.client_payload.version}}
|
||||||
steps:
|
steps:
|
||||||
|
@ -179,7 +180,8 @@ jobs:
|
||||||
run: |
|
run: |
|
||||||
node .github/workflows/getEnvironmentVariables.js \
|
node .github/workflows/getEnvironmentVariables.js \
|
||||||
--version $VERSION \
|
--version $VERSION \
|
||||||
--token "$TOKEN"
|
--token "$TOKEN" \
|
||||||
|
--repo_token "$REPO_TOKEN"
|
||||||
|
|
||||||
run-tests-on-release:
|
run-tests-on-release:
|
||||||
if: ${{ github.event_name == 'repository_dispatch' && (github.event.client_payload.environment == 'SANDBOX' || github.event.client_payload.environment == 'STAGING')}}
|
if: ${{ github.event_name == 'repository_dispatch' && (github.event.client_payload.environment == 'SANDBOX' || github.event.client_payload.environment == 'STAGING')}}
|
||||||
|
|
Loading…
Reference in a new issue