Skip to content

Commit

Permalink
BC-5468 refactor automatic trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
UzaeirKhan committed Nov 24, 2023
1 parent 00a296b commit 0523578
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 52 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/automatic-trigger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ on: [push]
jobs:
e2e-system-tests:
runs-on: ubuntu-latest
outputs:
cypress_brb: ${{steps.set_variables.outputs.cypress_brb}}
cypress_dbc: ${{steps.set_variables.outputs.cypress_dbc}}
cypress_nbc: ${{steps.set_variables.outputs.cypress_nbc}}
tag: ${{steps.set_variables.outputs.tag}}
environment: ${{steps.set_variables.outputs.environment}}

steps:
- name: Setup Node
Expand All @@ -14,8 +20,35 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Install 1Password CLI
uses: 1password/install-cli-action@v1

- name: Verify 1Password was Installed
run: op --version

- name: Configure 1Password Service Account
uses: 1password/load-secrets-action/configure@v1
with:
service-account-token: ${{ secrets.CYPRESS_ONEPWD_SERVICE_ACCOUNT_TOKEN }}

- name: Set all parameters for next job
id: set_variables
shell: bash
run: |
echo "cypress_brb=$(op document get cypress-json --vault cy-dev-brb | jq -r '.BRB')" >> $GITHUB_OUTPUT
echo "cypress_dbc=$(op document get cypress-json --vault cy-dev-dbc | jq -r '.DEFAULT')" >> $GITHUB_OUTPUT
echo "cypress_nbc=$(op document get cypress-json --vault cy-dev-nbc | jq -r '.NBC')" >> $GITHUB_OUTPUT
echo "tag=tag:stable:ci" >> GITHUB_OUTPUT
echo "environment=dev" >> GITHUB_OUTPUT
configuring-loading-secrets-running-tests:
needs: e2e-system-tests
uses: ./.github/workflows/main.yml
secrets:
service-account-token: ${{ secrets.CYPRESS_ONEPWD_SERVICE_ACCOUNT_TOKEN }}
with:
cypress_brb: ${{needs.e2e-system-tests.outputs.cypress_brb}}
cypress_default: ${{needs.e2e-system-tests.outputs.cypress_dbc}}
cypress_nbc: ${{needs.e2e-system-tests.outputs.cypress_nbc}}
tag: ${{needs.e2e-system-tests.outputs.tag}}
environment: ${{needs.e2e-system-tests.outputs.environment}}
51 changes: 29 additions & 22 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ on:
cypress_default:
description: "default url from remote workflow"
type: string
tag:
description: "tag for running cypress tests"
type: string
environment:
description: "environment for retriving credentials from 1Password vault"
type: string

jobs:
configure-load-secrets-and-run_tests:
Expand Down Expand Up @@ -45,10 +51,10 @@ jobs:
environments=(dev ref)
for instance in "${instances[@]}"; do
for environment in "${environments[@]}"; do
vault_name="cy-${environment}-${instance}"
op document get cypress-json --vault "$vault_name" --output ${{ github.workspace }}/e2e-system-tests/env_variables/file-${environment}-${instance}.json
done
# for environment in "${environments[@]}"; do
vault_name="cy-${{inputs.environment}}-${instance}"
op document get cypress-json --vault "$vault_name" --output ${{ github.workspace }}/e2e-system-tests/env_variables/file-${{inputs.environment}}-${instance}.json
# done
done
- name: Aggregate JSON Data into one File
Expand All @@ -57,27 +63,28 @@ jobs:
workflow=${{ github.workflow }}
workspace_path=${{ github.workspace }}
if [[ $workflow == *"manual"* ]]; then
brb_instance=${{ github.event.inputs.instance1 }}
dbc_instance=${{ github.event.inputs.instance2 }}
nbc_instance=${{ github.event.inputs.instance3 }}
elif [[ $workflow == *"automatic"* || $workflow == *"scheduled"* ]]; then
brb_instance=""
dbc_instance=""
nbc_instance=""
else
brb_instance=${{ inputs.cypress_brb }}
dbc_instance=${{ inputs.cypress_default }}
nbc_instance=${{ inputs.cypress_nbc }}
fi
# if [[ $workflow == *"manual"* ]]; then
# brb_instance=${{ github.event.inputs.instance1 }}
# dbc_instance=${{ github.event.inputs.instance2 }}
# nbc_instance=${{ github.event.inputs.instance3 }}
# elif [[ $workflow == *"automatic"* || $workflow == *"scheduled"* ]]; then
# brb_instance=""
# dbc_instance=""
# nbc_instance=""
# else
# brb_instance=${{ inputs.cypress_brb }}
# dbc_instance=${{ inputs.cypress_default }}
# nbc_instance=${{ inputs.cypress_nbc }}
# fi
chmod +x ${{ github.workspace }}/e2e-system-tests/scripts/aggregate-json-files.sh
${{ github.workspace }}/e2e-system-tests/scripts/aggregate-json-files.sh \
"${workflow}" \
"${brb_instance}" \
"${dbc_instance}" \
"${nbc_instance}" \
"${workspace_path}"
"${{inputs.cypress_brb}}" \
"${{inputs.cypress_default}}" \
"${{inputs.cypress_nbc}}" \
"${workspace_path}" \
"${{inputs.environment}}"
- name: Clean up previous report
uses: cypress-io/github-action@v5
Expand All @@ -89,7 +96,7 @@ jobs:
uses: cypress-io/github-action@v5
with:
working-directory: e2e-system-tests
command: npm run ${{ steps.read_variables.outputs.tag }}
command: npm run ${{ inputs.tag }}
browser: chrome

- name: Generate Report
Expand Down
60 changes: 30 additions & 30 deletions scripts/aggregate-json-files.sh
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
#!/bin/bash

instances=(brb dbc nbc)
environments=(dev ref)

workflow_name=$1
brb_instance=$2
dbc_instance=$3
nbc_instance=$4
workspace_path=$5
environment=$6

check_environment() {
local url="$1"
# check_environment() {
# local url="$1"

if [[ $url == *"staging"* || $url == *"schulportal"* ]]; then
echo "ref"
else
echo "dev"
fi
}
# if [[ $url == *"staging"* || $url == *"schulportal"* ]]; then
# echo "ref"
# else
# echo "dev"
# fi
# }

if [[ $workflow_name == *"manual"* ]]; then
echo "This is a manual workflow"
echo "TAG=tag:stable:ci" >>$GITHUB_OUTPUT
echo "$TAG"
elif [[ $workflow_name == *"automatic"* || $workflow_name == *"scheduled"* ]]; then
echo "This is an automatic or scheduled workflow"
echo "TAG=tag:stable:ci" >>$GITHUB_OUTPUT
echo "$TAG"
else
echo "This is a remote workflow"
echo "TAG=tag:stable:pr:ci" >>$GITHUB_OUTPUT
echo "$TAG"
fi
# if [[ $workflow_name == *"manual"* ]]; then
# echo "This is a manual workflow"
# echo "TAG=tag:stable:ci" >>$GITHUB_OUTPUT
# echo "$TAG"
# elif [[ $workflow_name == *"automatic"* || $workflow_name == *"scheduled"* ]]; then
# echo "This is an automatic or scheduled workflow"
# echo "TAG=tag:stable:ci" >>$GITHUB_OUTPUT
# echo "$TAG"
# else
# echo "This is a remote workflow"
# echo "TAG=tag:stable:pr:ci" >>$GITHUB_OUTPUT
# echo "$TAG"
# fi

brb_env=$(check_environment "$brb_instance")
dbc_env=$(check_environment "$dbc_instance")
nbc_env=$(check_environment "$nbc_instance")
# brb_env=$(check_environment "$brb_instance")
# dbc_env=$(check_environment "$dbc_instance")
# nbc_env=$(check_environment "$nbc_instance")

if [[ $brb_env == "ref" || $dbc_env == "ref" || $nbc_env == "ref" ]]; then
environment="ref"
else
environment="dev"
fi
# if [[ $brb_env == "ref" || $dbc_env == "ref" || $nbc_env == "ref" ]]; then
# environment="ref"
# else
# environment="dev"
# fi

file_paths=()
declare -A key_value_pairs
Expand Down

0 comments on commit 0523578

Please sign in to comment.