From 5c6c4cb9cac23256bf046445f256bb9442f9a602 Mon Sep 17 00:00:00 2001 From: uiolee <22849383+uiolee@users.noreply.github.com> Date: Mon, 1 Jan 2024 23:31:41 +0800 Subject: [PATCH] ci: improve test, build --- .github/workflows/build.yml | 71 +++++++++++++++++++++++++++++++++++++ .github/workflows/ci.yml | 71 ++++++------------------------------- 2 files changed, 82 insertions(+), 60 deletions(-) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..cfd1ee9 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,71 @@ +on: + workflow_call: + inputs: + cache: + description: "(boolean) use actions/cache" + required: false + default: true + type: boolean + node_version: + description: "(string) " + required: false + default: "lts/*" + type: string + runs_on: + description: "(string) " + required: false + default: "ubuntu-latest" + type: string + +env: + CI: true + +jobs: + build: + runs-on: ${{ inputs.runs_on }} + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version: ${{ inputs.node_version }} + + - uses: pnpm/action-setup@v2 + name: Install pnpm + with: + version: 8 + + - name: Get pnpm store directory + shell: bash + run: | + echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV + + - uses: actions/cache@v3 + name: Setup pnpm cache + if: ${{ inputs.cache }} + with: + path: | + ${{ env.STORE_PATH }} + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm-store- + + - name: Install Dependencies + run: pnpm i + + - name: Build + run: | + pnpm esb + + - name: pack + run: | + npm pack + + - uses: actions/upload-artifact@v4 + with: + retention-days: 1 + compression-level: 1 + name: artifact + path: | + bin + *.tgz diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 863dc58..f31e27d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -56,9 +56,12 @@ jobs: run: | pnpm run lint + build: + uses: ./.github/workflows/build.yml + test-ve: + needs: build runs-on: ${{ matrix.os }} - name: test (${{ matrix.pm }}, ${{ matrix.os }}) services: verdaccio: image: verdaccio/verdaccio:5 @@ -75,35 +78,13 @@ jobs: with: submodules: "recursive" - - uses: actions/setup-node@v4 - with: - node-version: "lts/*" - - - uses: pnpm/action-setup@v2 - name: Install pnpm + - uses: actions/download-artifact@v4 with: - version: 8 + name: artifact - - name: Get pnpm store directory - shell: bash - run: | - echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV - - - uses: actions/cache@v3 - name: Setup pnpm cache + - uses: actions/setup-node@v4 with: - path: | - ${{ env.STORE_PATH }} - key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} - restore-keys: | - ${{ runner.os }}-pnpm-store- - - - name: Install Dependencies - run: pnpm i - - - name: build - run: | - pnpm esb + node-version: "lts/*" - name: login to verdaccio run: npx npm-cli-login -u test -p 1234 -e test@domain.test -r http://localhost:4873 @@ -124,8 +105,8 @@ jobs: ${{ matrix.pm }} create hexo test-ln: + needs: build runs-on: ${{ matrix.os }} - name: test (${{ matrix.pm }}, ${{ matrix.os }}) strategy: matrix: os: [windows-latest, macos-latest] @@ -133,44 +114,14 @@ jobs: fail-fast: false steps: - - uses: actions/checkout@v4 + - uses: actions/download-artifact@v4 with: - submodules: "recursive" + name: artifact - uses: actions/setup-node@v4 with: node-version: "lts/*" - - uses: pnpm/action-setup@v2 - name: Install pnpm - with: - version: 8 - - - name: Get pnpm store directory - shell: bash - run: | - echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV - - - uses: actions/cache@v3 - name: Setup pnpm cache - with: - path: | - ${{ env.STORE_PATH }} - key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} - restore-keys: | - ${{ runner.os }}-pnpm-store- - - - name: Install Dependencies - run: pnpm i - - - name: build - run: | - pnpm esb - - - name: pack - run: | - npm pack - - name: config for test run: | mkdir ../temp