From ced1892377dafefe7f9e0d94cdc83737594a4d02 Mon Sep 17 00:00:00 2001 From: jantoun-scottlogic Date: Tue, 21 May 2024 08:58:56 +0100 Subject: [PATCH 1/9] Add merge pipeline --- .github/workflows/pull-request.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .github/workflows/pull-request.yml diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml new file mode 100644 index 00000000..cf4a78cf --- /dev/null +++ b/.github/workflows/pull-request.yml @@ -0,0 +1,17 @@ +name: PR Workflow +on: pull_request + +jobs: + unit_tests: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: '18' + - name: Install dependencies + run: npm ci + - name: Run tests + run: npm test From 1368fa985c9a4c2408e6d84dac86b119d85cd07d Mon Sep 17 00:00:00 2001 From: jantoun-scottlogic Date: Tue, 21 May 2024 09:13:16 +0100 Subject: [PATCH 2/9] Add build job --- .github/workflows/pull-request.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index cf4a78cf..4bbf5399 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -2,6 +2,19 @@ name: PR Workflow on: pull_request jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: '18' + - name: Install dependencies + run: npm ci + - name: Build app + run: npm run build unit_tests: runs-on: ubuntu-latest steps: From 52f3b65d576f914560dd5b2e160b61785716ec9b Mon Sep 17 00:00:00 2001 From: jantoun-scottlogic Date: Tue, 21 May 2024 09:24:40 +0100 Subject: [PATCH 3/9] Add build dependency to unit_tests job --- .github/workflows/pull-request.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 4bbf5399..f0e7c22e 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -16,6 +16,7 @@ jobs: - name: Build app run: npm run build unit_tests: + needs: build runs-on: ubuntu-latest steps: - name: Checkout code From 000a1be1345f55b2aa1a2aec6fc9012a4902a4a8 Mon Sep 17 00:00:00 2001 From: jantoun-scottlogic Date: Tue, 21 May 2024 09:34:30 +0100 Subject: [PATCH 4/9] Add dependency caching --- .github/workflows/pull-request.yml | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index f0e7c22e..5b832c2d 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -10,8 +10,15 @@ jobs: - name: Setup Node uses: actions/setup-node@v4 with: - node-version: '18' + node-version: 18 + - name: Cache dependencies + id: cache + uses: actions/cache@v4 + with: + path: node_modules + key: node-modules-${{ hashFiles('**/package-lock.json') }} - name: Install dependencies + if: steps.cache.outputs.cache-hit != 'true' run: npm ci - name: Build app run: npm run build @@ -24,8 +31,15 @@ jobs: - name: Setup Node uses: actions/setup-node@v4 with: - node-version: '18' + node-version: 18 + - name: Cache dependencies + id: cache + uses: actions/cache@v4 + with: + path: node_modules + key: node-modules-${{ hashFiles('**/package-lock.json') }} - name: Install dependencies + if: steps.cache.outputs.cache-hit != 'true' run: npm ci - name: Run tests run: npm test From 6f92d9ab0fd1782ed33c5a63b36a02a532dcc256 Mon Sep 17 00:00:00 2001 From: jantoun-scottlogic Date: Tue, 21 May 2024 14:27:05 +0100 Subject: [PATCH 5/9] Cache ~/.npm rather than node_modules --- .github/workflows/pull-request.yml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 5b832c2d..446e5678 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -12,13 +12,11 @@ jobs: with: node-version: 18 - name: Cache dependencies - id: cache uses: actions/cache@v4 with: - path: node_modules + path: ~/.npm key: node-modules-${{ hashFiles('**/package-lock.json') }} - name: Install dependencies - if: steps.cache.outputs.cache-hit != 'true' run: npm ci - name: Build app run: npm run build @@ -33,13 +31,11 @@ jobs: with: node-version: 18 - name: Cache dependencies - id: cache uses: actions/cache@v4 with: - path: node_modules + path: ~/.npm key: node-modules-${{ hashFiles('**/package-lock.json') }} - name: Install dependencies - if: steps.cache.outputs.cache-hit != 'true' run: npm ci - name: Run tests run: npm test From 091721852a04e509f0e17fab788da257d6d8eae0 Mon Sep 17 00:00:00 2001 From: jantoun-scottlogic Date: Tue, 21 May 2024 16:27:03 +0100 Subject: [PATCH 6/9] Move environment setup to custom action --- .github/actions/set-up-environment/action.yml | 17 +++++++++++ .github/workflows/pull-request.yml | 30 ++++--------------- 2 files changed, 23 insertions(+), 24 deletions(-) create mode 100644 .github/actions/set-up-environment/action.yml diff --git a/.github/actions/set-up-environment/action.yml b/.github/actions/set-up-environment/action.yml new file mode 100644 index 00000000..1f2c4348 --- /dev/null +++ b/.github/actions/set-up-environment/action.yml @@ -0,0 +1,17 @@ +name: 'Set up environment' +description: 'Sets up Node and installs dependencies' +runs: + using: 'composite' + steps: + - name: Set up Node + uses: actions/setup-node@v4 + with: + node-version: 18 + - name: Cache dependencies + uses: actions/cache@v4 + with: + path: ~/.npm + key: node-modules-${{ hashFiles('**/package-lock.json') }} + - name: Install dependencies + run: npm ci + shell: bash diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 446e5678..65b245fd 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -5,37 +5,19 @@ jobs: build: runs-on: ubuntu-latest steps: - - name: Checkout code + - name: Check out code uses: actions/checkout@v4 - - name: Setup Node - uses: actions/setup-node@v4 - with: - node-version: 18 - - name: Cache dependencies - uses: actions/cache@v4 - with: - path: ~/.npm - key: node-modules-${{ hashFiles('**/package-lock.json') }} - - name: Install dependencies - run: npm ci + - name: Set up environment + uses: ./.github/actions/set-up-environment - name: Build app run: npm run build unit_tests: needs: build runs-on: ubuntu-latest steps: - - name: Checkout code + - name: Check out code uses: actions/checkout@v4 - - name: Setup Node - uses: actions/setup-node@v4 - with: - node-version: 18 - - name: Cache dependencies - uses: actions/cache@v4 - with: - path: ~/.npm - key: node-modules-${{ hashFiles('**/package-lock.json') }} - - name: Install dependencies - run: npm ci + - name: Set up environment + uses: ./.github/actions/set-up-environment - name: Run tests run: npm test From 81da3f77eb025e8832d64ac969663852676a4861 Mon Sep 17 00:00:00 2001 From: jantoun-scottlogic Date: Tue, 21 May 2024 16:43:57 +0100 Subject: [PATCH 7/9] Use set-up-environment action in pages workflow --- .github/workflows/pages.yml | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml index d8c8c5b6..f01675f6 100644 --- a/.github/workflows/pages.yml +++ b/.github/workflows/pages.yml @@ -3,7 +3,7 @@ name: Deploy estimator Pages on: # Runs on pushes targeting the default branch push: - branches: ["main"] + branches: ['main'] # Allows you to run this workflow manually from the Actions tab workflow_dispatch: @@ -17,7 +17,7 @@ permissions: # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. # However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. concurrency: - group: "pages" + group: 'pages' cancel-in-progress: false jobs: @@ -25,12 +25,10 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - name: Setup Node - uses: actions/setup-node@v4 - with: - node-version: '18' - - run: npm install + - name: Check out code + uses: actions/checkout@v4 + - name: Set up environment + uses: ./.github/actions/set-up-environment - name: Build app run: npm run build - name: Upload artifact From ce8e71f425517f30ae79989027e7af3465e8b78d Mon Sep 17 00:00:00 2001 From: jantoun-scottlogic Date: Wed, 22 May 2024 10:35:40 +0100 Subject: [PATCH 8/9] Add unit tests to deployment pipeline --- .github/workflows/pages.yml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml index f01675f6..8c6f3bd0 100644 --- a/.github/workflows/pages.yml +++ b/.github/workflows/pages.yml @@ -36,12 +36,23 @@ jobs: with: path: ./dist/tech-carbon-estimator + unit_tests: + needs: build + 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 tests + run: npm test + deploy: environment: name: github-pages url: ${{ steps.deployment.outputs.page_url }} runs-on: ubuntu-latest - needs: build + needs: unit_tests steps: - name: Deploy to GitHub Pages id: deployment From 072cfb1b2db8fda903e35b9bd4b699270b56eb3f Mon Sep 17 00:00:00 2001 From: jantoun-scottlogic Date: Wed, 22 May 2024 11:08:36 +0100 Subject: [PATCH 9/9] Add documentation about skipping workflows on pushes to a PR branch --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 8d79339a..39d0a61b 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,10 @@ Run `ng build` to build the project. The build artifacts will be stored in the ` Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). +## GitHub Actions + +The project uses [GitHub Actions](https://docs.github.com/en/actions) to automate certain workflows. One such workflow runs when opening a pull request and pushing changes to the related branch. If you would like to skip running the workflow for a given push to a PR branch there are [various ways](https://docs.github.com/en/actions/managing-workflow-runs/skipping-workflow-runs) this can be achieved. For example, adding `[skip ci]` to the end of the commit message in the push (e.g. `git commit -m "My message [skip ci]"`) will skip running the workflow for that push. + ## Further help To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.