Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E2E workflows #1843

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
name: CI
on: [pull_request]
on:
# - pull_request
- workflow_call

env:
NODE_VERSION: 18.19.0
Expand Down
76 changes: 76 additions & 0 deletions .github/workflows/create-preview-env.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
on:
workflow_call:
outputs:
service-url:
value: "${{ jobs.create-preview-env.outputs.service-url }}"
inputs:
env-name:
type: string
description: Environment name
required: true
branch-name:
type: string
description: Branch to use to create preview env
required: true
app-id:
type: string
description: App Name (likely the GH repo)
required: true
aws-region:
type: string
default: us-east-1
required: false

jobs:

create-preview-env:
timeout-minutes: 10
runs-on: ubuntu-latest
name: Create Preview Env
permissions:
id-token: write
contents: read
pull-requests: write
discussions: write
env:
ENV_NAME: ${{ inputs.env-name }}
AWS_REGION: us-east-1
steps:
- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::992382368072:role/cmiml-feature-oidc-github-role
role-session-name: gha-preview-env
aws-region: ${{ inputs.aws-region }}
- name: Create preview branch
run: |
BRANCHES=$(aws amplify list-branches --app-id ${{ inputs.app-id }} --query 'length(branches[?branchName==`${{ inputs.branch-name }}`])')
if [ $BRANCHES -eq 0 ]; then
aws amplify create-branch --app-id ${{ inputs.app-id }} --branch-name ${{ inputs.branch-name }} --display-name ${{ inputs.env-name }} --stage PULL_REQUEST --no-enable-auto-build
fi
sleep 20
- name: Deploy branch
id: deploy
run: |
JOB_ID=$(aws amplify start-job --app-id ${{ inputs.app-id }} --branch-name ${{ inputs.branch-name }} --job-type RELEASE --query 'jobSummary.jobId')
echo "job-id=$JOB_ID" >> "$GITHUB_OUTPUT"
- name: Wait for job
run: |
while true; do
JOB_STATUS=$(aws amplify get-job --app-id ${{ inputs.app-id }} --branch-name ${{ inputs.branch-name }} --job-id ${{ steps.deploy.outputs.job-id }} --query 'job.summary.status' --output text)
echo "Current job ${{ steps.deploy.outputs.job-id }} status: $JOB_STATUS"
case "$JOB_STATUS" in
"SUCCEED")
break
;;
"FAILED" | "CANCELLED")
exit 1
;;
*)
echo "Waiting..."
;;
esac
sleep 2
done
outputs:
service-url: https://${{ inputs.env-name }}.${{ inputs.app-id }}.amplifyapp.com
43 changes: 43 additions & 0 deletions .github/workflows/destroy-preview-env.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Destroy preview environment

on:
workflow_call:
inputs:
env-name:
type: string
description: Environment name (likely the pr number)
required: true
app-id:
type: string
description: Amplify App ID
required: true
aws-region:
type: string
default: us-east-1
required: false

jobs:
destroy-preview-env:
runs-on: ubuntu-latest
name: Destroy Preview Env
permissions:
id-token: write
contents: read
env:
AWS_REGION: us-east-1
steps:
- name: Configure aws credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::992382368072:role/cmiml-feature-oidc-github-role
role-session-name: gha-preview-env
aws-region: ${{ inputs.aws-region }}
- name: Destroy Preview env
run: |
ENV_COUNT=$(aws amplify list-branches --app-id ${{ inputs.app-id }} --query 'length(branches[?branchName==`${{ inputs.env-name }}`])')
if [ $ENV_COUNT -ne 0 ]; then
aws amplify delete-branch --app-id ${{ inputs.app-id }} --branch-name ${{ inputs.env-name }}
else
echo "Environment ${{ inputs.env-name }} does not exist"
exit 1
fi
133 changes: 133 additions & 0 deletions .github/workflows/e2e-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
name: E2E Tests

on:
workflow_call:
inputs:
service-url:
type: string
description: Service URL endpoint
required: true
e2e-tests-ref:
type: string
description: Git ref to checkout from TAF repo
required: false
default: dev
outputs:
report-url:
description: URL of the test report
value: ${{ jobs.publish-report.outputs.report-url }}

env:
AWS_REGION: us-east-1

jobs:
run-e2e-tests:
name: Run E2E Test Suite
runs-on: ubuntu-latest

permissions:
id-token: write
contents: read
pull-requests: write
discussions: write

steps:
- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::917902836630:role/cmiml-devops-oidc-github-role
role-session-name: OIDC-GHA-session
aws-region: ${{ env.AWS_REGION }}
- uses: actions/checkout@v4
name: Checkout
with:
repository: ChildMindInstitute/MindLogger-TAF
# Matching deploy key in TAF repo
ssh-key: ${{ secrets.TAF_PRIVATE_KEY }}
ref: ${{ inputs.e2e-tests-ref }}
- name: Install
run: npm install
- name: Setup Environment
run: |
sed -i 's/WEB_APP_BASE_URL.*//' .env ;
echo 'WEB_APP_BASE_URL=${{ inputs.service-url }}' >> .env
sed -i 's/API_DOMAIN.*//' .env ;
echo 'API_DOMAIN=https://api-dev.cmiml.net' >> .env
echo 'MAILINATOR_TOKEN=${{ secrets.MAILINATOR_TOKEN }}' >> .env
- name: Validate Environment
run: cat .env
- name: Get Secrets by Name and by ARN
uses: aws-actions/aws-secretsmanager-get-secrets@v2
with:
secret-ids: |
taf/dev
parse-json-secrets: true

- name: Run tests
run: npm run test:ui:regression
continue-on-error: true
id: e2e-tests

- name: Collect artifacts
uses: actions/upload-artifact@v4
with:
name: e2e-results
path: test-results/ui
if-no-files-found: error

- name: Fail if tests failed
if: steps.e2e-tests.outcome != 'success'
uses: actions/github-script@v7
with:
script: |
core.setFailed('E2E tests failed')

publish-report:
name: Publish Report
needs: [ run-e2e-tests ]
if: ${{ always() }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
name: Checkout
with:
ref: gh-pages
path: gh-pages

- name: Fetch results
uses: actions/download-artifact@v4
with:
name: e2e-results
path: test-results/ui
- name: Build test report
uses: simple-elf/allure-report-action@master
if: always()
with:
# Where allure will write the generated report
allure_report: e2e
# Results dir
allure_results: test-results/ui/allure/allure-results
# Path to folder to be published
allure_history: allure-history
# Path to folder where gh-pages was checked out
gh_pages: gh-pages
# a subfolder
subfolder: e2e
keep_reports: 20

- name: Deploy report to Github Pages
if: always()
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: allure-history

- name: Generate Report URL
if: always()
id: report-url
uses: actions/github-script@v7
with:
script: |
core.setOutput('report-url', 'https://childmindinstitute.github.io/mindlogger-web-refactor/e2e/${{ github.run_number }}')
outputs:
report-url: ${{ steps.report-url.outputs.report-url }}
53 changes: 53 additions & 0 deletions .github/workflows/pr-close.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Tear down preview environment for pull request

on:
pull_request:
types:
- closed

# Cancel any in progress since we are shutting down
concurrency:
cancel-in-progress: true
group: "preview-env-manage-${{ github.event.number }}"

env:
APP_NAME: ${{ github.event.repository.name }}
COPILOT_SERVICE: mindlogger-backend
AWS_REGION: us-east-1


jobs:
destroy-preview-env:
name: Destroy preview env
uses: ./.github/workflows/destroy-preview-env.yaml
with:
env-name: "pr-${{ github.event.number }}"
app-id: d2ojy049t6jawn

comment-destroy-preview-env:
name: Comment on preview env
runs-on: ubuntu-latest
needs: [ destroy-preview-env ]
if: ${{ always() }}
steps:
- name: Comment on PR
uses: thollander/actions-comment-pull-request@v2
with:
message: |
:arrow_right: Preview environment failed to be destroyed
comment_tag: preview-env
- name: "Send Slack message on failure"
uses: rtCamp/action-slack-notify@v2
if: ${{ always() && needs.destroy-preview-env.result == 'failure' }}
env:
SLACK_COLOR: failure
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_TEST_RESULTS }}
SLACK_TITLE: |
:rotating_light: Preview Environment Destroy Failed
SLACK_MESSAGE: >-
Failed to destroy preview environment pr-${{ github.event.number }} for ${{ github.repository }}
\n\n
:arrow_right: [Action Run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
\n\n
:label: [Pull Request](${{ github.event.pull_request.html_url || github.event.head_commit.url }})
MSG_MINIMAL: true
Loading
Loading