diff --git a/.github/workflows/getEnvironmentVariables.js b/.github/workflows/getEnvironmentVariables.js index d646badb8..cd28f33a3 100644 --- a/.github/workflows/getEnvironmentVariables.js +++ b/.github/workflows/getEnvironmentVariables.js @@ -10,8 +10,12 @@ program .description("Approve and merge PR if patch release") .option("--version ", "version of a project") .option("--token ", "token fo login to cloud") + .option("--repo_token ", "github token") .action(async options => { - const isOldVersion = await checkIfOldVersion(options.version); + const isOldVersion = await checkIfOldVersion( + options.version, + options.repo_token, + ); core.setOutput("IS_OLD_VERSION", isOldVersion); if (!isPatchRelease(options.version)) { @@ -72,7 +76,7 @@ async function createEnvironment(version, token, versionBefore, snapshot) { throw new Error( `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"); }, 1200000); return await waitUntilTaskInProgress( @@ -106,7 +110,7 @@ async function updateEnvironment(environmentId, version, token) { throw new Error( `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"); }, 1200000); await waitUntilTaskInProgress( @@ -135,7 +139,7 @@ async function waitUntilTaskInProgress(taskId, token) { responseInJson.status == "IN_PROGRESS" ) { await new Promise(resolve => - setTimeout(function() { + setTimeout(function () { resolve(waitUntilTaskInProgress(taskId, token)); }, 10000), ); @@ -176,16 +180,18 @@ async function getDomainForUpdatedEnvironment(environmentId, token) { return responseInJson.domain; } -async function checkIfOldVersion(version) { - const newestVersion = await getTheNewestVersion(); +async function checkIfOldVersion(version, token) { + const newestVersion = await getTheNewestVersion(token); const howManyVersionsBehind = getFormattedVersion(newestVersion) - getFormattedVersion(version); //All versions besides last three are old versions return howManyVersionsBehind > 2 ? "true" : "false"; } -async function getTheNewestVersion() { - const octokit = new Octokit(); +async function getTheNewestVersion(token) { + const octokit = new Octokit({ + auth: token, + }); const response = await octokit.request( "GET /repos/{owner}/{repo}/releases/latest", @@ -233,7 +239,7 @@ function sortServicesByVersion(services) { // This function is used to sort environments by their version // 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] // Where 3 is main version, 5 is major version and 7 is patch version diff --git a/.github/workflows/tests-nightly.yml b/.github/workflows/tests-nightly.yml index 921519181..180d28e60 100644 --- a/.github/workflows/tests-nightly.yml +++ b/.github/workflows/tests-nightly.yml @@ -158,6 +158,7 @@ jobs: url: ${{ steps.get-environment-variables.outputs.url }} is_old_version: ${{ steps.get-environment-variables.outputs.IS_OLD_VERSION }} env: + REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} TOKEN: ${{ secrets.CLOUD_ACCESS_TOKEN }} VERSION: ${{github.event.client_payload.version}} steps: @@ -179,7 +180,8 @@ jobs: run: | node .github/workflows/getEnvironmentVariables.js \ --version $VERSION \ - --token "$TOKEN" + --token "$TOKEN" \ + --repo_token "$REPO_TOKEN" run-tests-on-release: if: ${{ github.event_name == 'repository_dispatch' && (github.event.client_payload.environment == 'SANDBOX' || github.event.client_payload.environment == 'STAGING')}}