From 597a7b4f50b24733b2cde800faa455f3aadec36b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n=20Jakub=20Nani=C5=A1ta?= Date: Fri, 5 Jan 2024 14:39:38 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=AA=9A=20Composite=20actions=20(#160)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../actions/install-dependencies/action.yaml | 20 +++++++ .../actions/setup-build-cache/action.yaml | 27 ++++++++++ .../actions/setup-environment/action.yaml | 16 ++++++ .github/workflows/reusable-publish.yaml | 49 +++-------------- .github/workflows/reusable-test.yaml | 53 ++++--------------- 5 files changed, 81 insertions(+), 84 deletions(-) create mode 100644 .github/workflows/actions/install-dependencies/action.yaml create mode 100644 .github/workflows/actions/setup-build-cache/action.yaml create mode 100644 .github/workflows/actions/setup-environment/action.yaml diff --git a/.github/workflows/actions/install-dependencies/action.yaml b/.github/workflows/actions/install-dependencies/action.yaml new file mode 100644 index 000000000..7da873ec5 --- /dev/null +++ b/.github/workflows/actions/install-dependencies/action.yaml @@ -0,0 +1,20 @@ +name: Install project dependencies +description: Install everything we need to build this repo +inputs: + NPM_TOKEN: + description: "NPM_TOKEN that grants permissions to private @layerzerolabs packages" + required: true +runs: + using: "composite" + steps: + # Fetch the dependencies without running the post-install scripts + - name: Fetch Dependencies + shell: bash + run: pnpm fetch --frozen-lockfile --prefer-offline --ignore-scripts + env: + NPM_TOKEN: ${{ inputs.NPM_TOKEN }} + + # Install the dependencies and run the post-install scripts + - name: Install Dependencies + shell: bash + run: pnpm install --frozen-lockfile --offline diff --git a/.github/workflows/actions/setup-build-cache/action.yaml b/.github/workflows/actions/setup-build-cache/action.yaml new file mode 100644 index 000000000..7303607b0 --- /dev/null +++ b/.github/workflows/actions/setup-build-cache/action.yaml @@ -0,0 +1,27 @@ +name: Setup build cache +description: Setup cache for turbo builds & hardhat compilers +runs: + using: "composite" + steps: + # Cache build artifacts from turbo + # + # This step will speed up workflow runs that don't touch the whole codebase + # (or the ones that don't touch the codebase at all) + - name: Cache turbo build setup + uses: actions/cache@v3 + with: + path: node_modules/.cache/turbo + key: ${{ runner.os }}-turbo-${{ github.ref_name }} + restore-keys: | + ${{ runner.os }}-turbo- + + # Cache hardhat compilers + # + # This step will speed up workflow runs that use hardhat compilation + - name: Cache hardhat compilers + uses: actions/cache@v3 + with: + path: .cache/hardhat + key: ${{ runner.os }}-hardhat-${{ github.ref_name }} + restore-keys: | + ${{ runner.os }}-hardhat- diff --git a/.github/workflows/actions/setup-environment/action.yaml b/.github/workflows/actions/setup-environment/action.yaml new file mode 100644 index 000000000..a57c83e2c --- /dev/null +++ b/.github/workflows/actions/setup-environment/action.yaml @@ -0,0 +1,16 @@ +name: Setup environment +description: Setup node & package manager, checkout code +runs: + using: "composite" + steps: + - uses: pnpm/action-setup@v2 + name: Install pnpm + with: + version: 8 + run_install: false + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version-file: ".nvmrc" + cache: "pnpm" diff --git a/.github/workflows/reusable-publish.yaml b/.github/workflows/reusable-publish.yaml index 7d0a967b2..77694e4a9 100644 --- a/.github/workflows/reusable-publish.yaml +++ b/.github/workflows/reusable-publish.yaml @@ -22,52 +22,19 @@ jobs: name: Publish runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - name: Checkout repo + uses: actions/checkout@v3 - - uses: pnpm/action-setup@v2 - name: Install pnpm - with: - version: 8 - run_install: false + - name: Setup environment + uses: ./.github/workflows/actions/setup-environment - - name: Setup Node.js - uses: actions/setup-node@v3 + - name: Install dependencies + uses: ./.github/workflows/actions/install-dependencies with: - node-version-file: ".nvmrc" - cache: "pnpm" - - # Fetch the dependencies without running the post-install scripts - - name: Fetch Dependencies - run: pnpm fetch --frozen-lockfile --prefer-offline --ignore-scripts - env: NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - # Install the dependencies and run the post-install scripts - - name: Install Dependencies - run: pnpm install --frozen-lockfile --offline - - # Cache build artifacts from turbo - # - # This step will speed up workflow runs that don't touch the whole codebase - # (or the ones that don't touch the codebase at all) - - name: Cache turbo build setup - uses: actions/cache@v3 - with: - path: node_modules/.cache/turbo - key: ${{ runner.os }}-turbo-${{ github.ref_name }} - restore-keys: | - ${{ runner.os }}-turbo- - - # Cache hardhat compilers - # - # This step will speed up workflow runs that use hardhat compilation - - name: Cache hardhat compilers - uses: actions/cache@v3 - with: - path: .cache/hardhat - key: ${{ runner.os }}-hardhat-${{ github.ref_name }} - restore-keys: | - ${{ runner.os }}-hardhat- + - name: Setup build cache + uses: ./.github/workflows/actions/setup-build-cache - name: Build run: pnpm build diff --git a/.github/workflows/reusable-test.yaml b/.github/workflows/reusable-test.yaml index 648c00582..546ec30a6 100644 --- a/.github/workflows/reusable-test.yaml +++ b/.github/workflows/reusable-test.yaml @@ -18,56 +18,23 @@ env: NPM_TOKEN: "" jobs: - build-and-test: - name: Build, Lint & Test + build: + name: Build & Lint runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - name: Checkout repo + uses: actions/checkout@v3 - - uses: pnpm/action-setup@v2 - name: Install pnpm - with: - version: 8 - run_install: false + - name: Setup environment + uses: ./.github/workflows/actions/setup-environment - - name: Setup Node.js - uses: actions/setup-node@v3 + - name: Install dependencies + uses: ./.github/workflows/actions/install-dependencies with: - node-version-file: ".nvmrc" - cache: "pnpm" - - # Fetch the dependencies without running the post-install scripts - - name: Fetch Dependencies - run: pnpm fetch --frozen-lockfile --prefer-offline --ignore-scripts - env: NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - # Install the dependencies and run the post-install scripts - - name: Install Dependencies - run: pnpm install --frozen-lockfile --offline - - # Cache build artifacts from turbo - # - # This step will speed up workflow runs that don't touch the whole codebase - # (or the ones that don't touch the codebase at all) - - name: Cache turbo build setup - uses: actions/cache@v3 - with: - path: node_modules/.cache/turbo - key: ${{ runner.os }}-turbo-${{ github.ref_name }} - restore-keys: | - ${{ runner.os }}-turbo- - - # Cache hardhat compilers - # - # This step will speed up workflow runs that use hardhat compilation - - name: Cache hardhat compilers - uses: actions/cache@v3 - with: - path: .cache/hardhat - key: ${{ runner.os }}-hardhat-${{ github.ref_name }} - restore-keys: | - ${{ runner.os }}-hardhat- + - name: Setup build cache + uses: ./.github/workflows/actions/setup-build-cache - name: Lint run: pnpm lint