From 9a865f97e617f53c89b4a2a35272a336641bbd3d Mon Sep 17 00:00:00 2001 From: evansmj Date: Sun, 9 Mar 2025 17:54:44 -0400 Subject: [PATCH 1/2] Create pr workflow Move build job to reusable workflow --- .github/workflows/build.yml | 58 +++++++++++++++++++++++++++++++++++++ .github/workflows/ci.yml | 51 ++------------------------------ .github/workflows/pr.yml | 16 ++++++++++ 3 files changed, 77 insertions(+), 48 deletions(-) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/pr.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..14ba4ce9 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,58 @@ +name: Build + +on: + workflow_call: + inputs: + node-version: + required: false + type: string + default: '18.x' + +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..7067b8b6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,57 +12,12 @@ env: CI: false 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 + run-build: + uses: ./.github/workflows/build-reusable.yml deploy: runs-on: ubuntu-22.04 - needs: build + needs: run-build steps: - name: Checkout source code uses: actions/checkout@v3 diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml new file mode 100644 index 00000000..e4895ac7 --- /dev/null +++ b/.github/workflows/pr.yml @@ -0,0 +1,16 @@ +name: Build and test Pull Request + +on: + pull_request: + +jobs: + run-build: + uses: ./.github/workflows/build-reusable.yml + + test: + runs-on: ubuntu-22.04 + needs: run-build + steps: + - name: Run unit tests + run: npm run frontend:test + From 7045b8caef9451acbaa12e9843ce145a75ae9e99 Mon Sep 17 00:00:00 2001 From: evansmj Date: Sun, 9 Mar 2025 17:54:44 -0400 Subject: [PATCH 2/2] 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 +