Skip to content

Commit

Permalink
SFD-89 Create merge pipeline (#60)
Browse files Browse the repository at this point in the history
* Add merge pipeline

* Add build job

* Add build dependency to unit_tests job

* Add dependency caching

* Cache ~/.npm rather than node_modules

* Move environment setup to custom action

* Use set-up-environment action in pages workflow

* Add unit tests to deployment pipeline

* Add documentation about skipping workflows on pushes to a PR branch
  • Loading branch information
jantoun-scottlogic authored May 24, 2024
1 parent 2e7022a commit 4a8ad42
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 9 deletions.
17 changes: 17 additions & 0 deletions .github/actions/set-up-environment/action.yml
Original file line number Diff line number Diff line change
@@ -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
27 changes: 18 additions & 9 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -17,33 +17,42 @@ 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:
# Build job
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
uses: actions/upload-pages-artifact@v3
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
Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: PR Workflow
on: pull_request

jobs:
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: Build app
run: npm run build
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 4a8ad42

Please sign in to comment.