From 87033f6847bd99ef792496050b7bfca7aa6f2160 Mon Sep 17 00:00:00 2001 From: waldronmatt Date: Thu, 18 Apr 2024 19:20:03 -0400 Subject: [PATCH] ci(.github): split out steps into separate actions, consolidate push and pull files --- .github/actions/checkout.yml | 9 ++++ .github/actions/install-deps.yml | 9 ++++ .github/actions/publish.yml | 27 +++++++++++ .github/actions/run-affected.yml | 10 +++++ .github/actions/setup-node.yml | 11 +++++ .github/actions/setup-pnpm.yml | 28 ++++++++++++ .github/workflows/cicd.yml | 46 +++++++++++++++++++ .github/workflows/pull.yml | 58 ------------------------ .github/workflows/push.yml | 77 -------------------------------- 9 files changed, 140 insertions(+), 135 deletions(-) create mode 100644 .github/actions/checkout.yml create mode 100644 .github/actions/install-deps.yml create mode 100644 .github/actions/publish.yml create mode 100644 .github/actions/run-affected.yml create mode 100644 .github/actions/setup-node.yml create mode 100644 .github/actions/setup-pnpm.yml create mode 100644 .github/workflows/cicd.yml delete mode 100644 .github/workflows/pull.yml delete mode 100644 .github/workflows/push.yml diff --git a/.github/actions/checkout.yml b/.github/actions/checkout.yml new file mode 100644 index 00000000..2c74f53b --- /dev/null +++ b/.github/actions/checkout.yml @@ -0,0 +1,9 @@ +name: 'Checkout Code' + +runs: + using: 'composite' + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 diff --git a/.github/actions/install-deps.yml b/.github/actions/install-deps.yml new file mode 100644 index 00000000..2bd93ee7 --- /dev/null +++ b/.github/actions/install-deps.yml @@ -0,0 +1,9 @@ +name: 'Install Playwright and Dependencies' + +runs: + using: 'composite' + steps: + # - name: Install Playwright Browsers + # run: npx playwright install --with-deps + - name: Install dependencies + run: pnpm install diff --git a/.github/actions/publish.yml b/.github/actions/publish.yml new file mode 100644 index 00000000..8b5bd6f7 --- /dev/null +++ b/.github/actions/publish.yml @@ -0,0 +1,27 @@ +name: 'Release' + +inputs: + github-token: + required: true + npm-token: + required: true + +runs: + using: 'composite' + steps: + - name: Config Git User + run: | + git config --global user.name "${{ github.actor }}" + git config --global user.email "${{ github.actor }}@users.noreply.github.com" + env: + GITHUB_TOKEN: ${{ inputs.github-token }} + + - name: NPM Registry Authentication + run: | + npm config set '//registry.npmjs.org/:_authToken' ${{ inputs.npm-token }} + + - name: Bump Versions + run: pnpm version:ci + + - name: Publish Packages + run: pnpm publish:ci diff --git a/.github/actions/run-affected.yml b/.github/actions/run-affected.yml new file mode 100644 index 00000000..478f5288 --- /dev/null +++ b/.github/actions/run-affected.yml @@ -0,0 +1,10 @@ +name: 'Run NX Affected' + +runs: + using: 'composite' + steps: + - name: NX Affected + uses: nrwl/nx-set-shas@v4 + + - name: Build, Lint, Test + run: npx nx affected -t build,lint,test --parallel=3 diff --git a/.github/actions/setup-node.yml b/.github/actions/setup-node.yml new file mode 100644 index 00000000..c0e0b8d7 --- /dev/null +++ b/.github/actions/setup-node.yml @@ -0,0 +1,11 @@ +name: 'Setup Node.js' +inputs: + node-version: + required: true +runs: + using: 'composite' + steps: + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: ${{ inputs.node-version }} diff --git a/.github/actions/setup-pnpm.yml b/.github/actions/setup-pnpm.yml new file mode 100644 index 00000000..e4131c72 --- /dev/null +++ b/.github/actions/setup-pnpm.yml @@ -0,0 +1,28 @@ +name: 'Setup pnpm and Cache' + +inputs: + pnpm-version: + required: true + +runs: + using: 'composite' + steps: + - name: Install pnpm + uses: pnpm/action-setup@v2 + with: + version: ${{ inputs.pnpm-version }} + run_install: false + + - name: Get pnpm store directory + id: pnpm-cache + shell: bash + run: | + echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT + + - name: Setup pnpm cache + uses: actions/cache@v4 + with: + path: ${{ steps.pnpm-cache.outputs.STORE_PATH }} + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm-store- diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml new file mode 100644 index 00000000..71f86bf2 --- /dev/null +++ b/.github/workflows/cicd.yml @@ -0,0 +1,46 @@ +name: CICD Workflow + +on: + push: + branches: + - main + pull_request: + branches: + - main + +env: + NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }} + +jobs: + build-and-test: + runs-on: ubuntu-22.04 + strategy: + matrix: + node-version: [20] + pnpm-version: [8] + steps: + - name: Checkout Code + uses: waldronmatt/groundwork/.github/actions/checkout.yml + + - name: Setup Node.js + uses: waldronmatt/groundwork/.github/actions/setup-node.yml + with: + node-version: ${{ matrix.node-version }} + + - name: Setup pnpm and Cache + uses: waldronmatt/groundwork/.github/actions/setup-pnpm.yml + with: + pnpm-version: ${{ matrix.pnpm-version }} + + - name: Install Playwright and Dependencies + uses: waldronmatt/groundwork/.github/actions/install-deps.yml + + - name: Run NX Affected Commands + uses: waldronmatt/groundwork/.github/actions/run-affected.yml + + - name: Publish Packages + if: github.event_name == 'push' + uses: waldronmatt/groundwork/.github/actions/publish.yml + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + npm-token: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/pull.yml b/.github/workflows/pull.yml deleted file mode 100644 index 890e77e5..00000000 --- a/.github/workflows/pull.yml +++ /dev/null @@ -1,58 +0,0 @@ -name: Pull -on: - pull_request: - branches: - - main - -env: - NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }} - -jobs: - setup: - runs-on: ubuntu-22.04 - strategy: - matrix: - node-version: [18] - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Install Node.js - uses: actions/setup-node@v4 - with: - node-version: ${{ matrix.node-version }} - - - name: Install pnpm - uses: pnpm/action-setup@v2 - id: pnpm-install - with: - version: 7 - run_install: false - - - name: Get pnpm store directory - id: pnpm-cache - shell: bash - run: | - echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT - - - name: Setup pnpm cache - uses: actions/cache@v4 - with: - path: ${{ steps.pnpm-cache.outputs.STORE_PATH }} - key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} - restore-keys: | - ${{ runner.os }}-pnpm-store- - - - name: Install dependencies - run: pnpm bootstrap:ci - - # - name: Install Playwright Browsers - # run: npx playwright install --with-deps - - - name: NX Affected - uses: nrwl/nx-set-shas@v4 - - - name: Build, Lint, Test - run: npx nx affected -t build,lint,test --parallel=3 diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml deleted file mode 100644 index ce066632..00000000 --- a/.github/workflows/push.yml +++ /dev/null @@ -1,77 +0,0 @@ -name: Push -on: - push: - branches: - - main - -env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }} - -jobs: - setup: - runs-on: ubuntu-22.04 - strategy: - matrix: - node-version: [18] - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Install Node.js - uses: actions/setup-node@v4 - with: - node-version: ${{ matrix.node-version }} - - - name: Install pnpm - uses: pnpm/action-setup@v2 - id: pnpm-install - with: - version: 7 - run_install: false - - - name: Get pnpm store directory - id: pnpm-cache - shell: bash - run: | - echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT - - - name: Setup pnpm cache - uses: actions/cache@v4 - with: - path: ${{ steps.pnpm-cache.outputs.STORE_PATH }} - key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} - restore-keys: | - ${{ runner.os }}-pnpm-store- - - - name: Install dependencies - run: pnpm bootstrap:ci - - # - name: Install Playwright Browsers - # run: npx playwright install --with-deps - - - name: NX Affected - uses: nrwl/nx-set-shas@v4 - - - name: Build, Lint, Test - run: npx nx affected -t build,lint,test --parallel=3 - - - name: Config Git User - run: | - git config --global user.name "${{ github.actor }}" - git config --global user.email "${{ github.actor }}@users.noreply.github.com" - - - name: NPM Registry Authentication - run: | - npm config set '//registry.npmjs.org/:_authToken' "${NPM_TOKEN}" - - - name: Bump Versions - run: | - pnpm version:ci - - - name: Publish Packages - run: | - pnpm publish:ci