Tag docker container as latest accordingly to the version #8449
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: TEST-ENV-DEPLOYMENT | |
# Build and deploy test instance for every pull request | |
on: [pull_request] | |
jobs: | |
deploy: | |
if: github.event.pull_request.head.repo.full_name == 'saleor/saleor-dashboard' | |
runs-on: ubuntu-22.04 | |
outputs: | |
base_URL: ${{ steps.set-domain.outputs.domain }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Setup Node | |
uses: actions/setup-node@v3 | |
with: | |
node-version-file: ".nvmrc" | |
- uses: rlespinasse/github-slug-action@v4 | |
- name: Start deployment | |
uses: bobheadxi/deployments@v1 | |
id: deployment | |
with: | |
step: start | |
token: ${{ secrets.GITHUB_TOKEN }} | |
env: ${{ env.GITHUB_HEAD_REF_SLUG_URL }} | |
ref: ${{ github.head_ref }} | |
- name: Start storybook deployment | |
uses: bobheadxi/deployments@v1 | |
id: storybook-deployment | |
with: | |
step: start | |
token: ${{ secrets.GITHUB_TOKEN }} | |
env: storybook ${{ env.GITHUB_HEAD_REF_SLUG_URL }} | |
ref: ${{ github.head_ref }} | |
- name: Cache node modules | |
uses: actions/cache@v3 | |
env: | |
cache-name: cache-node-modules | |
with: | |
path: ~/.npm | |
key: ${{ runner.os }}-qa-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-qa-${{ env.cache-name }}- | |
${{ runner.os }}-qa- | |
${{ runner.os }}- | |
- name: Install deps | |
run: | | |
npm ci | |
- name: Get custom API_URI | |
id: api_uri | |
# Search for API_URI in PR description | |
env: | |
pull_request_body: ${{ github.event.pull_request.body }} | |
prefix: API_URI= | |
pattern: (http|https)://[a-zA-Z0-9.-]+/graphql/? | |
run: | | |
echo "custom_api_uri=$(echo "$pull_request_body" | grep -Eo "$prefix$pattern" | sed s/$prefix// | head -n 1)" >> $GITHUB_OUTPUT | |
- name: Get APPS_MARKETPLACE_API_URI | |
id: apps_marketplace_api_uri | |
# Search for APPS_MARKETPLACE_API_URI in PR description | |
env: | |
pull_request_body: ${{ github.event.pull_request.body }} | |
prefix: APPS_MARKETPLACE_API_URI= | |
pattern: (http|https)://[a-zA-Z0-9.-]+[a-zA-Z0-9/-]+/? | |
run: | | |
echo "custom_apps_marketplace_api_uri=$(echo "$pull_request_body" | grep -Eo "$prefix$pattern" | sed s/$prefix// | head -n 1)" >> $GITHUB_OUTPUT | |
- name: Run build | |
env: | |
# Use custom API_URI or the default one | |
API_URI: ${{ steps.api_uri.outputs.custom_api_uri || 'https://qa.staging.saleor.cloud/graphql/' }} | |
APPS_MARKETPLACE_API_URI: ${{ steps.apps_marketplace_api_uri.outputs.custom_apps_marketplace_api_uri }} | |
APP_MOUNT_URI: / | |
STATIC_URL: / | |
IS_CLOUD_INSTANCE: true | |
run: | | |
npm run build | |
- name: Run build storybook | |
run: | | |
npm run build-storybook | |
- name: Set domain | |
id: set-domain | |
# Set test instance domain based on branch name slug | |
run: | | |
echo "domain=${{ env.GITHUB_HEAD_REF_SLUG_URL }}.dashboard.saleor.rocks" >> $GITHUB_OUTPUT | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v3 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ secrets.AWS_DEFAULT_REGION }} | |
- name: Deploy to S3 | |
run: | | |
aws s3 sync ./build/dashboard s3://${{ secrets.AWS_TEST_DEPLOYMENT_BUCKET }}/${{ steps.set-domain.outputs.domain }} | |
aws s3 sync ./build/storybook s3://${{ secrets.AWS_TEST_DEPLOYMENT_BUCKET }}/${{ steps.set-domain.outputs.domain }}/storybook | |
- name: Invalidate cache | |
run: aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_TEST_CF_DIST_ID }} --paths "/${{ steps.set-domain.outputs.domain }}/*" | |
- name: Update deployment status | |
uses: bobheadxi/deployments@v1 | |
if: always() | |
with: | |
step: finish | |
token: ${{ secrets.GITHUB_TOKEN }} | |
status: ${{ job.status }} | |
env_url: https://${{ steps.set-domain.outputs.domain }}/ | |
deployment_id: ${{ steps.deployment.outputs.deployment_id }} | |
env: ${{ env.GITHUB_HEAD_REF_SLUG_URL }} | |
- name: Update storybook deployment status | |
uses: bobheadxi/deployments@v1 | |
if: always() | |
with: | |
step: finish | |
token: ${{ secrets.GITHUB_TOKEN }} | |
status: ${{ job.status }} | |
env_url: https://${{ steps.set-domain.outputs.domain }}/storybook/index.html | |
deployment_id: ${{ steps.storybook-deployment.outputs.deployment_id }} | |
env: storybook ${{ env.GITHUB_HEAD_REF_SLUG_URL }} | |
prepare-tests: | |
runs-on: ubuntu-22.04 | |
needs: deploy | |
outputs: | |
tags: ${{steps.get_tags.outputs.result}} | |
containers: ${{ steps.get_containers.outputs.result}} | |
steps: | |
- name: Get tags | |
id: get_tags | |
uses: actions/github-script@v6 | |
env: | |
pullRequestBody: ${{ github.event.pull_request.body }} | |
with: | |
result-encoding: string | |
script: | | |
const { pullRequestBody } = process.env | |
const tags = ["@critical"]; | |
try{ | |
const removedPullRequestBodyBeforeTests = pullRequestBody.split(`### Do you want to run more stable tests?`); | |
const removedPullRequestBodyAfterTests = removedPullRequestBodyBeforeTests[1].split(`CONTAINERS`); | |
let tagsInString = removedPullRequestBodyAfterTests[0]; | |
tagsInString = tagsInString.split('\n'); | |
tagsInString.forEach(line => { | |
if (line.includes('[x]')) tags.push(line.replace(/[0-9]+\. \[x\] /, "@stable+@")) | |
}); | |
const tagsToReturn = tags.join(",").toString(); | |
return tagsToReturn.replace(/\r/g, '') | |
}catch{ | |
return '@critical' | |
} | |
- name: get-containers | |
id: get_containers | |
uses: actions/github-script@v6 | |
env: | |
pullRequestBody: ${{ github.event.pull_request.body }} | |
with: | |
script: | | |
const { pullRequestBody } = process.env | |
const containers = []; | |
const numberOfContainersRegex = /CONTAINERS=(\d*)/ | |
const numberOfContainers = pullRequestBody.match(numberOfContainersRegex); | |
for(let i=1; i<=numberOfContainers[1]; i++){ | |
containers.push(i) | |
} | |
return {"containers": containers} | |
- name: echo-tags | |
run: | | |
echo ${{steps.get_tags.outputs.result}} | |
testmo-report-preparation: | |
needs: prepare-tests | |
if: github.event.pull_request.head.repo.fork == false | |
runs-on: ubuntu-22.04 | |
outputs: | |
testmo-run-id: ${{ steps.run-tests.outputs.TESTMO_RUN_ID }} | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version-file: ".nvmrc" | |
cache: npm | |
- name: install dependencies | |
working-directory: .github/workflows | |
run: npm ci | |
- name: create testmo run | |
working-directory: .github/workflows | |
run: | | |
ID=$(npx testmo automation:run:create \ | |
--instance "$TESTMO_URL" \ | |
--project-id 1 \ | |
--name "Deployment tests" \ | |
--source frontend-e2e-tests) | |
echo "TESTMO_RUN_ID=$ID" >> $GITHUB_OUTPUT | |
env: | |
TESTMO_URL: ${{ secrets.TESTMO_URL }} | |
TESTMO_TOKEN: ${{ secrets.TESTMO_TOKEN }} | |
id: run-tests | |
cypress-run-selected: | |
runs-on: ubuntu-22.04 | |
needs: [prepare-tests, deploy, testmo-report-preparation] | |
container: cypress/browsers:node18.12.0-chrome106-ff106 | |
strategy: | |
fail-fast: false | |
max-parallel: 10 | |
matrix: ${{ fromJson(needs.prepare-tests.outputs.containers) }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Get API_URI | |
id: api_uri | |
# Search for API_URI in PR description and use default if not defined | |
env: | |
pull_request_body: ${{ github.event.pull_request.body }} | |
prefix: API_URI= | |
pattern: (http|https)://[a-zA-Z0-9.-]+/graphql/? | |
fallback_uri: ${{ secrets.CYPRESS_API_URI }} | |
run: | | |
echo "custom_api_uri=$(echo "$pull_request_body" | grep -Eo "$prefix$pattern" | sed s/$prefix// | head -n 1 | { read custom_uri; if [ -z "$custom_uri" ]; then echo "$fallback_uri"; else echo "$custom_uri"; fi })" >> $GITHUB_OUTPUT | |
- name: Setup Node | |
uses: actions/setup-node@v3 | |
with: | |
node-version-file: ".nvmrc" | |
- name: Cache node modules | |
uses: actions/cache@v3 | |
env: | |
cache-name: cache-node-modules | |
with: | |
path: ~/.npm | |
key: ${{ runner.os }}-qa-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-qa-${{ env.cache-name }}- | |
${{ runner.os }}-qa- | |
${{ runner.os }}- | |
- name: Install Dependencies | |
if: steps.cache-node-modules.outputs.cache-hit != 'true' | |
run: NODE_OPTIONS=--max_old_space_size=4096 npm install | |
- name: Cypress run critical | |
if: ${{ ! cancelled() }} | |
uses: cypress-io/github-action@v5 | |
env: | |
API_URI: ${{ steps.api_uri.outputs.custom_api_uri }} | |
APP_MOUNT_URI: ${{ secrets.APP_MOUNT_URI }} | |
CYPRESS_baseUrl: https://${{needs.deploy.outputs.base_URL}}/ | |
CYPRESS_USER_NAME: ${{ secrets.CYPRESS_USER_NAME }} | |
CYPRESS_SECOND_USER_NAME: ${{ secrets.CYPRESS_SECOND_USER_NAME }} | |
CYPRESS_USER_PASSWORD: ${{ secrets.CYPRESS_USER_PASSWORD }} | |
CYPRESS_PERMISSIONS_USERS_PASSWORD: ${{ secrets.CYPRESS_PERMISSIONS_USERS_PASSWORD }} | |
CYPRESS_MAILPITURL: ${{ secrets.CYPRESS_MAILPITURL }} | |
CYPRESS_grepTags: ${{ needs.prepare-tests.outputs.tags }} | |
SPLIT: ${{ strategy.job-total }} | |
SPLIT_INDEX: ${{ strategy.job-index }} | |
- name: Create reports dir | |
if: ${{ ! cancelled() }} | |
run: npm run qa:create-artifacts-dirs | |
- name: Move screenshots into reports dir | |
if: ${{ ! cancelled() }} | |
run: npm run qa:move-screenshots | |
- name: Install dependencies | |
if: ${{ ! cancelled() }} | |
working-directory: .github/workflows | |
run: npm ci | |
- name: Testmo threads submit | |
if: github.event.pull_request.head.repo.fork == false && !cancelled() | |
working-directory: .github/workflows | |
run: | | |
npx testmo automation:run:submit-thread \ | |
--instance "$TESTMO_URL" \ | |
--run-id "$TESTMO_RUN_ID" \ | |
--results ../../cypress/reports/junit/*.xml | |
env: | |
TESTMO_URL: ${{ secrets.TESTMO_URL }} | |
TESTMO_TOKEN: ${{ secrets.TESTMO_TOKEN }} | |
TESTMO_RUN_ID: ${{ needs.testmo-report-preparation.outputs.testmo-run-id }} | |
- name: Upload reports | |
uses: actions/upload-artifact@v3 | |
if: always() | |
with: | |
name: report-${{ strategy.job-index }} | |
path: ./cypress/reports | |
retention-days: 5 | |
if-no-files-found: ignore | |
test-complete: | |
needs: [testmo-report-preparation, cypress-run-selected] | |
if: | | |
always() && !contains(needs.*.result, 'skipped') && !contains(needs.*.result, 'cancelled') && github.event.pull_request.head.repo.fork == false | |
runs-on: ubuntu-22.04 | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version-file: ".nvmrc" | |
cache: npm | |
- name: Cache node modules | |
uses: actions/cache@v2 | |
env: | |
cache-name: cache-node-modules | |
with: | |
path: ~/.npm | |
key: ${{ runner.os }}-qa-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-qa-${{ env.cache-name }}- | |
${{ runner.os }}-qa- | |
${{ runner.os }}- | |
- name: Install Dependencies | |
if: steps.cache-node-modules.outputs.cache-hit != 'true' | |
run: NODE_OPTIONS=--max_old_space_size=4096 npm install | |
- run: npm ci | |
working-directory: .github/workflows | |
- name: complete testmo report | |
working-directory: .github/workflows | |
run: | | |
npx testmo automation:run:complete \ | |
--instance "$TESTMO_URL" \ | |
--run-id "$TESTMO_RUN_ID" | |
env: | |
TESTMO_URL: ${{ secrets.TESTMO_URL }} | |
TESTMO_TOKEN: ${{ secrets.TESTMO_TOKEN }} | |
TESTMO_RUN_ID: ${{ needs.testmo-report-preparation.outputs.testmo-run-id }} | |
- name: Download reports artifacts | |
uses: actions/download-artifact@v3 | |
with: | |
path: ./cypress/reports | |
- name: Create reports dir | |
continue-on-error: true | |
run: npm run qa:create-artifacts-dirs | |
- name: Merge report files | |
continue-on-error: true | |
run: npm run qa:generate-html-report | |
- name: Move artifacts screenshots into reports dir | |
continue-on-error: true | |
run: npm run qa:artifact-move-screenshots | |
- name: Upload reports | |
uses: actions/upload-artifact@v3 | |
if: always() | |
with: | |
name: combined-report | |
path: ./cypress/reports | |
retention-days: 5 | |
if-no-files-found: ignore |