fix release workflow for minor versions (#3366)

* fix release workflow for minor versions

* fix run title

* fix run title

* fix run title

* fixes after review

* Fix get branch

* remove complicated if
This commit is contained in:
Karolina Rakoczy 2023-04-19 14:05:27 +02:00 committed by GitHub
parent 82b0684c0e
commit dc960a22b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 12 deletions

View file

@ -9,8 +9,9 @@ program
.name("Approve PR") .name("Approve PR")
.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 for login to cloud")
.option("--repo_token <repo_token>", "github token") .option("--repo_token <repo_token>", "github token")
.option("--project <project>", "release project")
.action(async options => { .action(async options => {
const isOldVersion = await checkIfOldVersion( const isOldVersion = await checkIfOldVersion(
options.version, options.version,
@ -18,7 +19,7 @@ program
); );
core.setOutput("IS_OLD_VERSION", isOldVersion); 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 //If it's minor version, check services, to get one before current
//Then create environment with this service, and big db //Then create environment with this service, and big db
const snapshotWithBigDB = "nqw0Qmbr"; const snapshotWithBigDB = "nqw0Qmbr";
@ -26,6 +27,7 @@ program
options.version, options.version,
options.token, options.token,
); );
const environmentKey = await createEnvironment( const environmentKey = await createEnvironment(
options.version, options.version,
options.token, options.token,
@ -48,6 +50,9 @@ program
)}.staging.saleor.cloud/`, )}.staging.saleor.cloud/`,
); );
} }
const branch = await getBranch(options.repo_token);
core.setOutput("branch", branch);
}) })
.parse(); .parse();
@ -60,7 +65,7 @@ async function createEnvironment(version, token, versionBefore, snapshot) {
"service": "${versionBefore}", "service": "${versionBefore}",
"project": "staging", "project": "staging",
"name": "minor-release-test-${version}", "name": "minor-release-test-${version}",
"domain_label": "minor-release-test-${getFormattedVersion(version)}", "domain_label": "minor-release-${version}",
"restore_from": "${snapshot}" "restore_from": "${snapshot}"
}`, }`,
headers: { headers: {
@ -262,3 +267,28 @@ function sortServicesByVersion(services) {
} else return 0; } 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";
}
}

View file

@ -1,4 +1,5 @@
name: Execute nightly tests name: Execute nightly tests
run-name: Run tests on ${{ inputs.environment }}${{github.event.client_payload.version}} ${{github.event.client_payload.project}}
on: on:
workflow_dispatch: workflow_dispatch:
@ -161,6 +162,7 @@ jobs:
REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} 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}}
PROJECT: ${{github.event.client_payload.project}}
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v3 uses: actions/checkout@v3
@ -181,7 +183,8 @@ jobs:
node .github/workflows/getEnvironmentVariables.js \ node .github/workflows/getEnvironmentVariables.js \
--version $VERSION \ --version $VERSION \
--token "$TOKEN" \ --token "$TOKEN" \
--repo_token "$REPO_TOKEN" --repo_token "$REPO_TOKEN" \
--project "$PROJECT"
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')}}
@ -200,17 +203,10 @@ jobs:
containers: [1, 2, 3, 4, 5, 6, 7, 8, 9] containers: [1, 2, 3, 4, 5, 6, 7, 8, 9]
steps: 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 - name: Checkout
uses: actions/checkout@v3 uses: actions/checkout@v3
with: with:
ref: ${{ steps.branch.outputs.ref }} ref: ${{ needs.get-environment-variables.outputs.branch }}
- name: Set tag for tests - name: Set tag for tests
id: set-tag-for-tests id: set-tag-for-tests
@ -292,6 +288,7 @@ jobs:
send-slack-notification: send-slack-notification:
if: ${{ failure() && github.event_name == 'repository_dispatch'}} if: ${{ failure() && github.event_name == 'repository_dispatch'}}
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: [get-environment-variables, run-tests-on-release, add-review-and-merge-patch]
steps: steps:
- name: Notify Slack - name: Notify Slack
env: env: