Skip to content

Commit

Permalink
Merge branch 'mrc-6018' of github.com:mrc-ide/wodin into mrc-6021
Browse files Browse the repository at this point in the history
  • Loading branch information
M-Kusumgar committed Dec 3, 2024
2 parents 748c80f + c55d5a8 commit c42b13b
Show file tree
Hide file tree
Showing 10 changed files with 200 additions and 182 deletions.
15 changes: 15 additions & 0 deletions .github/actions/build-and-run-wodin/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Build and run WODIN (and deps)

runs:
using: "composite"
steps:
- uses: actions/setup-node@v4
with:
node-version: 20

- name: Build and run server
shell: bash
run: |
./scripts/build.sh
./scripts/run-dependencies.sh
npm run serve --prefix=app/server &
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
name: Setup Node, Env and login to GHCR
name: Setup CI Env and login to GHCR

inputs:
install-packages:
required: false
default: 'false'
build-and-run-server:
required: false
default: 'false'
ghcr-username:
required: false
default: ''
required: true
ghcr-password:
required: false
default: ''
required: true

outputs:
CI_SHA:
Expand All @@ -25,13 +17,6 @@ outputs:
runs:
using: "composite"
steps:
- name: Login to GHCR (GitHub Packages)
if: inputs.ghcr-username != '' && inputs.ghcr-password != ''
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ inputs.ghcr-username }}
password: ${{ inputs.ghcr-password }}
- id: ci-env
name: Setup Environment
shell: bash
Expand All @@ -46,22 +31,9 @@ runs:
fi
echo "CI_SHA=${long_sha:0:7}" >> $GITHUB_OUTPUT
- uses: actions/setup-node@v4
- name: Login to GHCR (GitHub Packages)
uses: docker/login-action@v3
with:
node-version: 20

- name: Install packages
# we install in the build script anyway so skip if build-and-run-server
if: inputs.install-packages == 'true' && inputs.build-and-run-server != 'true'
shell: bash
run: |
npm i --prefix=app/server
npm i --prefix=app/static
- name: Build and run server
if: inputs.build-and-run-server == 'true'
shell: bash
run: |
./scripts/build.sh
./scripts/run-dependencies.sh
npm run serve --prefix=app/server &
registry: ghcr.io
username: ${{ inputs.ghcr-username }}
password: ${{ inputs.ghcr-password }}
28 changes: 28 additions & 0 deletions .github/actions/install-npm-packages/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Install NPM packages

inputs:
server:
required: false
default: 'false'
static:
required: false
default: 'false'

runs:
using: "composite"
steps:
- uses: actions/setup-node@v4
with:
node-version: 20

- name: Install server (backend) NPM packages
if: inputs.server == 'true'
shell: bash
run: |
npm ci --prefix=app/server
- name: Install static (frontend) NPM packages
if: inputs.static == 'true'
shell: bash
run: |
npm ci --prefix=app/static
135 changes: 135 additions & 0 deletions .github/workflows/build-test-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
name: CI

on: [push]

env:
TAG_GHCR: mrc-ide/wodin

jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- id: ci-env
uses: ./.github/actions/ci-env-and-ghcr-login
with:
ghcr-username: ${{ github.actor }}
ghcr-password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push docker
uses: docker/build-push-action@v5
with:
file: ./docker/Dockerfile
push: true
tags: |
ghcr.io/${{ env.TAG_GHCR }}:${{ steps.ci-env.outputs.CI_SHA }}
ghcr.io/${{ env.TAG_GHCR }}:${{ steps.ci-env.outputs.CI_BRANCH }}
- name: Smoke test
run: |
./scripts/run-version.sh --app ${{ steps.ci-env.outputs.CI_BRANCH }} &
./scripts/smoke-test.sh
fe-unit-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/install-npm-packages
with:
static: true

- name: Test front end
run: npm run coverage --prefix=app/static
- uses: codecov/codecov-action@v4
with:
fail_ci_if_error: true
files: ./app/static/coverage/coverage-final.json
token: ${{ secrets.CODECOV_TOKEN }}
codecov_yml_path: ./codecov.yml

be-unit-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/build-and-run-wodin

- name: Test back end
run: npm run coverage --prefix=app/server
- name: Check versions
run: npm run genversion --prefix=app/server -- --check-only
- uses: codecov/codecov-action@v4
with:
fail_ci_if_error: true # optional (default = false)
files: ./app/server/coverage/coverage-final.json
token: ${{ secrets.CODECOV_TOKEN }} # required

integration-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/build-and-run-wodin

- name: Test back end integration
run: npm run test:integration --prefix=app/server

playwright-tests:
runs-on: ubuntu-latest
strategy:
matrix:
shard: [1, 2, 3, 4, 5, 6]
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/build-and-run-wodin

- name: Get installed Playwright version
run: echo "PLAYWRIGHT_VERSION=$(node -e "console.log(require('./app/static/package-lock.json').packages['node_modules/@playwright/test'].version)")" >> $GITHUB_ENV
- name: Cache binaries for playwright version
uses: actions/cache@v4
id: playwright-cache
with:
path: |
~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ env.PLAYWRIGHT_VERSION }}
- name: Install Playwright Browsers
if: steps.playwright-cache.outputs.cache-hit != 'true'
run: npx playwright@${{ env.PLAYWRIGHT_VERSION }} install --with-deps
- name: Test e2e
run: npm run test:e2e --prefix=app/static -- --shard=${{ matrix.shard }}/6

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/install-npm-packages
with:
static: true
server: true

- name: Lint back end
run: npm run lint --prefix=app/server
- name: Lint front end
run: npm run lint --prefix=app/static

publish-latest-image:
runs-on: ubuntu-latest
# change this ref to publish to "latest" tag from another branch
if: github.ref == 'refs/heads/main'
needs: [build-and-push, fe-unit-tests, be-unit-tests, integration-tests, playwright-tests, lint]
steps:
- uses: actions/checkout@v4
- id: ci-env
uses: ./.github/actions/ci-env-and-ghcr-login
with:
ghcr-username: ${{ github.actor }}
ghcr-password: ${{ secrets.GITHUB_TOKEN }}

- name: Publish image manifest to latest
run: |
GHCR_TOKEN=$(echo ${{ secrets.GITHUB_TOKEN }} | base64)
curl "https://ghcr.io/v2/mrc-ide/wodin/manifests/${{ steps.ci-env.outputs.CI_BRANCH }}" \
-H "accept: application/vnd.docker.distribution.manifest.v2+json" \
-H "Authorization: Bearer ${GHCR_TOKEN}" \
> manifest.json
curl -XPUT "https://ghcr.io/v2/mrc-ide/wodin/manifests/latest" \
-H "content-type: application/vnd.docker.distribution.manifest.v2+json" \
-H "Authorization: Bearer ${GHCR_TOKEN}" \
-d '@manifest.json'
31 changes: 0 additions & 31 deletions .github/workflows/build.yml

This file was deleted.

95 changes: 0 additions & 95 deletions .github/workflows/test.yml

This file was deleted.

2 changes: 0 additions & 2 deletions app/static/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ export default defineConfig({
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 1,
/* Opt out of parallel tests on CI. */
// workers: process.env.CI ? 1 : undefined,
fullyParallel: true,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
// reporter: 'html',
Expand Down
Loading

0 comments on commit c42b13b

Please sign in to comment.