From 585d7fe457c16aab999d7f7d3cfddbdc694c605e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=A5=E6=B5=A9?= Date: Mon, 30 Sep 2024 21:33:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20CI=20=E5=B7=A5=E4=BD=9C?= =?UTF-8?q?=E6=B5=81=EF=BC=8C=E6=9B=BF=E6=8D=A2=20setup-node-pnpm-install?= =?UTF-8?q?=20=E4=B8=BA=20setup-node-environment=EF=BC=8C=E5=B9=B6?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=9B=B8=E5=BA=94=E7=9A=84=20action.yml=20?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 3 +- setup-node-environment/action.yml | 52 ++++++++++++++++++++++++++++++ setup-node-pnpm-install/action.yml | 42 ------------------------ 3 files changed, 54 insertions(+), 43 deletions(-) create mode 100644 setup-node-environment/action.yml delete mode 100644 setup-node-pnpm-install/action.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f8248ae..ce98f95 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,12 +6,13 @@ jobs: another-job: runs-on: ubuntu-latest steps: - - uses: yanhao98/composite-actions/setup-node-pnpm-install@main + - uses: yanhao98/composite-actions/setup-node-environment@main - name: Check Node and PNPM versions run: | set -x node --version pnpm --version + which pnpm date pwd ls -al \ No newline at end of file diff --git a/setup-node-environment/action.yml b/setup-node-environment/action.yml new file mode 100644 index 0000000..462cbb8 --- /dev/null +++ b/setup-node-environment/action.yml @@ -0,0 +1,52 @@ +# ๐Ÿ”— Links: +# Source file: https://github.com/obytes/react-native-template-obytes/blob/master/.github/actions/setup-node-pnpm-install/action.yml +# Composite actions docs: https://docs.github.com/en/actions/creating-actions/creating-a-composite-action + +# โœ๏ธ Description: +# This is a composite action, which means it can be used in other actions. +# It is used in almost all workflows to set up the environment and install dependencies. +# Updating the package manager or Node version here will be reflected in all workflows. + +# ๐Ÿ‘€ Example usage: +# - name : ๐Ÿ“ฆ Setup Node + PNPM + install deps +# uses: ./.github/actions/setup-node-pnpm-install + +name: "Setup Node Environment" +description: "Setup Node + PNPM + Install Dependencies" +runs: + using: "composite" + steps: + - uses: actions/checkout@main + with: + # fetch-depth: 0 # zero stands for full checkout, which is required for semantic-release + filter: blob:none # we don't need all blobs, only the full tree + show-progress: false + + - name: Prepare data + shell: bash + id: prepare + run: | + # Check package manager + packageManager=$(jq -r '.packageManager' package.json) + echo "packageManager: $packageManager" + if [[ "$packageManager" == "pnpm"* ]]; then + echo "pnpm detected: $packageManager" + echo "setup-pnpm=true" >> $GITHUB_OUTPUT + fi + + # Check if pnpm-lock.yaml exists + if [[ -f "pnpm-lock.yaml" ]]; then + echo "pnpm-lock.yaml exists" + echo "pnpm-lock-exists=true" >> $GITHUB_OUTPUT + fi + + - uses: pnpm/action-setup@v4 # https://github.com/pnpm/action-setup?tab=readme-ov-file#inputs + if: steps.prepare.outputs.setup-pnpm == 'true' + - uses: actions/setup-node@v4 # https://github.com/actions/setup-node?tab=readme-ov-file#usage + with: + node-version: lts/* + # cache: 'pnpm' # TODO: ๅˆคๆ–ญๆ˜ฏๅฆๆœ‰pnpm-lock.yamlๆ–‡ไปถ๏ผŒๆœ‰ๅˆ™ๅฏ็”จ็ผ“ๅญ˜ + - name: ๐Ÿ“ฆ Install Project Dependencies + if: steps.prepare.outputs.pnpm-lock-exists == 'true' + run: pnpm install --frozen-lockfile + shell: bash diff --git a/setup-node-pnpm-install/action.yml b/setup-node-pnpm-install/action.yml deleted file mode 100644 index e849051..0000000 --- a/setup-node-pnpm-install/action.yml +++ /dev/null @@ -1,42 +0,0 @@ -# ๐Ÿ”— Links: -# Source file: https://github.com/obytes/react-native-template-obytes/blob/master/.github/actions/setup-node-pnpm-install/action.yml -# Composite actions docs: https://docs.github.com/en/actions/creating-actions/creating-a-composite-action - -# โœ๏ธ Description: -# This is a composite action, which means it can be used in other actions. -# It is used in almost all workflows to set up the environment and install dependencies. -# Updating the package manager or Node version here will be reflected in all workflows. - -# ๐Ÿ‘€ Example usage: -# - name : ๐Ÿ“ฆ Setup Node + PNPM + install deps -# uses: ./.github/actions/setup-node-pnpm-install - -name: "Setup Node + PNPM + Install Dependencies" -description: "Setup Node + PNPM + Install Dependencies" -runs: - using: "composite" - steps: - - uses: actions/checkout@main - with: - # fetch-depth: 0 # zero stands for full checkout, which is required for semantic-release - filter: blob:none # we don't need all blobs, only the full tree - show-progress: false - - uses: pnpm/action-setup@v4 - with: - # version: latest - run_install: false - - uses: actions/setup-node@v4 - with: - node-version: lts/* - # cache: 'pnpm' - # - name: Check Node and PNPM versions - # shell: bash - # run: | - # set -x - # node --version - # pnpm --version - # pwd - # ls -al - # - name: ๐Ÿ“ฆ Install Project Dependencies - # run: pnpm install --frozen-lockfile - # shell: bash