From 4a8ad420ba73ee146ca5142fc1b28b3d18da45c3 Mon Sep 17 00:00:00 2001 From: jantoun-scottlogic <110816538+jantoun-scottlogic@users.noreply.github.com> Date: Fri, 24 May 2024 10:11:58 +0100 Subject: [PATCH] SFD-89 Create merge pipeline (#60) * 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 --- .github/actions/set-up-environment/action.yml | 17 ++++++++++++ .github/workflows/pages.yml | 27 ++++++++++++------- .github/workflows/pull-request.yml | 23 ++++++++++++++++ README.md | 4 +++ 4 files changed, 62 insertions(+), 9 deletions(-) create mode 100644 .github/actions/set-up-environment/action.yml create mode 100644 .github/workflows/pull-request.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/pages.yml b/.github/workflows/pages.yml index d8c8c5b6..8c6f3bd0 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 @@ -38,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 diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml new file mode 100644 index 00000000..65b245fd --- /dev/null +++ b/.github/workflows/pull-request.yml @@ -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 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.