Skip to content

Commit

Permalink
Merge branch 'develop' into feat/events-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
makelicious committed Dec 16, 2024
2 parents 4ebb3f0 + f3e58e2 commit 08446a4
Show file tree
Hide file tree
Showing 101 changed files with 210,359 additions and 666 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module.exports = {
fhir: true
},
env: {
node: true
node: true,
jest: true
}
}
7 changes: 5 additions & 2 deletions .github/workflows/clear-environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
environment:
required: true
type: string
outputs:
outcome:
value: ${{ jobs.reset-data.outputs.outcome }}
workflow_dispatch:
inputs:
environment:
Expand All @@ -20,7 +23,7 @@ on:
jobs:
reset-data:
name: 'Reset data'
environment: ${{ github.event.inputs.environment }}
environment: ${{ inputs.environment }}
runs-on: ubuntu-22.04
outputs:
outcome: ${{ steps.reset-data.outcome }}
Expand All @@ -29,7 +32,7 @@ jobs:
- name: Clone country config resource package
uses: actions/checkout@v3
with:
fetch-depth: 0
fetch-depth: 1
path: './${{ github.event.repository.name }}'

- name: Read known hosts
Expand Down
196 changes: 196 additions & 0 deletions .github/workflows/deploy-and-e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
name: Deploy & run E2E
run-name: Deploy & E2E, triggered by ${{ github.event.client_payload.actor || github.actor }} to ${{ github.event.inputs.environment || 'development' }}
on:
repository_dispatch:
types: [run_e2e]
push:
branches:
- develop
workflow_dispatch:
inputs:
environment:
type: choice
description: Environment to deploy to
required: true
default: 'development'
options:
- development
core-image-tag:
description: Core DockerHub image tag
required: true
default: 'v1.4.1'
countryconfig-image-tag:
description: Your Country Config DockerHub image tag
required: true
default: 'v1.4.1'

concurrency:
group: ci-build
cancel-in-progress: false

jobs:
get-core-commit:
name: Resolve latest core tag
runs-on: ubuntu-latest
outputs:
latest_commit_sha: ${{ steps.get_latest_commit.outputs.commit_sha }}
steps:
- name: Checkout opencrvs-core repository
if: github.event_name == 'push' || github.event_name == 'repository_dispatch'
uses: actions/checkout@v3
with:
repository: 'opencrvs/opencrvs-core'
ref: 'develop'
- name: Get latest commit SHA
if: github.event_name == 'push' || github.event_name == 'repository_dispatch'
id: get_latest_commit
run: echo "::set-output name=commit_sha::$(git rev-parse HEAD | cut -c 1-7)"

get-country-config-commit:
name: Resolve latest Farajaland tag
runs-on: ubuntu-latest
needs: get-core-commit
outputs:
short_sha: ${{ steps.set_short_sha.outputs.short_sha }}
steps:
- name: Checkout code
uses: actions/checkout@v3
if: github.event_name == 'push' || github.event_name == 'repository_dispatch'
- name: Get short commit hash
id: set_short_sha
run: echo "::set-output name=short_sha::${GITHUB_SHA:0:7}"
if: github.event_name == 'push' || github.event_name == 'repository_dispatch'

deploy:
needs: [get-country-config-commit, get-core-commit]
uses: ./.github/workflows/deploy.yml
with:
environment: ${{ github.event.inputs.environment || 'development' }}
core-image-tag: ${{ github.event.inputs.core-image-tag || needs.get-core-commit.outputs.latest_commit_sha }}
countryconfig-image-tag: ${{ github.event.inputs.countryconfig-image-tag || needs.get-country-config-commit.outputs.short_sha }}
reset: 'true'
secrets: inherit

discover-tests:
name: Discover test directories
runs-on: ubuntu-22.04
outputs:
test_matrix: ${{ steps.list-tests.outputs.test_matrix }}
steps:
- name: Check out code
uses: actions/checkout@v4

- name: List Test Directories
id: list-tests
run: |
test_dirs=$(find ./e2e/testcases -mindepth 1 -maxdepth 1 -type d -exec basename {} \; | jq -R -s -c 'split("\n")[:-1]')
echo "Test directories: $test_dirs"
echo "test_matrix=$test_dirs" >> $GITHUB_OUTPUT
echo "test_matrix=$test_dirs"
test:
needs: [deploy, discover-tests, get-core-commit, get-country-config-commit]
runs-on: ubuntu-22.04
environment: ${{ github.event.inputs.environment || 'development' }}
strategy:
fail-fast: false
matrix:
test_dir: ${{ fromJson(needs.discover-tests.outputs.test_matrix) }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18

- name: Check for Spec Files
id: check-specs
run: |
if ls ./e2e/testcases/${{ matrix.test_dir }}/*.spec.ts > /dev/null 2>&1; then
echo "::set-output name=has_spec_files::true"
else
echo "::set-output name=has_spec_files::false"
fi
- name: Cache Node.js dependencies
uses: actions/cache@v4
with:
path: |
node_modules
~/.cache/yarn/v6
key: node-${{ hashFiles('**/yarn.lock', format('{0}/{1}',matrix.package,'package.json')) }}
restore-keys: |
${{ runner.os }}-node-
- name: Install Dependencies
if: steps.check-specs.outputs.has_spec_files == 'true'
run: yarn

- name: Install Playwright Browsers
if: steps.check-specs.outputs.has_spec_files == 'true'
run: npx playwright install --with-deps

- name: Run Playwright Tests
if: steps.check-specs.outputs.has_spec_files == 'true'
run: npx playwright test ./e2e/testcases/${{ matrix.test_dir }}
env:
DOMAIN: '${{ vars.DOMAIN }}'

- uses: actions/upload-artifact@v4
if: always() && steps.check-specs.outputs.has_spec_files == 'true'
with:
name: playwright-report-${{github.event.inputs.core-image-tag || needs.get-core-commit.outputs.latest_commit_sha}}-${{github.event.inputs.countryconfig-image-tag || needs.get-country-config-commit.outputs.short_sha}}-${{matrix.test_dir}}
path: playwright-report/
retention-days: 30

get-previous-run:
runs-on: ubuntu-latest
outputs:
previous_run_result: ${{ steps.set-output.outputs.result }}

steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Get Previous Run Conclusion
id: get-previous-conclusion
run: |
previous_conclusion=$(gh run list --limit 1 --status=completed --workflow="Deploy & run E2E" --json conclusion -q '.[0].conclusion')
echo "PREVIOUS_CONCLUSION=$previous_conclusion" >> $GITHUB_ENV
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}

- name: Set Output Based on Conclusion
id: set-output
run: |
echo "result=$PREVIOUS_CONCLUSION" >> $GITHUB_OUTPUT
notify-slack:
name: Notify Slack on Failure
runs-on: ubuntu-latest
needs: [deploy, discover-tests, test, get-previous-run]
if: failure()
steps:
- name: Send Slack notification
uses: slackapi/slack-github-action@v1.26.0
with:
channel-id: 'C02LU432JGK'
slack-message: "❌ E2E pipeline triggered by ${{ github.event.client_payload.actor || github.actor }}'s commit failed. Check the logs at https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}."
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}

notify-slack-success:
name: Notify Slack on success
runs-on: ubuntu-latest
needs: [deploy, discover-tests, test, get-previous-run]
if: success()
steps:
- name: Send Slack notification
if: needs.get-previous-run.outputs.previous_run_result == 'failure'
uses: slackapi/slack-github-action@v1.26.0
with:
channel-id: 'C02LU432JGK'
slack-message: "✅ E2E pipeline triggered by ${{ github.event.client_payload.actor || github.actor }}'s fixed the failing tests 🤩!. Check the logs at https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}."
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
4 changes: 2 additions & 2 deletions .github/workflows/deploy-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ on:
core-image-tag:
description: Core DockerHub image tag
required: true
default: 'v1.5.0'
default: 'v1.6.0'
countryconfig-image-tag:
description: Your Country Config DockerHub image tag
required: true
Expand All @@ -28,7 +28,7 @@ jobs:
- uses: trstringer/manual-approval@v1
with:
secret: ${{ github.TOKEN }}
approvers: euanmillar,rikukissa
approvers: euanmillar,rikukissa,alsmk
minimum-approvals: 1
issue-title: 'Deploy (${{ github.event.inputs.environment }}): core: ${{ github.event.inputs.core-image-tag }} country config: ${{ github.event.inputs.countryconfig-image-tag }}'
issue-body: 'Please approve or deny the deployment of core: ${{ github.event.inputs.core-image-tag }} country config: ${{ github.event.inputs.countryconfig-image-tag }} to ${{ github.event.inputs.environment }}'
Expand Down
61 changes: 43 additions & 18 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
name: Deploy (development)
run-name: Deploy to ${{ github.event.inputs.environment }} with reset=${{ github.event.inputs.reset }} core=${{ github.event.inputs.core-image-tag }} country config=${{ github.event.inputs.countryconfig-image-tag }}
run-name: Deploy to ${{ inputs.environment }} with reset=${{ inputs.reset }} core=${{ inputs.core-image-tag }} country config=${{ inputs.countryconfig-image-tag }}
on:
workflow_call:
inputs:
environment:
type: string
description: Environment to deploy to
required: true
core-image-tag:
type: string
description: Core DockerHub image tag
required: true
default: 'v1.4.1'
countryconfig-image-tag:
type: string
description: Your Country Config DockerHub image tag
required: true
reset:
type: string
description: Reset the environment
default: 'false'
required: false
debug:
type: boolean
description: Open SSH session to the runner after deployment
default: false
required: false
workflow_dispatch:
inputs:
environment:
Expand All @@ -15,7 +40,7 @@ on:
core-image-tag:
description: Core DockerHub image tag
required: true
default: 'v1.5.0'
default: 'v1.6.0'
countryconfig-image-tag:
description: Your Country Config DockerHub image tag
required: true
Expand All @@ -25,7 +50,7 @@ on:
default: false
jobs:
deploy:
environment: ${{ github.event.inputs.environment }}
environment: ${{ inputs.environment }}
runs-on: ubuntu-22.04
outputs:
outcome: ${{ steps.deploy.outcome }}
Expand All @@ -46,13 +71,13 @@ jobs:
- name: Checkout country branch
run: |
cd ${{ github.event.repository.name }}
git checkout ${{ github.event.inputs.countryconfig-image-tag }}
git checkout ${{ inputs.countryconfig-image-tag }}
cd ../
- name: Checkout core branch
run: |
cd opencrvs-core
git checkout ${{ github.event.inputs.core-image-tag }}
git checkout ${{ inputs.core-image-tag }}
- name: Read known hosts
run: |
Expand Down Expand Up @@ -81,13 +106,13 @@ jobs:
- name: Wait for images to be available
run: |
while true; do
if docker manifest inspect opencrvs/ocrvs-auth:${{ github.event.inputs.core-image-tag }}; then
if docker manifest inspect opencrvs/ocrvs-auth:${{ inputs.core-image-tag }}; then
break
fi
sleep 10
done
while true; do
if docker manifest inspect ${{ secrets.DOCKERHUB_ACCOUNT }}/${{ secrets.DOCKERHUB_REPO }}:${{ github.event.inputs.countryconfig-image-tag }}; then
if docker manifest inspect ${{ secrets.DOCKERHUB_ACCOUNT }}/${{ secrets.DOCKERHUB_REPO }}:${{ inputs.countryconfig-image-tag }}; then
break
fi
sleep 10
Expand All @@ -106,7 +131,7 @@ jobs:
# This includes SSH_KEY and KNOWN_HOSTS
#
while IFS= read -r secret; do
echo "$secret" >> .env.${{ github.event.inputs.environment }}
echo "$secret" >> .env.${{ inputs.environment }}
done < <(
jq -r '
to_entries |
Expand All @@ -122,7 +147,7 @@ jobs:
EOF)
while IFS= read -r var; do
echo "$var" >> .env.${{ github.event.inputs.environment }}
echo "$var" >> .env.${{ inputs.environment }}
done < <(
jq -r '
to_entries |
Expand All @@ -133,34 +158,34 @@ jobs:
.[]' <<< "$VARS_JSON_WITH_NEWLINES"
)
- name: Deploy to ${{ github.event.inputs.environment }}
- name: Deploy to ${{ inputs.environment }}
id: deploy
run: |
cd ./${{ github.event.repository.name }}
yarn deploy \
--clear_data=no \
--environment=${{ github.event.inputs.environment }} \
--environment=${{ inputs.environment }} \
--host=${{ vars.DOMAIN }} \
--ssh_host=${{ vars.SSH_HOST || secrets.SSH_HOST }} \
--ssh_port=${{ vars.SSH_PORT || secrets.SSH_PORT }} \
--ssh_user=${{ secrets.SSH_USER }} \
--version=${{ github.event.inputs.core-image-tag }} \
--country_config_version=${{ github.event.inputs.countryconfig-image-tag }} \
--version=${{ inputs.core-image-tag }} \
--country_config_version=${{ inputs.countryconfig-image-tag }} \
--replicas=${{ vars.REPLICAS }}
reset:
needs: deploy
if: ${{ github.event.inputs.reset == 'true' && needs.deploy.outputs.outcome == 'success' }}
if: ${{ inputs.reset == 'true' && needs.deploy.outputs.outcome == 'success' }}
uses: ./.github/workflows/clear-environment.yml
with:
environment: ${{ github.event.inputs.environment }}
environment: ${{ inputs.environment }}
secrets: inherit

seed-data:
needs: reset
if: ${{ github.event.inputs.reset == 'true' && needs.reset.outputs.outcome == 'success' }}
if: ${{ inputs.reset == 'true' && needs.reset.outputs.outcome == 'success' }}
uses: ./.github/workflows/seed-data.yml
with:
environment: ${{ github.event.inputs.environment }}
core-image-tag: ${{ github.event.inputs.core-image-tag }}
environment: ${{ inputs.environment }}
core-image-tag: ${{ inputs.core-image-tag }}
secrets: inherit
Loading

0 comments on commit 08446a4

Please sign in to comment.