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

Refactor GHA pipelines and add the E2E test suite #75

Merged
merged 9 commits into from
Feb 12, 2025
Merged
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
37 changes: 31 additions & 6 deletions .github/workflows/deploy_to_env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ on:
- dev
- test
default: 'dev'
version:
description: version to be deployed to the environment - must already exist.
required: true
image_tag:
description: Optional image tag to deploy. If left blank, a new image will be built, pushed and deployed
required: false
default: ''
type: string

Expand All @@ -23,16 +23,41 @@ permissions:
jobs:
helm_lint:
name: helm lint
uses: ministryofjustice/hmpps-github-actions/.github/workflows/test_helm_lint.yml@v2 # WORKFLOW_VERSION
uses: ministryofjustice/hmpps-github-actions/.github/workflows/test_helm_lint.yml@v2
secrets: inherit
with:
environment: ${{ inputs.environment }}

build_docker:
if: ${{ inputs.image_tag == '' }}
name: Build docker image
uses: ministryofjustice/hmpps-github-actions/.github/workflows/docker_build.yml@v2
with:
docker_registry: 'ghcr.io'
registry_org: 'ministryofjustice'
tag_latest: false
push: true
docker_multiplatform: false

deploy_env_prebuilt:
if: ${{ inputs.image_tag != '' }}
name: Deploy pre-built image to environment
needs:
- helm_lint
uses: ministryofjustice/hmpps-github-actions/.github/workflows/deploy_env.yml@v2
secrets: inherit
with:
environment: ${{ inputs.environment }}
app_version: ${{ inputs.image_tag }}

deploy_env:
if: ${{ inputs.image_tag == '' }}
name: Deploy to environment
needs:
- helm_lint
uses: ministryofjustice/hmpps-github-actions/.github/workflows/deploy_env.yml@v2 # WORKFLOW_VERSION
- build_docker
uses: ministryofjustice/hmpps-github-actions/.github/workflows/deploy_env.yml@v2
secrets: inherit
with:
environment: ${{ inputs.environment }}
app_version: ${{ inputs.version }}
app_version: ${{ needs.build_docker.outputs.app_version }}
62 changes: 62 additions & 0 deletions .github/workflows/e2e_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Run end-to-end tests

on:
workflow_call:
inputs:
app_version:
description: App version
required: true
type: string

permissions:
contents: read

jobs:
e2e_test:
runs-on: ubuntu-latest
env:
APP_VERSION: ${{ inputs.app_version }}
steps:
- uses: actions/checkout@v4

- name: Download docker image
uses: actions/download-artifact@v4
with:
name: build_image
path: ${{ runner.temp }}

- name: Load image
run: |
docker load --input ${{ runner.temp }}/build_image.tar

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 22
cache: 'npm'

- name: Run npm ci
run: npm ci

- name: Stand up a test environment
run: |
echo $APP_VERSION
make test-up

- name: Run the end-to-end tests
run: make e2e-ci

- name: Export container logs
if: failure()
run: make save-logs OUTPUT_LOGS_DIR=${{ runner.temp }}/docker-logs PROJECT_NAME="hmpps-assess-risks-and-needs-test"

- name: Upload test results
if: '!cancelled()'
uses: actions/upload-artifact@v4
with:
name: test_results
path: |
test_results
cypress/videos
cypress/screenshots
${{ runner.temp }}/docker-logs
72 changes: 0 additions & 72 deletions .github/workflows/pipeline.yml

This file was deleted.

77 changes: 77 additions & 0 deletions .github/workflows/pipeline_main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Main pipeline [build -> test -> deploy]

on:
push:
branches:
- main

permissions:
contents: read
packages: write

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false

jobs:

node_build:
name: node build
uses: ministryofjustice/hmpps-github-actions/.github/workflows/node_build.yml@v2
secrets: inherit

node_unit_tests:
name: node unit tests
uses: ministryofjustice/hmpps-github-actions/.github/workflows/node_unit_tests.yml@v2
needs: node_build
secrets: inherit

helm_lint:
strategy:
matrix:
environments: ['dev', 'test']
name: helm lint
uses: ministryofjustice/hmpps-github-actions/.github/workflows/test_helm_lint.yml@v2
secrets: inherit
with:
environment: ${{ matrix.environments }}

build_docker:
name: Build docker image
uses: ministryofjustice/hmpps-github-actions/.github/workflows/docker_build.yml@v2
with:
docker_registry: 'ghcr.io'
registry_org: 'ministryofjustice'
tag_latest: false
push: false
load: true
docker_multiplatform: false
upload_image_artifact: true

e2e_test:
needs: build_docker
uses: ministryofjustice/hmpps-assess-risks-and-needs-oastub-ui/.github/workflows/e2e_test.yml@add-e2e-to-pipeline
with:
app_version: ${{ needs.build_docker.outputs.app_version }}

publish_docker:
name: Publish docker image
needs:
- node_build
- node_unit_tests
- e2e_test
- helm_lint
uses: ministryofjustice/hmpps-github-actions/.github/workflows/docker_push.yml@upload-image-to-artifacts
with:
docker_registry: 'ghcr.io'
registry_org: 'ministryofjustice'
app_version: ${{ needs.build_docker.outputs.app_version }}

deploy_dev:
name: Deploy to the development environment
needs: publish_docker
uses: ministryofjustice/hmpps-github-actions/.github/workflows/deploy_env.yml@v2
secrets: inherit
with:
environment: 'dev'
app_version: '${{ needs.build.outputs.app_version }}'
50 changes: 50 additions & 0 deletions .github/workflows/pipeline_pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Build and test PR

on:
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
node_build:
name: Build
uses: ministryofjustice/hmpps-github-actions/.github/workflows/node_build.yml@v2
secrets: inherit

node_unit_tests:
name: Unit tests
uses: ministryofjustice/hmpps-github-actions/.github/workflows/node_unit_tests.yml@v2
needs: [node_build]
secrets: inherit

helm_lint:
name: Helm lint
strategy:
matrix:
environments: ['dev', 'test']
uses: ministryofjustice/hmpps-github-actions/.github/workflows/test_helm_lint.yml@v2
secrets: inherit
with:
environment: ${{ matrix.environments }}

build_docker:
name: Build docker image
uses: ministryofjustice/hmpps-github-actions/.github/workflows/docker_build.yml@upload-image-to-artifacts
with:
docker_registry: 'ghcr.io'
registry_org: 'ministryofjustice'
tag_latest: false
push: false
load: true
docker_multiplatform: false
upload_image_artifact: true
image_artifact_retention_days: 2


e2e_test:
needs: [build_docker]
uses: ministryofjustice/hmpps-assess-risks-and-needs-oastub-ui/.github/workflows/e2e_test.yml@add-e2e-to-pipeline
with:
app_version: ${{ needs.build_docker.outputs.app_version }}
1 change: 0 additions & 1 deletion .husky/pre-commit

This file was deleted.

2 changes: 1 addition & 1 deletion docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ services:
LOGGING_LEVEL_ORG_SPRINGFRAMEWORK_SECURITY: DEBUG

oasys-ui:
image: quay.io/hmpps/hmpps-assess-risks-and-needs-oastub-ui:${APP_VERSION:-latest}
image: ghcr.io/ministryofjustice/hmpps-assess-risks-and-needs-oastub-ui:${APP_VERSION:-latest}
build:
context: ../
target: production
Expand Down
17 changes: 0 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"repository": "[email protected]:ministryofjustice/hmpps-assess-risks-and-needs-oastub-ui.git",
"license": "MIT",
"scripts": {
"prepare": "husky",
"watch-ts": "tsc -w",
"build": "node esbuild/esbuild.config.js --build",
"start": "node $NODE_OPTIONS dist/server.js | bunyan -o short",
Expand Down Expand Up @@ -152,7 +151,6 @@
"esbuild-plugin-copy": "^2.1.1",
"esbuild-sass-plugin": "^3.3.1",
"glob": "^11.0.1",
"husky": "^9.1.7",
"jest": "^29.7.0",
"jest-html-reporter": "^4.0.0",
"jest-junit": "^16.0.0",
Expand Down
Loading