From 4ebb932961b7e9acec7ee037b5d60401e4c74ae5 Mon Sep 17 00:00:00 2001 From: evansmj Date: Sun, 9 Mar 2025 17:54:44 -0400 Subject: [PATCH] Add pull request pipeline Add test workflow to Artifact, Pull Request, and Build and publish workflows. Refactor build steps into build.yml --- .github/workflows/build.yml | 53 ++++++++++++++++++++++++++++++++++++ .github/workflows/ci.yml | 51 ++++------------------------------ .github/workflows/github.yml | 4 +++ .github/workflows/pr.yml | 12 ++++++++ .github/workflows/test.yml | 37 +++++++++++++++++++++++++ 5 files changed, 111 insertions(+), 46 deletions(-) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/pr.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..ec162a69 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,53 @@ +name: Build + +on: + workflow_call: + +jobs: + build: + runs-on: ubuntu-22.04 + steps: + - name: Checkout source code + uses: actions/checkout@v3 + + - name: Setup Node + uses: actions/setup-node@v3 + with: + node-version: 18.x + + - name: Get version from package.json + id: package-version + run: | + echo "VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_ENV + echo "Project Version: $VERSION" + + - name: Cache node_modules + uses: actions/cache@v3 + id: cache-npm-packages + with: + path: node_modules + key: ${{ runner.OS }}-build-${{ hashFiles('**/package-lock.json') }} + + - name: Install NPM dependencies + if: steps.cache-npm-packages.outputs.cache-hit != 'true' + run: npm clean-install + + - name: Cache build frontend + uses: actions/cache@v3 + id: cache-build-frontend + with: + path: apps/frontend + key: ${{ runner.os }}-frontend-${{ github.sha }} + + - name: Run build production application + run: npm run frontend:build + + - name: Cache build backend + uses: actions/cache@v3 + id: cache-build-backend + with: + path: apps/backend + key: ${{ runner.os }}-backend-${{ github.sha }} + + - name: Run build backend server + run: npm run backend:build diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4d851528..f3e3a397 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,53 +12,12 @@ env: CI: false jobs: + test: + uses: ./.github/workflows/test.yml + build: - runs-on: ubuntu-22.04 - steps: - - name: Checkout source code - uses: actions/checkout@v3 - - - name: Setup Node - uses: actions/setup-node@v3 - with: - node-version: 18.x - - - name: Get version from package.json - id: package-version - run: | - echo "VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_ENV - echo "Project Version: $VERSION" - - - name: Cache node_modules - uses: actions/cache@v3 - id: cache-npm-packages - with: - path: node_modules - key: ${{ runner.OS }}-build-${{ hashFiles('**/package-lock.json') }} - - - name: Install NPM dependencies - if: steps.cache-npm-packages.outputs.cache-hit != 'true' - run: npm clean-install - - - name: Cache build frontend - uses: actions/cache@v3 - id: cache-build-frontend - with: - path: apps/frontend - key: ${{ runner.os }}-frontend-${{ github.sha }} - - - name: Run build production application - run: npm run frontend:build - - - name: Cache build backend - uses: actions/cache@v3 - id: cache-build-backend - with: - path: apps/backend - key: ${{ runner.os }}-backend-${{ github.sha }} - - - name: Run build backend server - run: npm run backend:build + uses: ./.github/workflows/build.yml + needs: test deploy: runs-on: ubuntu-22.04 diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index e3c58b72..b23308e8 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -9,9 +9,13 @@ on: workflow_dispatch: jobs: + test: + uses: ./.github/workflows/test.yml + build: name: Build image runs-on: ubuntu-22.04 + needs: test steps: - name: Set env variables diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml new file mode 100644 index 00000000..1a59f674 --- /dev/null +++ b/.github/workflows/pr.yml @@ -0,0 +1,12 @@ +name: Pull Request checks + +on: + pull_request: + +jobs: + build: + uses: ./.github/workflows/build.yml + + test: + uses: ./.github/workflows/test.yml + diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..e42e0f41 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,37 @@ +name: Unit tests + +on: + workflow_call: + +jobs: + test: + runs-on: ubuntu-22.04 + steps: + - name: Checkout source code + uses: actions/checkout@v3 + + - name: Setup Node + uses: actions/setup-node@v3 + with: + node-version: 18.x + + - name: Get version from package.json + id: package-version + run: | + echo "VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_ENV + echo "Project Version: $VERSION" + + - name: Cache node_modules + uses: actions/cache@v3 + id: cache-npm-packages + with: + path: node_modules + key: ${{ runner.OS }}-build-${{ hashFiles('**/package-lock.json') }} + + - name: Install NPM dependencies + if: steps.cache-npm-packages.outputs.cache-hit != 'true' + run: npm clean-install + + - name: Run frontend unit tests + run: npm run frontend:test +