diff --git a/.github/workflows/getEnvironmentVariables.js b/.github/workflows/getEnvironmentVariables.js index cd28f33a3..d79006ab3 100644 --- a/.github/workflows/getEnvironmentVariables.js +++ b/.github/workflows/getEnvironmentVariables.js @@ -9,8 +9,9 @@ program .name("Approve PR") .description("Approve and merge PR if patch release") .option("--version ", "version of a project") - .option("--token ", "token fo login to cloud") + .option("--token ", "token for login to cloud") .option("--repo_token ", "github token") + .option("--project ", "release project") .action(async options => { const isOldVersion = await checkIfOldVersion( options.version, @@ -18,7 +19,7 @@ program ); core.setOutput("IS_OLD_VERSION", isOldVersion); - if (!isPatchRelease(options.version)) { + if (!isPatchRelease(options.version) && options.project == "CORE") { //If it's minor version, check services, to get one before current //Then create environment with this service, and big db const snapshotWithBigDB = "nqw0Qmbr"; @@ -26,6 +27,7 @@ program options.version, options.token, ); + const environmentKey = await createEnvironment( options.version, options.token, @@ -48,6 +50,9 @@ program )}.staging.saleor.cloud/`, ); } + + const branch = await getBranch(options.repo_token); + core.setOutput("branch", branch); }) .parse(); @@ -60,7 +65,7 @@ async function createEnvironment(version, token, versionBefore, snapshot) { "service": "${versionBefore}", "project": "staging", "name": "minor-release-test-${version}", - "domain_label": "minor-release-test-${getFormattedVersion(version)}", + "domain_label": "minor-release-${version}", "restore_from": "${snapshot}" }`, headers: { @@ -262,3 +267,28 @@ function sortServicesByVersion(services) { } else return 0; }); } + +async function getBranch(token, version) { + const regex = /^\d+\.\d+/; + const formattedVersion = version.match(regex)[0]; + + const octokit = new Octokit({ + auth: token, + }); + + try { + const response = await octokit.request( + `GET /repos/{owner}/{repo}/branches/${formattedVersion}`, + { + owner: "saleor", + repo: "saleor-dashboard", + headers: { + "X-GitHub-Api-Version": "2022-11-28", + }, + }, + ); + return response.status == 200 ? response.data.name : "main"; + } catch (error) { + return "main"; + } +} diff --git a/.github/workflows/tests-nightly.yml b/.github/workflows/tests-nightly.yml index 78abd6a4b..0a38af208 100644 --- a/.github/workflows/tests-nightly.yml +++ b/.github/workflows/tests-nightly.yml @@ -1,4 +1,5 @@ name: Execute nightly tests +run-name: Run tests on ${{ inputs.environment }}${{github.event.client_payload.version}} ${{github.event.client_payload.project}} on: workflow_dispatch: @@ -161,6 +162,7 @@ jobs: REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} TOKEN: ${{ secrets.CLOUD_ACCESS_TOKEN }} VERSION: ${{github.event.client_payload.version}} + PROJECT: ${{github.event.client_payload.project}} steps: - name: Checkout uses: actions/checkout@v3 @@ -181,7 +183,8 @@ jobs: node .github/workflows/getEnvironmentVariables.js \ --version $VERSION \ --token "$TOKEN" \ - --repo_token "$REPO_TOKEN" + --repo_token "$REPO_TOKEN" \ + --project "$PROJECT" run-tests-on-release: if: ${{ github.event_name == 'repository_dispatch' && (github.event.client_payload.environment == 'SANDBOX' || github.event.client_payload.environment == 'STAGING')}} @@ -200,17 +203,10 @@ jobs: containers: [1, 2, 3, 4, 5, 6, 7, 8, 9] steps: - - name: Get branch - id: branch - env: - version: ${{github.event.client_payload.version}} - run: | - echo "ref=$(echo $version | grep -ohE "[0-9]\.[0-9]+" )" >> $GITHUB_OUTPUT - - name: Checkout uses: actions/checkout@v3 with: - ref: ${{ steps.branch.outputs.ref }} + ref: ${{ needs.get-environment-variables.outputs.branch }} - name: Set tag for tests id: set-tag-for-tests @@ -292,6 +288,7 @@ jobs: send-slack-notification: if: ${{ failure() && github.event_name == 'repository_dispatch'}} runs-on: ubuntu-latest + needs: [get-environment-variables, run-tests-on-release, add-review-and-merge-patch] steps: - name: Notify Slack env: