From 7b58fdb621d390bcfc9635346b4bdec1efd37db0 Mon Sep 17 00:00:00 2001 From: Matthew Griffin Date: Thu, 13 Jun 2024 15:27:43 +0100 Subject: [PATCH 01/11] Move playwright workflow Update with local actions and Python specific requirements --- .github/workflows/playwright.yml | 28 +++++++++++++++++++++ playwright/.github/workflows/playwright.yml | 27 -------------------- 2 files changed, 28 insertions(+), 27 deletions(-) create mode 100644 .github/workflows/playwright.yml delete mode 100644 playwright/.github/workflows/playwright.yml diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml new file mode 100644 index 00000000..0b17e594 --- /dev/null +++ b/.github/workflows/playwright.yml @@ -0,0 +1,28 @@ +name: Playwright Tests +on: + push: + branches: [ main ] + pull_request: +jobs: + test: + timeout-minutes: 10 + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v4 + - name: Set up environment + uses: ./.github/actions/set-up-environment + - name: Setup Python + uses: actions/setup-python@v5.1.0 + with: + python-version: '3.11' + - name: Install Playwright Dependencies + run: npm run playwright-install + - name: Run Playwright tests + run: npm run playwright-test + - uses: actions/upload-artifact@v4 + if: always() + with: + name: playwright-report + path: playwright/playwright-report/ + retention-days: 30 diff --git a/playwright/.github/workflows/playwright.yml b/playwright/.github/workflows/playwright.yml deleted file mode 100644 index 467190be..00000000 --- a/playwright/.github/workflows/playwright.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Playwright Tests -on: - push: - branches: [ main, master ] - pull_request: - branches: [ main, master ] -jobs: - test: - timeout-minutes: 60 - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 - with: - node-version: lts/* - - name: Install dependencies - run: npm ci - - name: Install Playwright Browsers - run: npx playwright install --with-deps - - name: Run Playwright tests - run: npx playwright test - - uses: actions/upload-artifact@v4 - if: always() - with: - name: playwright-report - path: playwright-report/ - retention-days: 30 From 26434d1a20c4b472bc87f228ad5b43f96a4fac88 Mon Sep 17 00:00:00 2001 From: Matthew Griffin Date: Thu, 13 Jun 2024 15:42:33 +0100 Subject: [PATCH 02/11] CI Install may need dependencies --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7d677bb0..97fe2f98 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "watch": "ng build --watch --configuration development", "test": "ng test", "lint": "ng lint", - "playwright-install": "pip install -r requirements.txt && playwright install", + "playwright-install": "pip install -r requirements.txt && playwright install --with-deps", "playwright-test": "cd playwright/tests && pytest" }, "private": true, From 1b084cd14dce782e022505b0972ae5ad82dc35ee Mon Sep 17 00:00:00 2001 From: Matthew Griffin Date: Fri, 14 Jun 2024 13:52:13 +0100 Subject: [PATCH 03/11] Use cross platform method of running npm Ensure server is terminated on interrupt --- playwright/tests/conftest.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/playwright/tests/conftest.py b/playwright/tests/conftest.py index a1ce0a81..66a3c25a 100644 --- a/playwright/tests/conftest.py +++ b/playwright/tests/conftest.py @@ -1,4 +1,5 @@ import pytest +import shutil from xprocess import ProcessStarter @pytest.fixture(autouse=True, scope="session") @@ -8,7 +9,9 @@ class Starter(ProcessStarter): pattern = "Application bundle generation complete." # command to start process - args = ['sh', 'npm', 'start'] + args = [shutil.which('npm'), 'start'] + + terminate_on_interrupt = True # ensure process is running and return its logfile logfile = xprocess.ensure("estimator", Starter) From 4949da1d53440410068132e813428487f0d45bfa Mon Sep 17 00:00:00 2001 From: Matthew Griffin Date: Mon, 17 Jun 2024 09:20:05 +0100 Subject: [PATCH 04/11] Run playwright on successful completion of PR Workflow and allow manual trigger --- .github/workflows/playwright.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 0b17e594..30ff50b4 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -2,11 +2,15 @@ name: Playwright Tests on: push: branches: [ main ] - pull_request: + workflow_run: + workflows: ['PR Workflow'] + types: [completed] + workflow_dispatch: jobs: test: timeout-minutes: 10 runs-on: ubuntu-latest + if: ${{ github.event.workflow_run == null || github.event.workflow_run.conclusion != 'failure' }} steps: - name: Check out code uses: actions/checkout@v4 From 09317b8970ab93c148f8518af326692b121072aa Mon Sep 17 00:00:00 2001 From: Matthew Griffin Date: Mon, 17 Jun 2024 09:46:13 +0100 Subject: [PATCH 05/11] Add Playwright into its own action that can run separately or in pull request --- .github/actions/run-playwright/action.yml | 21 +++++++++++++++++++++ .github/workflows/playwright.yml | 20 ++------------------ .github/workflows/pull-request.yml | 10 ++++++++++ 3 files changed, 33 insertions(+), 18 deletions(-) create mode 100644 .github/actions/run-playwright/action.yml diff --git a/.github/actions/run-playwright/action.yml b/.github/actions/run-playwright/action.yml new file mode 100644 index 00000000..68cc8df2 --- /dev/null +++ b/.github/actions/run-playwright/action.yml @@ -0,0 +1,21 @@ +name: 'Run Playwright' +description: 'Sets up Python, installs dependencies and runs playwright tests' +runs: + using: 'composite' + steps: + - name: Setup Python + uses: actions/setup-python@v5.1.0 + with: + python-version: '3.11' + - name: Install Playwright Dependencies + run: npm run playwright-install + shell: bash + - name: Run Playwright tests + run: npm run playwright-test + shell: bash + - uses: actions/upload-artifact@v4 + if: always() + with: + name: playwright-report + path: playwright/playwright-report/ + retention-days: 30 \ No newline at end of file diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 30ff50b4..c519ab48 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -2,31 +2,15 @@ name: Playwright Tests on: push: branches: [ main ] - workflow_run: - workflows: ['PR Workflow'] - types: [completed] workflow_dispatch: jobs: test: timeout-minutes: 10 runs-on: ubuntu-latest - if: ${{ github.event.workflow_run == null || github.event.workflow_run.conclusion != 'failure' }} steps: - name: Check out code uses: actions/checkout@v4 - name: Set up environment uses: ./.github/actions/set-up-environment - - name: Setup Python - uses: actions/setup-python@v5.1.0 - with: - python-version: '3.11' - - name: Install Playwright Dependencies - run: npm run playwright-install - - name: Run Playwright tests - run: npm run playwright-test - - uses: actions/upload-artifact@v4 - if: always() - with: - name: playwright-report - path: playwright/playwright-report/ - retention-days: 30 + - name: Run Playwright + uses: ./.github/actions/run-playwright diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 65b245fd..960f65ec 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -21,3 +21,13 @@ jobs: uses: ./.github/actions/set-up-environment - name: Run tests run: npm test + playwright_tests: + needs: unit_tests + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v4 + - name: Set up environment + uses: ./.github/actions/set-up-environment + - name: Run Playwright + uses: ./.github/actions/run-playwright From 58d2f7a4c976a4edced32e4445a27d3830dcf272 Mon Sep 17 00:00:00 2001 From: Matthew Griffin Date: Mon, 17 Jun 2024 11:43:29 +0100 Subject: [PATCH 06/11] Fix up a couple more errors --- .../tests/test_0_TrialTest_HappyPath.py | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/playwright/tests/test_0_TrialTest_HappyPath.py b/playwright/tests/test_0_TrialTest_HappyPath.py index e062d471..9a8709e7 100644 --- a/playwright/tests/test_0_TrialTest_HappyPath.py +++ b/playwright/tests/test_0_TrialTest_HappyPath.py @@ -15,27 +15,23 @@ def test_example(page: Page) -> None: page.get_by_text("Laptops 50%").click() expect(page.get_by_role("heading", name="On-Premise Servers")).to_be_visible() expect(page.get_by_label("Number of Servers:")).to_have_value("10"); - expect(page.get_by_label("Where are they primarily")).to_have_value("global"); + expect(page.get_by_label("Where are they primarily")).to_have_value("WORLD"); expect(page.get_by_role("heading", name="Cloud Services")).to_be_visible() expect(page.get_by_text("Cloud 50%")).to_be_visible() - expect(page.get_by_text("On-prem 50%")).to_be_visible() - expect(page.get_by_label("Where are your cloud servers")).to_have_value("global"); + expect(page.get_by_text("On-premise 50%")).to_be_visible() + expect(page.get_by_label("Where are your cloud servers")).to_have_value("WORLD"); expect(page.get_by_label("What is your monthly cloud")).to_have_value("0: Object"); expect(page.get_by_role("heading", name="Users")).to_be_visible() - expect(page.get_by_text("Where are your users")).to_be_visible() - expect(page.get_by_label("Where are your users")).to_have_value("global"); + expect(page.get_by_text("Where are your end-users")).to_be_visible() + expect(page.get_by_label("Where are your end-users")).to_have_value("WORLD"); expect(page.get_by_text("How many monthly active users")).to_be_visible() expect(page.get_by_label("How many monthly active users")).to_have_value("100"); expect(page.get_by_text("Mobile 50%")).to_be_visible() expect(page.get_by_text("Computer 50%")).to_be_visible() - expect(page.get_by_text("What's the purpose of your")).to_be_visible() - expect(page.get_by_label("What's the purpose of your")).to_have_value("average"); + expect(page.get_by_text("What's the primary purpose of your")).to_be_visible() + expect(page.get_by_label("What's the primary purpose of your")).to_have_value("average"); page.get_by_role("button", name="Calculate").click() - expect(page.get_by_text("Upstream Emissions:")).to_be_visible() - expect(page.get_by_text("28%")).to_be_visible() - expect(page.get_by_text("Indirect Emissions:")).to_be_visible() - expect(page.get_by_text("0%", exact=True)).to_be_visible() - expect(page.get_by_text("Direct Emissions:", exact=True)).to_be_visible() - expect(page.get_by_text("71%")).to_be_visible() - expect(page.get_by_text("Downstream Emissions:")).to_be_visible() - expect(page.get_by_text("1%", exact=True)).to_be_visible() + expect(page.locator("foreignobject")).to_contain_text("Upstream Emissions - 33%") + expect(page.locator("foreignobject")).to_contain_text("Direct Emissions - 65%") + expect(page.locator("foreignobject")).to_contain_text("Indirect Emissions - 1%") + expect(page.locator("foreignobject")).to_contain_text("Downstream Emissions - <1%") From d4741d78e5b0fbb5af063bd8a3d3ede202c05c0e Mon Sep 17 00:00:00 2001 From: Matthew Griffin Date: Mon, 17 Jun 2024 11:51:39 +0100 Subject: [PATCH 07/11] Add a shorter timeout for server startup --- playwright/tests/conftest.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/playwright/tests/conftest.py b/playwright/tests/conftest.py index 66a3c25a..8af17bb6 100644 --- a/playwright/tests/conftest.py +++ b/playwright/tests/conftest.py @@ -13,6 +13,8 @@ class Starter(ProcessStarter): terminate_on_interrupt = True + timeout = 20 + # ensure process is running and return its logfile logfile = xprocess.ensure("estimator", Starter) From c9499599a5f212eab0a4e02cfa8afa80b9901dc8 Mon Sep 17 00:00:00 2001 From: Matthew Griffin <117279304+mgriffin-scottlogic@users.noreply.github.com> Date: Mon, 17 Jun 2024 13:23:55 +0100 Subject: [PATCH 08/11] Run playwright in parallel with unit tests Co-authored-by: jantoun-scottlogic <110816538+jantoun-scottlogic@users.noreply.github.com> --- .github/workflows/pull-request.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 960f65ec..6ddc6563 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -22,7 +22,7 @@ jobs: - name: Run tests run: npm test playwright_tests: - needs: unit_tests + needs: build runs-on: ubuntu-latest steps: - name: Check out code From 7f7da4668a96fa0c0f09bfd0438dc68f62fdeb7a Mon Sep 17 00:00:00 2001 From: Matthew Griffin Date: Mon, 17 Jun 2024 15:45:02 +0100 Subject: [PATCH 09/11] Remove artifact upload step until we have reports generated by Playwright --- .github/actions/run-playwright/action.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/actions/run-playwright/action.yml b/.github/actions/run-playwright/action.yml index 68cc8df2..3f3f7b1a 100644 --- a/.github/actions/run-playwright/action.yml +++ b/.github/actions/run-playwright/action.yml @@ -13,9 +13,3 @@ runs: - name: Run Playwright tests run: npm run playwright-test shell: bash - - uses: actions/upload-artifact@v4 - if: always() - with: - name: playwright-report - path: playwright/playwright-report/ - retention-days: 30 \ No newline at end of file From 15760c9545ade0a7a9eec45994c7c5d0b6c8daf6 Mon Sep 17 00:00:00 2001 From: Matthew Griffin Date: Thu, 20 Jun 2024 16:41:49 +0100 Subject: [PATCH 10/11] Move Reset before Calculate in tab order --- .../carbon-estimator-form.component.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/carbon-estimator-form/carbon-estimator-form.component.html b/src/app/carbon-estimator-form/carbon-estimator-form.component.html index 7c1b69cc..1594cc93 100644 --- a/src/app/carbon-estimator-form/carbon-estimator-form.component.html +++ b/src/app/carbon-estimator-form/carbon-estimator-form.component.html @@ -250,7 +250,8 @@ -
+
+ -
Date: Fri, 21 Jun 2024 16:22:50 +0100 Subject: [PATCH 11/11] Add terms and conditions file --- TERMS.md | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 TERMS.md diff --git a/TERMS.md b/TERMS.md new file mode 100644 index 00000000..66a31a8a --- /dev/null +++ b/TERMS.md @@ -0,0 +1,98 @@ +## PLEASE READ THESE TERMS AND CONDITIONS CAREFULLY BEFORE USING THIS SITE + +### Who we are and how to contact us + +https://github.com/ScottLogic/sl-tech-carbon-estimator is a site operated by Scott Logic Limited ("We"). We are registered in England and Wales under company number 05377430 and have our registered office at 6th Floor The Lumen, St James Boulevard, Newcastle Helix, Newcastle upon Tyne, NE4 5BZ. Our VAT number is 866105130. + +We are a limited company. + +To contact us, please email sustainability@scottlogic.com + +### By using our site you accept these terms + +By using our site, you confirm that you accept these terms of use and that you agree to comply with them. + +If you do not agree to these terms, you must not use our site. + +We recommend that you print a copy of these terms for future reference. + +### We may make changes to these terms + +We amend these terms from time to time. Every time you wish to use our site, please check these terms to ensure you understand the terms that apply at that time. + +### We may make changes to our site + +We may update and change our site from time to time + +### We may suspend or withdraw our site + +Our site is made available free of charge. + +We do not guarantee that our site, or any content on it, will always be available or be uninterrupted. We may suspend or withdraw or restrict the availability of all or any part of our site for business and operational reasons. We will try to give you reasonable notice of any suspension or withdrawal. + +### How you may use material on our site + +We are the owner or the licensee of all intellectual property rights in our site, and in the material published on it. Those works are protected by copyright laws and treaties around the world. All such rights are reserved. + +You may print off one copy, and may download extracts, of any page(s) from our site for your personal use and you may draw the attention of others within your organisation to content posted on our site. + +You must not modify the paper or digital copies of any materials you have printed off or downloaded in any way, and you must not use any illustrations, photographs, video or audio sequences or any graphics separately from any accompanying text. + +Our status (and that of any identified contributors) as the authors of content on our site must always be acknowledged. + +You must not use any part of the content on our site for commercial purposes without obtaining a licence to do so from us or our licensors. + +If you print off, copy, download, share or repost any part of our site in breach of these terms of use, your right to use our site will cease immediately and you must, at our option, return or destroy any copies of the materials you have made. + +### No text or data mining, or web scraping + +You shall not conduct, facilitate, authorise or permit any text or data mining or web scraping in relation to our site or any services provided via, or in relation to, our site. This includes using (or permitting, authorising or attempting the use of): + +- Any "robot", "bot", "spider", "scraper" or other automated device, program, tool, algorithm, code, process or methodology to access, obtain, copy, monitor or republish any portion of the site or any data, content, information or services accessed via the same. +- Any automated analytical technique aimed at analysing text and data in digital form to generate information which includes but is not limited to patterns, trends and correlations. + +The provisions in this clause should be treated as an express reservation of our rights in this regard, including for the purposes of Article 4(3) of Digital Copyright Directive (_(EU) 2019/790_). + +This clause shall not apply insofar as (but only to the extent that) we are unable to exclude or limit text or data mining or web scraping activity by contract under the laws which are applicable to us. + +### Do not rely on information on this site + +The content on our site is provided for general information only. It is not intended to amount to advice on which you should rely. You must obtain professional or specialist advice before taking, or refraining from, any action on the basis of the content on our site. + +Although we make reasonable efforts to update the information on our site, we make no representations, warranties or guarantees, whether express or implied, that the content on our site is accurate, complete or up to date. + +### We are not responsible for websites we link to + +Where our site contains links to other sites and resources provided by third parties, these links are provided for your information only. Such links should not be interpreted as approval by us of those linked websites or information you may obtain from them. + +We have no control over the contents of those sites or resources. + +### Our responsibility for loss or damage suffered by you + +- We do not exclude or limit in any way our liability to you where it would be unlawful to do so. This includes liability for death or personal injury caused by our negligence or the negligence of our employees, agents or subcontractors and for fraud or fraudulent misrepresentation. +- We exclude all implied conditions, warranties, representations or other terms that may apply to our site or any content on it. +- We will not be liable to you for any loss or damage, whether in contract, tort (including negligence), breach of statutory duty, or otherwise, even if foreseeable, arising under or in connection with: + - use of, or inability to use, our site; or + - use of or reliance on any content displayed on our site. +- In particular, we will not be liable for: + - loss of profits, sales, business, or revenue; + - business interruption; + - loss of anticipated savings; + - loss of business opportunity, goodwill or reputation; or + - any indirect or consequential loss or damage. + +### Rights you are giving us to use material you upload + +When you upload content to our site, you grant us a worldwide, non-exclusive, royalty-free, transferable licence for to use that content to promote the Site, environmental credentials, our business and carbon estimation calculations. + +### We are not responsible for viruses and you must not introduce them + +We do not guarantee that our site will be secure or free from bugs or viruses. + +You are responsible for configuring your information technology, computer programmes and platform to access our site. You should use your own virus protection software. + +You must not misuse our site by knowingly introducing viruses, trojans, worms, logic bombs or other material that is malicious or technologically harmful. You must not attempt to gain unauthorised access to our site, the server on which our site is stored or any server, computer or database connected to our site. You must not attack our site via a denial-of-service attack or a distributed denial-of service attack. By breaching this provision, you would commit a criminal offence under the Computer Misuse Act 1990. We will report any such breach to the relevant law enforcement authorities and we will co-operate with those authorities by disclosing your identity to them. In the event of such a breach, your right to use our site will cease immediately. + +### Which country's laws apply to any disputes? + +These terms of use, their subject matter and their formation (and any non-contractual disputes or claims) are governed by English law. We both agree to the exclusive jurisdiction of the courts of England and Wales. \ No newline at end of file