Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
INFRA-857 - Improve test-envs CICD - better logging and get rid of rlespinasse/github-slug-action (#18678)
Mikolaj Stempniewicz197bd66a7344
diff --git a/.github/workflows/test-env-cleanup-cron.yml b/.github/workflows/test-env-cleanup-cron.ymlindex f58e4b401c..ae1ea8b160 100644--- a/.github/workflows/test-env-cleanup-cron.yml+++ b/.github/workflows/test-env-cleanup-cron.yml@@ -21,27 +21,24 @@ jobs:role-to-assume: arn:aws:iam::${{ secrets.AWS_TESTENVS_ACCOUNT_ID }}:role/${{ secrets.AWS_TESTENVS_CICD_ROLE_NAME }}aws-region: ${{ vars.AWS_TESTENVS_REGION }}- - name: Get branches from open PRs with "test deployment" label- id: get-branches+ - name: Get branches from open PRs with "test deployment" label and slugify+ id: get-branches-and-slugifyuses: actions/github-script@v8with:script: |- // Get all open PRs - pagination is needed or otherwise we would retrieve only first 30+ // 1. Get all open PRs - pagination is needed or otherwise we would retrieve only first 30const pulls = await github.paginate(github.rest.pulls.list, {owner: context.repo.owner,repo: context.repo.repo,state: 'open'});- // Select PRs with "test deployment" label and extract their source branches+ // 2. Select PRs with "test deployment" label and extract their source branchesconst branches = pulls.filter(pr => pr.labels.some(label => label.name === 'test deployment')).map(pr => pr.head.ref);- // Deduplicate (in case there are multiple PRs with the same source branch) and then slugify the branch names- // using the same logic as https://github.com/marketplace/actions/github-slug-action#overview (this GHA is used- // to slugify branch names in the https://github.com/saleor/saleor/actions/workflows/test-env-deploy.yml workflow,- // which this workflow cleans up after).+ // 3. Deduplicate (in case there are multiple PRs with the same source branch) and then slugify the branch namesreturn [...new Set(branches)].map(ref =>ref.toLowerCase().replace(/[^a-z0-9._]/g, '-') // replace any character except [0-9, a-z, .,_] with dash@@ -51,6 +48,7 @@ jobs:);- name: Invoke test-env-manager lambda+ id: lambdauses: gagoar/invoke-aws-lambda@2ea0b5791eba7a9513ddf0fb7f91aa8f098b6458 # v3.4.0with:AWS_ACCESS_KEY_ID: ${{ env.AWS_ACCESS_KEY_ID }}@@ -61,6 +59,37 @@ jobs:Payload: >-{"action": "daily-cleanup",- "labels_to_preserve": ${{ steps.get-branches.outputs.result }}+ "labels_to_preserve": ${{ steps.get-branches-and-slugify.outputs.result }}}LogType: Tail++ - name: Print lambda outputs+ if: ${{ always() && steps.lambda.conclusion != 'skipped' }}+ env:+ RESPONSE: ${{ steps.lambda.outputs.response }}+ INVOCATION_STATUS_CODE: ${{ fromJSON(steps.lambda.outputs.response).StatusCode }}+ LOG_RESULT_BASE64: ${{ fromJSON(steps.lambda.outputs.response).LogResult }}+ FUNCTION_ERROR: ${{ fromJSON(steps.lambda.outputs.response).FunctionError }}+ PAYLOAD: ${{ fromJSON(steps.lambda.outputs.response).Payload }}+ run: |+ # If there is no response (e.g. invoke step failed before calling Lambda), bail out gracefully+ if [ -z "${RESPONSE}" ]; then+ echo "No lambda response available (invoke step may have failed before receiving output)."+ exit 0+ fi++ echo "Invocation HTTP Status Code:"+ echo "${INVOCATION_STATUS_CODE:-null}"+ echo "--------"++ echo "Lambda runtime logs:"+ echo "$LOG_RESULT_BASE64" | base64 --decode || true+ echo "--------"++ echo "FunctionError (If present, indicates that an error has occurred, with more information in Payload):"+ echo "${FUNCTION_ERROR:-null}"+ echo "--------"++ echo "Payload (JSON returned by the function invocation, or error object):"+ echo "${PAYLOAD:-null}"+ echo "--------"diff --git a/.github/workflows/test-env-cleanup.yml b/.github/workflows/test-env-cleanup.ymlindex 11803c5cb1..60d35c0d54 100644--- a/.github/workflows/test-env-cleanup.yml+++ b/.github/workflows/test-env-cleanup.yml@@ -16,7 +16,21 @@ jobs:contents: readdeployments: writesteps:- - uses: rlespinasse/github-slug-action@c33ff65466c58d57e4d796f88bb1ae0ff26ee453 # v5.2.0+ - name: Generate GITHUB_HEAD_REF_SLUG_URL+ id: slugify-branch-name+ uses: actions/github-script@v8+ with:+ result-encoding: string # by default results are JSON-encoded+ script: |+ // 1. Get the PRs' base branch name+ const ref = context.payload.pull_request.head.ref++ // 2. Slugify:+ return slug = ref.toLowerCase() // convert all letters to lowercase+ .replace(/[^a-z0-9._]/g, '-') // replace any character except [0-9, a-z, .,_] with dash+ .replace(/^-+/, '') // remove leading dash+ .slice(0, 63) // trim length down (limit is up to 64 characters)+ .replace(/-+$/, ''); // remove trailing dash- name: Configure AWS Credentialsuses: aws-actions/configure-aws-credentials@a03048d87541d1d9fcf2ecf528a4a65ba9bd7838 # v5.0.0@@ -25,6 +39,7 @@ jobs:aws-region: ${{ vars.AWS_TESTENVS_REGION }}- name: Invoke deployment lambda+ id: lambdauses: gagoar/invoke-aws-lambda@2ea0b5791eba7a9513ddf0fb7f91aa8f098b6458 # v3.4.0with:AWS_ACCESS_KEY_ID: ${{ env.AWS_ACCESS_KEY_ID }}@@ -35,14 +50,45 @@ jobs:Payload: >-{"action": "${{ github.event.action }}",- "label": "${{ env.GITHUB_HEAD_REF_SLUG_URL }}",- "image": "${{ secrets.AWS_TESTENVS_ACCOUNT_ID }}.dkr.ecr.${{ vars.AWS_TESTENVS_REGION }}.amazonaws.com/saleor-testenvs:${{ env.GITHUB_HEAD_REF_SLUG_URL }}"+ "label": "${{ steps.slugify-branch-name.outputs.result }}",+ "image": "${{ secrets.AWS_TESTENVS_ACCOUNT_ID }}.dkr.ecr.${{ vars.AWS_TESTENVS_REGION }}.amazonaws.com/saleor-testenvs:${{ steps.slugify-branch-name.outputs.result }}"}LogType: Tail+ - name: Print lambda outputs+ if: ${{ always() && steps.lambda.conclusion != 'skipped' }}+ env:+ RESPONSE: ${{ steps.lambda.outputs.response }}+ INVOCATION_STATUS_CODE: ${{ fromJSON(steps.lambda.outputs.response).StatusCode }}+ LOG_RESULT_BASE64: ${{ fromJSON(steps.lambda.outputs.response).LogResult }}+ FUNCTION_ERROR: ${{ fromJSON(steps.lambda.outputs.response).FunctionError }}+ PAYLOAD: ${{ fromJSON(steps.lambda.outputs.response).Payload }}+ run: |+ # If there is no response (e.g. invoke step failed before calling Lambda), bail out gracefully+ if [ -z "${RESPONSE}" ]; then+ echo "No lambda response available (invoke step may have failed before receiving output)."+ exit 0+ fi++ echo "Invocation HTTP Status Code:"+ echo "${INVOCATION_STATUS_CODE:-null}"+ echo "--------"++ echo "Lambda runtime logs:"+ echo "$LOG_RESULT_BASE64" | base64 --decode || true+ echo "--------"++ echo "FunctionError (If present, indicates that an error has occurred, with more information in Payload):"+ echo "${FUNCTION_ERROR:-null}"+ echo "--------"++ echo "Payload (JSON returned by the function invocation, or error object):"+ echo "${PAYLOAD:-null}"+ echo "--------"+- name: Mark deployment as deactivateduses: bobheadxi/deployments@648679e8e4915b27893bd7dbc35cb504dc915bc8 # v1.5.0with:step: deactivate-envtoken: ${{ secrets.GITHUB_TOKEN }}- env: ${{ env.GITHUB_HEAD_REF_SLUG_URL }}+ env: ${{ steps.slugify-branch-name.outputs.result }}diff --git a/.github/workflows/test-env-deploy.yml b/.github/workflows/test-env-deploy.ymlindex 1f9dd12561..295114c276 100644--- a/.github/workflows/test-env-deploy.yml+++ b/.github/workflows/test-env-deploy.yml@@ -16,14 +16,29 @@ jobs:contents: readdeployments: writesteps:- - uses: actions/checkout@v5- - uses: rlespinasse/github-slug-action@c33ff65466c58d57e4d796f88bb1ae0ff26ee453 # v5.2.0+ - uses: actions/checkout@v6++ - name: Generate GITHUB_HEAD_REF_SLUG_URL+ id: slugify-branch-name+ uses: actions/github-script@v8+ with:+ result-encoding: string # by default results are JSON-encoded+ script: |+ // 1. Get the PRs' base branch name+ const ref = context.payload.pull_request.head.ref++ // 2. Slugify:+ return slug = ref.toLowerCase() // convert all letters to lowercase+ .replace(/[^a-z0-9._]/g, '-') // replace any character except [0-9, a-z, .,_] with dash+ .replace(/^-+/, '') // remove leading dash+ .slice(0, 63) // trim length down (limit is up to 64 characters)+ .replace(/-+$/, ''); // remove trailing dash- name: Set domainid: set-domain# Set test instance domain based on branch name slugrun: |- echo "domain=${{ env.GITHUB_HEAD_REF_SLUG_URL }}.api.saleor.rocks" >> $GITHUB_OUTPUT+ echo "domain=${{ steps.slugify-branch-name.outputs.result }}.api.saleor.rocks" >> $GITHUB_OUTPUT- name: Start deploymentuses: bobheadxi/deployments@648679e8e4915b27893bd7dbc35cb504dc915bc8 # v1.5.0@@ -31,11 +46,11 @@ jobs:with:step: starttoken: ${{ secrets.GITHUB_TOKEN }}- env: ${{ env.GITHUB_HEAD_REF_SLUG_URL }}+ env: ${{ steps.slugify-branch-name.outputs.result }}ref: ${{ github.head_ref }}- name: Configure AWS Credentials- uses: aws-actions/configure-aws-credentials@a03048d87541d1d9fcf2ecf528a4a65ba9bd7838 # v5.0.0+ uses: aws-actions/configure-aws-credentials@61815dcd50bd041e203e49132bacad1fd04d2708 # v5.1.1with:role-to-assume: arn:aws:iam::${{ secrets.AWS_TESTENVS_ACCOUNT_ID }}:role/${{ secrets.AWS_TESTENVS_CICD_ROLE_NAME }}aws-region: ${{ vars.AWS_TESTENVS_REGION }}@@ -48,9 +63,10 @@ jobs:account_id: ${{ secrets.AWS_TESTENVS_ACCOUNT_ID }}repo: saleor-testenvsregion: ${{ vars.AWS_TESTENVS_REGION }}- tags: ${{ env.GITHUB_HEAD_REF_SLUG_URL }},${{ github.sha }}+ tags: ${{ steps.slugify-branch-name.outputs.result }},${{ github.sha }}- name: Invoke deployment lambda+ id: lambdauses: gagoar/invoke-aws-lambda@2ea0b5791eba7a9513ddf0fb7f91aa8f098b6458 # v3.4.0with:AWS_ACCESS_KEY_ID: ${{ env.AWS_ACCESS_KEY_ID }}@@ -61,18 +77,49 @@ jobs:Payload: >-{"action": "${{ github.event.action }}",- "label": "${{ env.GITHUB_HEAD_REF_SLUG_URL }}",+ "label": "${{ steps.slugify-branch-name.outputs.result }}","image": "${{ secrets.AWS_TESTENVS_ACCOUNT_ID }}.dkr.ecr.${{ vars.AWS_TESTENVS_REGION }}.amazonaws.com/saleor-testenvs:${{ github.sha }}"}LogType: Tail+ - name: Print lambda outputs+ if: ${{ always() && steps.lambda.conclusion != 'skipped' }}+ env:+ RESPONSE: ${{ steps.lambda.outputs.response }}+ INVOCATION_STATUS_CODE: ${{ fromJSON(steps.lambda.outputs.response).StatusCode }}+ LOG_RESULT_BASE64: ${{ fromJSON(steps.lambda.outputs.response).LogResult }}+ FUNCTION_ERROR: ${{ fromJSON(steps.lambda.outputs.response).FunctionError }}+ PAYLOAD: ${{ fromJSON(steps.lambda.outputs.response).Payload }}+ run: |+ # If there is no response (e.g. invoke step failed before calling Lambda), bail out gracefully+ if [ -z "${RESPONSE}" ]; then+ echo "No lambda response available (invoke step may have failed before receiving output)."+ exit 0+ fi++ echo "Invocation HTTP Status Code:"+ echo "${INVOCATION_STATUS_CODE:-null}"+ echo "--------"++ echo "Lambda runtime logs:"+ echo "$LOG_RESULT_BASE64" | base64 --decode || true+ echo "--------"++ echo "FunctionError (If present, indicates that an error has occurred, with more information in Payload):"+ echo "${FUNCTION_ERROR:-null}"+ echo "--------"++ echo "Payload (JSON returned by the function invocation, or error object):"+ echo "${PAYLOAD:-null}"+ echo "--------"+- name: Update deployment statususes: bobheadxi/deployments@648679e8e4915b27893bd7dbc35cb504dc915bc8 # v1.5.0if: always()with:step: finishtoken: ${{ secrets.GITHUB_TOKEN }}- env: ${{ env.GITHUB_HEAD_REF_SLUG_URL }}+ env: ${{ steps.slugify-branch-name.outputs.result }}status: ${{ job.status }}env_url: https://${{ steps.set-domain.outputs.domain }}/graphql/deployment_id: ${{ steps.deployment.outputs.deployment_id }}