diff --git a/.github/actions/run-playwright-tests/action.yml b/.github/actions/run-playwright-tests/action.yml new file mode 100644 index 00000000..03cf714c --- /dev/null +++ b/.github/actions/run-playwright-tests/action.yml @@ -0,0 +1,36 @@ +name: "Run Util & Example Tests" +runs-on: ubuntu-latest +timeout-minutes: 3 +runs: + using: "composite" + steps: + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.13' + - name: Install dependencies + shell: bash + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + - name: Ensure browsers are installed + shell: bash + run: python -m playwright install --with-deps + - name: Run util tests + shell: bash + run: pytest -m "utils" --ignore=tests/ + - uses: actions/upload-artifact@v4 + if: ${{ !cancelled() }} + with: + name: result-output-utils + path: test-results/ + retention-days: 3 + - name: Run example tests + shell: bash + run: pytest --ignore=tests_utils/ + - uses: actions/upload-artifact@v4 + if: ${{ !cancelled() }} + with: + name: result-output-example + path: test-results/ + retention-days: 3 diff --git a/.github/workflows/cicd-1-pull-request.yaml b/.github/workflows/cicd-1-pull-request.yaml index f3eda4af..214266f7 100644 --- a/.github/workflows/cicd-1-pull-request.yaml +++ b/.github/workflows/cicd-1-pull-request.yaml @@ -87,29 +87,3 @@ jobs: python_version: "${{ needs.metadata.outputs.python_version }}" version: "${{ needs.metadata.outputs.version }}" secrets: inherit - build-stage: # Recommended maximum execution time is 3 minutes - name: "Build & Assurance stage" - needs: [metadata, test-stage] - uses: ./.github/workflows/stage-3-build.yaml - if: needs.metadata.outputs.does_pull_request_exist == 'true' || (github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'reopened')) - with: - build_datetime: "${{ needs.metadata.outputs.build_datetime }}" - build_timestamp: "${{ needs.metadata.outputs.build_timestamp }}" - build_epoch: "${{ needs.metadata.outputs.build_epoch }}" - nodejs_version: "${{ needs.metadata.outputs.nodejs_version }}" - python_version: "${{ needs.metadata.outputs.python_version }}" - version: "${{ needs.metadata.outputs.version }}" - secrets: inherit - # acceptance-stage: # Recommended maximum execution time is 10 minutes - # name: "Acceptance stage" - # needs: [metadata, build-stage] - # uses: ./.github/workflows/stage-4-acceptance.yaml - # if: needs.metadata.outputs.does_pull_request_exist == 'true' || (github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'reopened')) - # with: - # build_datetime: "${{ needs.metadata.outputs.build_datetime }}" - # build_timestamp: "${{ needs.metadata.outputs.build_timestamp }}" - # build_epoch: "${{ needs.metadata.outputs.build_epoch }}" - # nodejs_version: "${{ needs.metadata.outputs.nodejs_version }}" - # python_version: "${{ needs.metadata.outputs.python_version }}" - # version: "${{ needs.metadata.outputs.version }}" - # secrets: inherit diff --git a/.github/workflows/cicd-2-publish.yaml b/.github/workflows/cicd-2-publish.yaml deleted file mode 100644 index 149b34ac..00000000 --- a/.github/workflows/cicd-2-publish.yaml +++ /dev/null @@ -1,95 +0,0 @@ -name: "CI/CD publish" - -on: - pull_request: - types: [closed] - branches: - - main - -jobs: - metadata: - name: "Set CI/CD metadata" - runs-on: ubuntu-latest - if: github.event.pull_request.merged == true - timeout-minutes: 1 - outputs: - build_datetime: ${{ steps.variables.outputs.build_datetime }} - build_timestamp: ${{ steps.variables.outputs.build_timestamp }} - build_epoch: ${{ steps.variables.outputs.build_epoch }} - nodejs_version: ${{ steps.variables.outputs.nodejs_version }} - python_version: ${{ steps.variables.outputs.python_version }} - version: ${{ steps.variables.outputs.version }} - steps: - - name: "Checkout code" - uses: actions/checkout@v4 - - name: "Set CI/CD variables" - id: variables - run: | - datetime=$(date -u +'%Y-%m-%dT%H:%M:%S%z') - echo "build_datetime=$datetime" >> $GITHUB_OUTPUT - echo "build_timestamp=$(date --date=$datetime -u +'%Y%m%d%H%M%S')" >> $GITHUB_OUTPUT - echo "build_epoch=$(date --date=$datetime -u +'%s')" >> $GITHUB_OUTPUT - echo "nodejs_version=$(grep "^nodejs" .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT - echo "python_version=$(grep "^nodejs" .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT - # TODO: Get the version, but it may not be the .version file as this should come from the CI/CD Pull Request Workflow - echo "version=$(head -n 1 .version 2> /dev/null || echo unknown)" >> $GITHUB_OUTPUT - - name: "List variables" - run: | - export BUILD_DATETIME="${{ steps.variables.outputs.build_datetime }}" - export BUILD_TIMESTAMP="${{ steps.variables.outputs.build_timestamp }}" - export BUILD_EPOCH="${{ steps.variables.outputs.build_epoch }}" - export NODEJS_VERSION="${{ steps.variables.outputs.nodejs_version }}" - export PYTHON_VERSION="${{ steps.variables.outputs.python_version }}" - export VERSION="${{ steps.variables.outputs.version }}" - make list-variables - publish: - name: "Publish packages" - runs-on: ubuntu-latest - needs: [metadata] - if: github.event.pull_request.merged == true - timeout-minutes: 3 - steps: - - name: "Checkout code" - uses: actions/checkout@v4 - - name: "Get the artefacts" - run: | - echo "Getting the artefacts created by the build stage ..." - # TODO: Use either action/cache or action/upload-artifact - - name: "Create release" - id: create_release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tag_name: ${{ needs.metadata.outputs.version }} - release_name: Release ${{ needs.metadata.outputs.version }} - body: | - Release of ${{ needs.metadata.outputs.version }} - draft: false - prerelease: false - # - name: "Upload release asset" - # uses: actions/upload-release-asset@v1 - # env: - # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # with: - # upload_url: "${{ steps.create_release.outputs.upload_url }}" - # asset_path: ./* - # asset_name: repository-template-${{ needs.metadata.outputs.version }}.tar.gz - # asset_content_type: "application/gzip" - # success: - # name: "Success notification" - # runs-on: ubuntu-latest - # needs: [publish] - # steps: - # - name: "Check prerequisites for notification" - # id: check - # run: echo "secret_exist=${{ secrets.TEAMS_NOTIFICATION_WEBHOOK_URL != '' }}" >> $GITHUB_OUTPUT - # - name: "Notify on publishing packages" - # if: steps.check.outputs.secret_exist == 'true' - # uses: nhs-england-tools/notify-msteams-action@v1.0.0 - # with: - # github-token: ${{ secrets.GITHUB_TOKEN }} - # teams-webhook-url: ${{ secrets.TEAMS_NOTIFICATION_WEBHOOK_URL }} - # message-title: "Notification title" - # message-text: "This is a notification body" - # link: ${{ github.event.pull_request.html_url }} diff --git a/.github/workflows/cicd-3-deploy.yaml b/.github/workflows/cicd-3-deploy.yaml deleted file mode 100644 index 95c88dd2..00000000 --- a/.github/workflows/cicd-3-deploy.yaml +++ /dev/null @@ -1,74 +0,0 @@ -name: "CI/CD deploy" - -on: - workflow_dispatch: - inputs: - tag: - description: "This is the tag that is oging to be deployed" - required: true - default: "latest" - -jobs: - metadata: - name: "Set CI/CD metadata" - runs-on: ubuntu-latest - timeout-minutes: 1 - outputs: - build_datetime: ${{ steps.variables.outputs.build_datetime }} - build_timestamp: ${{ steps.variables.outputs.build_timestamp }} - build_epoch: ${{ steps.variables.outputs.build_epoch }} - nodejs_version: ${{ steps.variables.outputs.nodejs_version }} - python_version: ${{ steps.variables.outputs.python_version }} - version: ${{ steps.variables.outputs.version }} - tag: ${{ steps.variables.outputs.tag }} - steps: - - name: "Checkout code" - uses: actions/checkout@v4 - - name: "Set CI/CD variables" - id: variables - run: | - datetime=$(date -u +'%Y-%m-%dT%H:%M:%S%z') - echo "build_datetime=$datetime" >> $GITHUB_OUTPUT - echo "build_timestamp=$(date --date=$datetime -u +'%Y%m%d%H%M%S')" >> $GITHUB_OUTPUT - echo "build_epoch=$(date --date=$datetime -u +'%s')" >> $GITHUB_OUTPUT - echo "nodejs_version=$(grep "^nodejs" .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT - echo "python_version=$(grep "^nodejs" .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT - # TODO: Get the version, but it may not be the .version file as this should come from the CI/CD Pull Request Workflow - echo "version=$(head -n 1 .version 2> /dev/null || echo unknown)" >> $GITHUB_OUTPUT - echo "tag=${{ github.event.inputs.tag }}" >> $GITHUB_OUTPUT - - name: "List variables" - run: | - export BUILD_DATETIME="${{ steps.variables.outputs.build_datetime }}" - export BUILD_TIMESTAMP="${{ steps.variables.outputs.build_timestamp }}" - export BUILD_EPOCH="${{ steps.variables.outputs.build_epoch }}" - export NODEJS_VERSION="${{ steps.variables.outputs.nodejs_version }}" - export PYTHON_VERSION="${{ steps.variables.outputs.python_version }}" - export VERSION="${{ steps.variables.outputs.version }}" - export TAG="${{ steps.variables.outputs.tag }}" - make list-variables - deploy: - name: "Deploy to an environment" - runs-on: ubuntu-latest - needs: [metadata] - timeout-minutes: 10 - steps: - - name: "Checkout code" - uses: actions/checkout@v4 - # TODO: More jobs or/and steps here - # success: - # name: "Success notification" - # runs-on: ubuntu-latest - # needs: [deploy] - # steps: - # - name: "Check prerequisites for notification" - # id: check - # run: echo "secret_exist=${{ secrets.TEAMS_NOTIFICATION_WEBHOOK_URL != '' }}" >> $GITHUB_OUTPUT - # - name: "Notify on deployment to an environment" - # if: steps.check.outputs.secret_exist == 'true' - # uses: nhs-england-tools/notify-msteams-action@v0.0.4 - # with: - # github-token: ${{ secrets.GITHUB_TOKEN }} - # teams-webhook-url: ${{ secrets.TEAMS_NOTIFICATION_WEBHOOK_URL }} - # message-title: "Notification title" - # message-text: "This is a notification body" - # link: ${{ github.event.pull_request.html_url }} diff --git a/.github/workflows/stage-2-test.yaml b/.github/workflows/stage-2-test.yaml index 8af66ad6..48a47ca6 100644 --- a/.github/workflows/stage-2-test.yaml +++ b/.github/workflows/stage-2-test.yaml @@ -29,62 +29,12 @@ on: type: string jobs: - test-unit: - name: "Unit tests" + run-tests: + name: "Run Util & Example Tests" runs-on: ubuntu-latest - timeout-minutes: 5 + timeout-minutes: 3 steps: - name: "Checkout code" uses: actions/checkout@v4 - - name: "Run unit test suite" - run: | - make test-unit - - name: "Save the result of fast test suite" - run: | - echo "Nothing to save" - test-lint: - name: "Linting" - runs-on: ubuntu-latest - timeout-minutes: 5 - steps: - - name: "Checkout code" - uses: actions/checkout@v4 - - name: "Run linting" - run: | - make test-lint - - name: "Save the linting result" - run: | - echo "Nothing to save" - test-coverage: - name: "Test coverage" - needs: [test-unit] - runs-on: ubuntu-latest - timeout-minutes: 5 - steps: - - name: "Checkout code" - uses: actions/checkout@v4 - - name: "Run test coverage check" - run: | - make test-coverage - - name: "Save the coverage check result" - run: | - echo "Nothing to save" - perform-static-analysis: - name: "Perform static analysis" - needs: [test-unit] - runs-on: ubuntu-latest - permissions: - id-token: write - contents: read - timeout-minutes: 5 - steps: - - name: "Checkout code" - uses: actions/checkout@v4 - with: - fetch-depth: 0 # Full history is needed to improving relevancy of reporting - - name: "Perform static analysis" - uses: ./.github/actions/perform-static-analysis - with: - sonar_organisation_key: "${{ vars.SONAR_ORGANISATION_KEY }}" - sonar_project_key: "${{ vars.SONAR_PROJECT_KEY }}" - sonar_token: "${{ secrets.SONAR_TOKEN }}" + - name: "Run Playwright Tests" + uses: ./.github/actions/run-playwright-tests diff --git a/.github/workflows/stage-3-build.yaml b/.github/workflows/stage-3-build.yaml deleted file mode 100644 index fceea727..00000000 --- a/.github/workflows/stage-3-build.yaml +++ /dev/null @@ -1,57 +0,0 @@ -name: "Build & Assurance stage" - -on: - workflow_call: - inputs: - build_datetime: - description: "Build datetime, set by the CI/CD pipeline workflow" - required: true - type: string - build_timestamp: - description: "Build timestamp, set by the CI/CD pipeline workflow" - required: true - type: string - build_epoch: - description: "Build epoch, set by the CI/CD pipeline workflow" - required: true - type: string - nodejs_version: - description: "Node.js version, set by the CI/CD pipeline workflow" - required: true - type: string - python_version: - description: "Python version, set by the CI/CD pipeline workflow" - required: true - type: string - version: - description: "Version of the software, set by the CI/CD pipeline workflow" - required: true - type: string - -jobs: - run-tests: - name: "Run Util & Example Tests" - runs-on: ubuntu-latest - timeout-minutes: 3 - steps: - - uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: '3.12' - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements.txt - - name: Ensure browsers are installed - run: python -m playwright install --with-deps - - name: Run util tests - run: pytest -m "utils" --ignore=tests/ - - name: Run example tests - run: pytest - - uses: actions/upload-artifact@v4 - if: ${{ !cancelled() }} - with: - name: result-output - path: test-results/ - retention-days: 5 diff --git a/.github/workflows/stage-4-acceptance.yaml b/.github/workflows/stage-4-acceptance.yaml deleted file mode 100644 index d4e4155b..00000000 --- a/.github/workflows/stage-4-acceptance.yaml +++ /dev/null @@ -1,166 +0,0 @@ -name: "Acceptance stage" - -on: - workflow_call: - inputs: - build_datetime: - description: "Build datetime, set by the CI/CD pipeline workflow" - required: true - type: string - build_timestamp: - description: "Build timestamp, set by the CI/CD pipeline workflow" - required: true - type: string - build_epoch: - description: "Build epoch, set by the CI/CD pipeline workflow" - required: true - type: string - nodejs_version: - description: "Node.js version, set by the CI/CD pipeline workflow" - required: true - type: string - python_version: - description: "Python version, set by the CI/CD pipeline workflow" - required: true - type: string - version: - description: "Version of the software, set by the CI/CD pipeline workflow" - required: true - type: string - -jobs: - environment-set-up: - name: "Environment set up" - runs-on: ubuntu-latest - timeout-minutes: 5 - steps: - - name: "Checkout code" - uses: actions/checkout@v4 - - name: "Create infractructure" - run: | - echo "Creating infractructure..." - - name: "Update database" - run: | - echo "Updating database..." - - name: "Deploy application" - run: | - echo "Deploying application..." - test-contract: - name: "Contract test" - runs-on: ubuntu-latest - needs: environment-set-up - timeout-minutes: 10 - steps: - - name: "Checkout code" - uses: actions/checkout@v4 - - name: "Run contract test" - run: | - make test-contract - - name: "Save result" - run: | - echo "Nothing to save" - test-security: - name: "Security test" - runs-on: ubuntu-latest - needs: environment-set-up - timeout-minutes: 10 - steps: - - name: "Checkout code" - uses: actions/checkout@v4 - - name: "Run security test" - run: | - make test-security - - name: "Save result" - run: | - echo "Nothing to save" - test-ui: - name: "UI test" - runs-on: ubuntu-latest - needs: environment-set-up - timeout-minutes: 10 - steps: - - name: "Checkout code" - uses: actions/checkout@v4 - - name: "Run UI test" - run: | - make test-ui - - name: "Save result" - run: | - echo "Nothing to save" - test-ui-performance: - name: "UI performance test" - runs-on: ubuntu-latest - needs: environment-set-up - timeout-minutes: 10 - steps: - - name: "Checkout code" - uses: actions/checkout@v4 - - name: "Run UI performance test" - run: | - make test-ui-performance - - name: "Save result" - run: | - echo "Nothing to save" - test-integration: - name: "Integration test" - runs-on: ubuntu-latest - needs: environment-set-up - timeout-minutes: 10 - steps: - - name: "Checkout code" - uses: actions/checkout@v4 - - name: "Run integration test" - run: | - make test-integration - - name: "Save result" - run: | - echo "Nothing to save" - test-accessibility: - name: "Accessibility test" - runs-on: ubuntu-latest - needs: environment-set-up - timeout-minutes: 10 - steps: - - name: "Checkout code" - uses: actions/checkout@v4 - - name: "Run accessibility test" - run: | - make test-accessibility - - name: "Save result" - run: | - echo "Nothing to save" - test-load: - name: "Load test" - runs-on: ubuntu-latest - needs: environment-set-up - timeout-minutes: 10 - steps: - - name: "Checkout code" - uses: actions/checkout@v4 - - name: "Run load tests" - run: | - make test-load - - name: "Save result" - run: | - echo "Nothing to save" - environment-tear-down: - name: "Environment tear down" - runs-on: ubuntu-latest - needs: - [ - test-accessibility, - test-contract, - test-integration, - test-load, - test-security, - test-ui-performance, - test-ui, - ] - if: always() - timeout-minutes: 5 - steps: - - name: "Checkout code" - uses: actions/checkout@v4 - - name: "Tear down environment" - run: | - echo "Tearing down environment..."