Add gh token secret #3
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: e2e tests | ||
on: | ||
workflow_call: | ||
inputs: | ||
node_version: | ||
description: "Node.js version" | ||
default: "18.18.2" | ||
required: false | ||
type: string | ||
e2e-timeout: | ||
description: "Timeout in minutes" | ||
default: 20 | ||
required: false | ||
type: number | ||
retries: | ||
description: "Number of retries" | ||
default: 2 | ||
required: false | ||
type: number | ||
registry_id: | ||
description: "YC registry ID" | ||
default: "crpo9tj76o3c7pi8i72n" | ||
required: false | ||
type: string | ||
image_name: | ||
description: "e2e image name" | ||
default: "dev_new_frontend" | ||
required: false | ||
type: string | ||
core_project: | ||
description: "True if project is frontend_core_v2" | ||
default: false | ||
required: false | ||
type: boolean | ||
target_port: | ||
type: number | ||
description: "The port for k8 services" | ||
required: false | ||
default: 8080 | ||
cypress_dashboard_enabled: | ||
description: "Cypress dashboard enabled" | ||
default: false | ||
required: false | ||
type: boolean | ||
secrets: | ||
github_token: | ||
description: "A GITHUB_TOKEN token passed from the caller workflow" | ||
required: true | ||
npm_token: | ||
description: "A GH_NPM_REGISTRY token passed from the caller workflow" | ||
required: true | ||
frontend_gha_full_token: | ||
description: "A FRONTEND_GHA_FULL_TOKEN token passed from the caller workflow" | ||
required: true | ||
container_registry_key: | ||
description: "A CONTAINER_REGISTRY_KEY token passed from the caller workflow" | ||
required: true | ||
cypress_login: | ||
description: "A CYPRESS_LOGIN token passed from the caller workflow" | ||
required: true | ||
cypress_pass: | ||
description: "A CYPRESS_PASSWORD token passed from the caller workflow" | ||
required: true | ||
cypress_record_key: | ||
description: "A CYPRESS_RECORD_KEY passed from the caller workflow (dashboard key)" | ||
required: false | ||
kube_dev_config_k8: | ||
description: "A SA_TOKEN_DTLN_KUBE_CDP_STAGING_MICROFRONTENDS token passed from the caller workflow for new deploy" | ||
required: false | ||
kube_token: | ||
description: "A SA_TOKEN_RU_STAGING_YC_KUBE_CDP_MIXED1_MICROFRONTENDS token passed from the caller workflow for deploy" | ||
required: true | ||
env: | ||
NODE_OPTIONS: --unhandled-rejections=strict | ||
jobs: | ||
prepare-site: | ||
timeout-minutes: 20 | ||
runs-on: ubuntu-latest | ||
env: | ||
retries: ${{ inputs.retries }} | ||
CYPRESS_username: "${{ secrets.cypress_login }}" | ||
CYPRESS_password: "${{ secrets.cypress_pass }}" | ||
registry: cr.yandex/${{ inputs.registry_id }} | ||
image: ${{ inputs.image_name }} | ||
steps: | ||
- name: Checkout the repository | ||
uses: actions/checkout@v3 | ||
- name: Change Dockerd param | ||
run: | | ||
sudo sed -i 's/ }/, \"max-concurrent-uploads\": 2 }/' /etc/docker/daemon.json | ||
sudo systemctl restart docker | ||
- name: Set variables | ||
run: | | ||
echo "ref_name=$(echo $GITHUB_HEAD_REF | tr '[A-Z]' '[a-z]')" >> $GITHUB_ENV | ||
echo "repository_name=$(cat $GITHUB_EVENT_PATH | jq '.repository.name' | sed 's/\"//g')" >> $GITHUB_ENV | ||
id: set_variables | ||
- name: Get branch and repo names hash | ||
run: echo "hash_payload=$(echo $BRANCH_AND_REPO | md5sum | sed 's/ -//g')" >> $GITHUB_ENV | ||
id: branch_and_repo_hash | ||
env: | ||
BRANCH_AND_REPO: "${{ env.repository_name }} ${{ env.ref_name }}" | ||
- name: Set project path | ||
run: | | ||
project_name=$(cat ./package.json | jq .name | sed -s 's/@mindbox-cloud\///g' | sed -s 's/-/_/g' | sed -s 's/"//g') | ||
if [[ $project_name == "frontend_core_v2" ]]; then | ||
echo "project_folder=core" >> $GITHUB_ENV | ||
echo "project_name=core" >> $GITHUB_ENV | ||
echo "frontend_core_service=e2e-testing-${{ env.hash_payload }}" >> $GITHUB_ENV | ||
else | ||
echo "project_folder=$project_name" >> $GITHUB_ENV | ||
echo "project_name=$project_name" >> $GITHUB_ENV | ||
echo "frontend_core_service=core-service-standard" >> $GITHUB_ENV | ||
fi | ||
id: set_project | ||
- name: Checkout frontend-deploy repository | ||
uses: actions/checkout@v3 | ||
with: | ||
repository: mindbox-cloud/frontend-deploy | ||
token: ${{ secrets.frontend_gha_full_token }} | ||
path: ./deploy | ||
- name: Select core deploy.yml | ||
if: ${{ env.repository_name == 'frontend-core-v2' }} | ||
run: mv ./deploy/e2e/kubernetes/deploy-k8-core.yml ./deploy/e2e/kubernetes/deploy-k8.yml | ||
- name: Select micro deploy.yml | ||
if: ${{ env.repository_name != 'frontend-core-v2' }} | ||
run: mv ./deploy/e2e/kubernetes/deploy-k8-micro.yml ./deploy/e2e/kubernetes/deploy-k8.yml | ||
- name: Set variables in deployment.yaml | ||
working-directory: ./deploy/e2e/kubernetes | ||
run: | | ||
sed -i "s~DOCKER_IMAGE~$DOCKER_IMAGE~g" ./deploy-k8.yml | ||
sed -i "s~HASH_PAYLOAD~$HASH_PAYLOAD~g" ./deploy-k8.yml | ||
sed -i "s~CI_COMMIT_SHA~$CI_COMMIT_SHA~g" ./deploy-k8.yml | ||
sed -i "s~BASE_PROJECT_URL~$BASE_PROJECT_URL~g" ./deploy-k8.yml | ||
sed -i "s~PROJECT_FOLDER~$PROJECT_FOLDER~g" ./deploy-k8.yml | ||
sed -i "s~TARGET_PORT~$TARGET_PORT~g" ./deploy-k8.yml | ||
sed -i "s~FRONTEND_CORE_SERVICE_NAME~$FRONTEND_CORE_SERVICE_NAME~g" ./deploy-k8.yml | ||
env: | ||
DOCKER_IMAGE: ${{ env.registry }}/${{ env.image }}-k8/${{ env.ref_name }}:${{ github.sha }} | ||
HASH_PAYLOAD: ${{ env.hash_payload }} | ||
CI_COMMIT_SHA: ${{ github.sha }} | ||
BASE_PROJECT_URL: standard.mindbox.ru | ||
PROJECT_FOLDER: ${{ env.project_folder }} | ||
TARGET_PORT: ${{ inputs.target_port }} | ||
FRONTEND_CORE_SERVICE_NAME: ${{ env.frontend_core_service }} | ||
- name: Setup kubeconfig.yaml | ||
working-directory: ./deploy/testing-common | ||
run: | | ||
sed -i "s~TOKEN~$TOKEN~g" ./kubeconfig.yaml | ||
kubeconfig_encoded=$(base64 -w 0 ./kubeconfig.yaml) | ||
echo "KUBECONFIG_ENCODED=$kubeconfig_encoded" >> $GITHUB_ENV | ||
shell: bash | ||
env: | ||
TOKEN: ${{ secrets.kube_token }} | ||
- name: Deploy to cluster | ||
uses: actions-hub/[email protected] | ||
env: | ||
KUBE_CONFIG: ${{ env.KUBECONFIG_ENCODED }} | ||
with: | ||
args: apply -f ./deploy/e2e/kubernetes/deploy-k8.yml | ||
- name: Check dns record creation | ||
id: check_dns | ||
uses: nick-fields/retry@v3 | ||
with: | ||
timeout_seconds: 15 | ||
shell: bash | ||
max_attempts: 90 | ||
retry_wait_seconds: 10 | ||
command: | | ||
dig @8.8.8.8 -t cname +short e2e-testing-${{ env.hash_payload }}-staging.mindbox.ru. | grep -q "ru-staging-yc-kube-cdp-mixed1-services.mindbox.ru." || \ | ||
exit 1 | ||
continue-on-error: true | ||
- name: Fail with error message | ||
if: ${{ steps.check_dns.outcome == 'failure' }} | ||
run: | | ||
echo "The DNS CNAME record for 'e2e-testing-${{ env.hash_payload }}-staging.mindbox.ru' was not created as expected." | ||
exit 1 | ||
e2e-tests: | ||
runs-on: [self-hosted, frontend] | ||
container: | ||
image: cr.yandex/crpo9tj76o3c7pi8i72n/cached/browsers:node-18.16.1-chrome-114.0.5735.133-1-ff-114.0.2-edge-114.0.1823.51-1 | ||
credentials: | ||
username: json_key | ||
password: ${{ secrets.CONTAINER_REGISTRY_KEY }} | ||
volumes: | ||
- /runner/.cache/Cypress:/root/.cache/Cypress | ||
needs: prepare-site | ||
timeout-minutes: ${{ inputs.e2e-timeout }} | ||
if: ${{ always() && !cancelled() && !inputs.core_project }} | ||
env: | ||
retries: ${{ inputs.retries }} | ||
CYPRESS_username: "${{ secrets.cypress_login }}" | ||
CYPRESS_password: "${{ secrets.cypress_pass }}" | ||
registry: cr.yandex/${{ inputs.registry_id }} | ||
image: ${{ inputs.image_name }} | ||
steps: | ||
- uses: technote-space/workflow-conclusion-action@v3 | ||
- name: check fail | ||
if: env.WORKFLOW_CONCLUSION == 'failure' | ||
run: echo "previous steps are failed" && exit 1 | ||
- name: downgrade npm | ||
run: npm -g install npm@9 | ||
- name: install additional tools | ||
run: apt-get update && apt-get -y install jq | ||
- name: Checkout the repository | ||
uses: actions/checkout@v3 | ||
- name: Set variables | ||
run: | | ||
echo "ref_name=$(echo $GITHUB_HEAD_REF | tr '[A-Z]' '[a-z]')" >> $GITHUB_ENV | ||
echo "repository_name=$(cat $GITHUB_EVENT_PATH | jq '.repository.name' | sed 's/\"//g')" >> $GITHUB_ENV | ||
id: set_variables | ||
- name: Get branch and repo names hash | ||
run: echo "hash_payload=$(echo $BRANCH_AND_REPO | md5sum | sed 's/ -//g')" >> $GITHUB_ENV | ||
id: branch_and_repo_hash | ||
env: | ||
BRANCH_AND_REPO: "${{ env.repository_name }} ${{ env.ref_name }}" | ||
- name: Set project path | ||
run: | | ||
project_name=$(cat ./package.json | jq .name | sed -s 's/@mindbox-cloud\///g' | sed -s 's/-/_/g' | sed -s 's/"//g') | ||
if [[ $project_name == "frontend_core_v2" ]]; then | ||
echo "project_folder=core" >> $GITHUB_ENV | ||
echo "project_name=core" >> $GITHUB_ENV | ||
else | ||
echo "project_folder=$project_name" >> $GITHUB_ENV | ||
echo "project_name=$project_name" >> $GITHUB_ENV | ||
fi | ||
id: set_project | ||
- name: Setup Node.JS | ||
uses: actions/setup-node@v3 | ||
with: | ||
always-auth: true | ||
node-version: ${{ inputs.node_version }} | ||
registry-url: "https://npm.pkg.github.com/mindbox-cloud" | ||
- name: Run E2E tests on not core project | ||
uses: cypress-io/github-action@v5 | ||
if: ${{ !inputs.cypress_dashboard_enabled }} | ||
with: | ||
install: true | ||
config: baseUrl=https://e2e-testing-${{ env.hash_payload }}-staging.mindbox.ru,retries=${{ env.retries }},videoUploadOnPasses=false,videoCompression=false | ||
working-directory: e2e | ||
browser: chrome | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.npm_token }} | ||
GITHUB_TOKEN: ${{ secrets.github_token }} | ||
NPM_TOKEN: ${{ secrets.npm_token }} | ||
- name: Run E2E tests on not core project with dashboard | ||
uses: cypress-io/github-action@v5 | ||
if: ${{ inputs.cypress_dashboard_enabled }} | ||
with: | ||
install: true | ||
config: baseUrl=https://e2e-testing-${{ env.hash_payload }}-staging.mindbox.ru,retries=${{ env.retries }},videoUploadOnPasses=false,videoCompression=false | ||
working-directory: e2e | ||
browser: chrome | ||
record: true | ||
parallel: false | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.npm_token }} | ||
GITHUB_TOKEN: ${{ secrets.github_token }} | ||
NPM_TOKEN: ${{ secrets.npm_token }} | ||
CYPRESS_RECORD_KEY: ${{ secrets.cypress_record_key }} | ||
- name: Upload test results artifacts | ||
uses: actions/upload-artifact@v4 | ||
if: failure() | ||
with: | ||
name: cypress-${{ env.project_name }} | ||
path: e2e/cypress | ||
retention-days: 1 | ||
core-e2e-tests-matrix: | ||
runs-on: ubuntu-latest | ||
needs: prepare-site | ||
if: ${{ inputs.core_project }} | ||
env: | ||
retries: ${{ inputs.retries }} | ||
CYPRESS_username: "${{ secrets.cypress_login }}" | ||
CYPRESS_password: "${{ secrets.cypress_pass }}" | ||
registry: cr.yandex/${{ inputs.registry_id }} | ||
image: ${{ inputs.image_name }} | ||
outputs: | ||
matrix: ${{ steps.set-matrix.outputs.matrix }} | ||
steps: | ||
- name: Checkout the repository | ||
uses: actions/checkout@v3 | ||
- name: Set variables | ||
run: | | ||
echo "ref_name=$(echo $GITHUB_HEAD_REF | tr '[A-Z]' '[a-z]')" >> $GITHUB_ENV | ||
echo "repository_name=$(cat $GITHUB_EVENT_PATH | jq '.repository.name' | sed 's/\"//g')" >> $GITHUB_ENV | ||
id: set_variables | ||
- name: Get branch and repo names hash | ||
run: echo "hash_payload=$(echo $BRANCH_AND_REPO | md5sum | sed 's/ -//g')" >> $GITHUB_ENV | ||
id: branch_and_repo_hash | ||
env: | ||
BRANCH_AND_REPO: "${{ env.repository_name }} ${{ env.ref_name }}" | ||
- name: Set project path | ||
run: | | ||
project_name=$(cat ./package.json | jq .name | sed -s 's/@mindbox-cloud\///g' | sed -s 's/-/_/g' | sed -s 's/"//g') | ||
if [[ $project_name == "frontend_core_v2" ]]; then | ||
echo "project_folder=core" >> $GITHUB_ENV | ||
echo "project_name=core" >> $GITHUB_ENV | ||
else | ||
echo "project_folder=$project_name" >> $GITHUB_ENV | ||
echo "project_name=$project_name" >> $GITHUB_ENV | ||
fi | ||
id: set_project | ||
- name: Setup Node.JS | ||
uses: actions/setup-node@v3 | ||
with: | ||
always-auth: true | ||
node-version: ${{ inputs.node_version }} | ||
registry-url: "https://npm.pkg.github.com/mindbox-cloud" | ||
- name: Install YC | ||
run: | | ||
sudo curl https://storage.yandexcloud.net/yandexcloud-yc/install.sh | bash | ||
sudo ln -s /home/runner/yandex-cloud/bin/yc /bin/yc | ||
core-e2e-tests-runner: | ||
runs-on: [self-hosted, frontend] | ||
needs: core-e2e-tests-matrix | ||
strategy: | ||
matrix: | ||
project: | ||
- customers | ||
- newmailings | ||
- scenarios | ||
- personalization | ||
- campaigns | ||
- retail | ||
- auth-page | ||
max-parallel: 4 | ||
timeout-minutes: ${{ inputs.e2e-timeout }} | ||
if: ${{ always() && !cancelled() && inputs.core_project }} | ||
env: | ||
retries: ${{ inputs.retries }} | ||
CYPRESS_username: "${{ secrets.cypress_login }}" | ||
CYPRESS_password: "${{ secrets.cypress_pass }}" | ||
registry: cr.yandex/${{ inputs.registry_id }} | ||
image: ${{ inputs.image_name }} | ||
steps: | ||
- uses: technote-space/workflow-conclusion-action@v3 | ||
- name: check fail | ||
if: env.WORKFLOW_CONCLUSION == 'failure' | ||
run: echo "previous steps are failed" && exit 1 | ||
- name: Checkout the repository | ||
uses: actions/checkout@v3 | ||
- name: Set variables | ||
run: | | ||
echo "ref_name=$(echo $GITHUB_HEAD_REF | tr '[A-Z]' '[a-z]')" >> $GITHUB_ENV | ||
echo "repository_name=$(cat $GITHUB_EVENT_PATH | jq '.repository.name' | sed 's/\"//g')" >> $GITHUB_ENV | ||
id: set_variables | ||
- name: Get branch and repo names hash | ||
run: echo "hash_payload=$(echo $BRANCH_AND_REPO | md5sum | sed 's/ -//g')" >> $GITHUB_ENV | ||
id: branch_and_repo_hash | ||
env: | ||
BRANCH_AND_REPO: "${{ env.repository_name }} ${{ env.ref_name }}" | ||
- name: Set project path | ||
run: | | ||
project_name=$(cat ./package.json | jq .name | sed -s 's/@mindbox-cloud\///g' | sed -s 's/-/_/g' | sed -s 's/"//g') | ||
if [[ $project_name == "frontend_core_v2" ]]; then | ||
echo "project_folder=core" >> $GITHUB_ENV | ||
echo "project_name=core" >> $GITHUB_ENV | ||
else | ||
echo "project_folder=$project_name" >> $GITHUB_ENV | ||
echo "project_name=$project_name" >> $GITHUB_ENV | ||
fi | ||
id: set_project | ||
- name: Setup Node.JS | ||
uses: actions/setup-node@v3 | ||
with: | ||
always-auth: true | ||
node-version: ${{ inputs.node_version }} | ||
registry-url: "https://npm.pkg.github.com/mindbox-cloud" | ||
- name: Authenticate in yandex registry | ||
run: echo '${{ secrets.container_registry_key }}' | docker login -u json_key --password-stdin cr.yandex | ||
- name: Pull docker image to registry with retry | ||
uses: nick-fields/retry@v2 | ||
with: | ||
timeout_seconds: 300 | ||
retry_wait_seconds: 30 | ||
max_attempts: 5 | ||
shell: bash | ||
command: docker pull cr.yandex/${{ inputs.registry_id }}/frontend-e2e:${{ matrix.project }}-latest 2>&1 | ||
- name: Run E2E tests on core project. | ||
run: | | ||
[ -d ./cypress/${{ matrix.project }} ] && mkdir -p ./cypress/${{ matrix.project }} | ||
mkdir -p ./cypress/${{ matrix.project }}/videos && mkdir -p ./cypress/${{ matrix.project }}/screenshots | ||
docker run -i \ | ||
-e BASE_URL="${{ env.E2E_URL }}" \ | ||
-e RETRIES="${{ env.retries }}" \ | ||
-e CYPRESS_username=${{ secrets.cypress_login }} \ | ||
-e CYPRESS_password=${{ secrets.cypress_pass }} \ | ||
-e CYPRESS_grepTags="@smoke" \ | ||
-e CYPRESS_grepOmitFiltered=true \ | ||
-v $(pwd)/cypress/${{ matrix.project }}/videos:/e2e/cypress/videos \ | ||
-v $(pwd)/cypress/${{ matrix.project }}/screenshots:/e2e/cypress/screenshots \ | ||
cr.yandex/${{ inputs.registry_id }}/frontend-e2e:${{ matrix.project }}-latest 2>&1 | ||
env: | ||
E2E_URL: https://e2e-testing-${{ env.hash_payload }}-staging.mindbox.ru | ||
- name: Upload test results artifacts | ||
uses: actions/upload-artifact@v4 | ||
if: ${{ failure() }} | ||
with: | ||
name: cypress-${{ matrix.project }} | ||
path: e2e/cypress | ||
retention-days: 1 | ||
post-e2e-tests: | ||
runs-on: ubuntu-latest | ||
needs: [e2e-tests, core-e2e-tests-runner] | ||
if: ${{ failure() }} | ||
steps: | ||
- name: Add comment to commit if the job has failed | ||
if: ${{ failure() }} | ||
uses: mshick/add-pr-comment@v2 | ||
with: | ||
message: ":negative_squared_cross_mark: E2E tests failed. Check logs at\nhttps://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" | ||
repo-token: ${{ secrets.github_token }} | ||
clean-up-e2e-tests: | ||
needs: [e2e-tests, core-e2e-tests-runner] | ||
if: ${{ always() && ( needs.e2e-tests.result == 'success' || needs.core-e2e-tests-runner.result == 'success' ) }} | ||
uses: mindbox-cloud/github-actions/.github/workflows/frontend_cleanup_testing.yml@master | ||
with: | ||
hot_testing: false | ||
hot_testing_k8: false | ||
e2e_testing: true | ||
e2e_testing_k8: true | ||
secrets: | ||
frontend_gha_full_token: ${{ secrets.frontend_gha_full_token }} | ||
container_registry_key: ${{ secrets.container_registry_key }} | ||
kube_dev_config_k8: ${{ secrets.kube_dev_config_k8 }} | ||
kube_token: ${{ secrets.kube_token }} |