From dfbc674c2a4dc7d505eef5f33a0043fbe01d368a Mon Sep 17 00:00:00 2001 From: Albert Hernandez Pellicer Date: Sat, 24 Feb 2024 15:34:15 +0100 Subject: [PATCH 1/6] ci: reuse setup node action --- .github/actions/setup-node/action.yml | 31 +++++++++++++++++++++++++++ .github/workflows/node.yml | 14 ++---------- .github/workflows/release.yml | 25 +-------------------- 3 files changed, 34 insertions(+), 36 deletions(-) create mode 100644 .github/actions/setup-node/action.yml diff --git a/.github/actions/setup-node/action.yml b/.github/actions/setup-node/action.yml new file mode 100644 index 00000000..f05ee03e --- /dev/null +++ b/.github/actions/setup-node/action.yml @@ -0,0 +1,31 @@ +--- +name: 'Setup node' + +inputs: + version: + description: 'Node version to use' + required: false + type: string + default: '20' + +runs: + using: "composite" + steps: + - name: Authenticate npm 🔑 + if: steps.changelog.outputs.tag + run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc + - name: Cache Dependencies ⌛️ + uses: actions/cache@v4 + id: cache-node-modules + with: + path: 'node_modules' + key: ${{ runner.os }}-node_modules-${{ hashFiles('package*.json') }}-${{ hashFiles('.github/actions/setup-node/action.yml') }}-node-${{ inputs.version }} + - name: Setup Node ⚙️ + uses: actions/setup-node@v4 + with: + node-version: ${{ inputs.version }} + cache: npm + - name: Install dependencies 📥 + if: steps.cache-node-modules.outputs.cache-hit != 'true' + shell: bash + run: npm ci diff --git a/.github/workflows/node.yml b/.github/workflows/node.yml index a024acc2..011b646b 100644 --- a/.github/workflows/node.yml +++ b/.github/workflows/node.yml @@ -16,20 +16,10 @@ jobs: steps: - name: Checkout 🛬 uses: actions/checkout@v4 - - name: Cache Dependencies ⌛️ - uses: actions/cache@v4 - id: cache-node-modules - with: - path: 'node_modules' - key: ${{ runner.os }}-node_modules-${{ hashFiles('package*.json') }}-${{ hashFiles('.github/workflows/node.yml') }}-node-${{ matrix.node-version }} - name: Setup Node ⚙️ - uses: actions/setup-node@v4 + uses: ./.github/actions/setup-node with: - node-version: ${{ matrix.node-version }} - cache: npm - - name: Install dependencies 📥 - if: steps.cache-node-modules.outputs.cache-hit != 'true' - run: npm ci + version: ${{ matrix.node-version }} - name: Build typescript 📦 run: npm run build && find dist/index.js - name: Lint code 💅 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9a7b18bd..29e27b5f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -37,31 +37,8 @@ jobs: git push -f origin $major git push -f origin $minor - - name: Release 🚀 - if: steps.changelog.outputs.tag - uses: softprops/action-gh-release@v1 - with: - tag_name: ${{ steps.changelog.outputs.tag }} - body: ${{ steps.changelog.outputs.clean_changelog }} - token: ${{ secrets.GITHUB_TOKEN }} - - name: Cache Dependencies ⌛️ - if: steps.changelog.outputs.tag - uses: actions/cache@v4 - id: cache-node-modules - with: - path: 'node_modules' - key: ${{ runner.os }}-node_modules-${{ hashFiles('package*.json') }}-${{ hashFiles('.github/workflows/release.yml') }}-node-20.9 - - name: Authenticate npm 🔑 - if: steps.changelog.outputs.tag - run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc - name: Setup Node ⚙️ - if: ${{ steps.release.outputs.release_created }} - uses: actions/setup-node@v4 - with: - node-version-file: '.nvmrc' - - name: Install dependencies 📥 - if: steps.changelog.outputs.tag - run: npm ci + uses: ./.github/actions/setup-node - name: Publish to NPM 🚀 if: steps.changelog.outputs.tag run: npm publish From c08d1ee36ec65f79883deb0e099a5a34594648e5 Mon Sep 17 00:00:00 2001 From: Albert Hernandez Pellicer Date: Sat, 24 Feb 2024 15:36:03 +0100 Subject: [PATCH 2/6] ci: fix yml lint issue --- .yamllint.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.yamllint.yml b/.yamllint.yml index 9e5d47ad..27bbb2df 100644 --- a/.yamllint.yml +++ b/.yamllint.yml @@ -11,6 +11,7 @@ rules: /.github/workflows/*.yaml /.github/workflows/*.yml /.github/settings.yml + /.github/actions/setup-node/action.yml truthy: ignore: | /.github/workflows/*.yaml From eca23e5f775d145b33f4b7f0645e4eb079ff1c82 Mon Sep 17 00:00:00 2001 From: Albert Hernandez Pellicer Date: Sat, 24 Feb 2024 15:37:54 +0100 Subject: [PATCH 3/6] ci: add shell --- .github/actions/setup-node/action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/actions/setup-node/action.yml b/.github/actions/setup-node/action.yml index f05ee03e..3b4b57ec 100644 --- a/.github/actions/setup-node/action.yml +++ b/.github/actions/setup-node/action.yml @@ -13,6 +13,7 @@ runs: steps: - name: Authenticate npm 🔑 if: steps.changelog.outputs.tag + shell: bash run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc - name: Cache Dependencies ⌛️ uses: actions/cache@v4 From 815d4add5bc33f30923f39608b4fb7c504c048d6 Mon Sep 17 00:00:00 2001 From: Albert Hernandez Pellicer Date: Sat, 24 Feb 2024 15:39:59 +0100 Subject: [PATCH 4/6] ci: propagate npm token as input --- .github/actions/setup-node/action.yml | 6 +++++- .github/workflows/node.yml | 1 + .github/workflows/release.yml | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/actions/setup-node/action.yml b/.github/actions/setup-node/action.yml index 3b4b57ec..7d0a5ca5 100644 --- a/.github/actions/setup-node/action.yml +++ b/.github/actions/setup-node/action.yml @@ -7,6 +7,10 @@ inputs: required: false type: string default: '20' + npm_token: + description: 'NPM Token' + required: true + type: string runs: using: "composite" @@ -14,7 +18,7 @@ runs: - name: Authenticate npm 🔑 if: steps.changelog.outputs.tag shell: bash - run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc + run: echo "//registry.npmjs.org/:_authToken=${{ inputs.npm_token }}" > ~/.npmrc - name: Cache Dependencies ⌛️ uses: actions/cache@v4 id: cache-node-modules diff --git a/.github/workflows/node.yml b/.github/workflows/node.yml index 011b646b..ba2976dd 100644 --- a/.github/workflows/node.yml +++ b/.github/workflows/node.yml @@ -20,6 +20,7 @@ jobs: uses: ./.github/actions/setup-node with: version: ${{ matrix.node-version }} + npm_token: ${{ secrets.NPM_TOKEN }} - name: Build typescript 📦 run: npm run build && find dist/index.js - name: Lint code 💅 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 29e27b5f..eb8a651d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -39,6 +39,8 @@ jobs: git push -f origin $minor - name: Setup Node ⚙️ uses: ./.github/actions/setup-node + with: + npm_token: ${{ secrets.NPM_TOKEN }} - name: Publish to NPM 🚀 if: steps.changelog.outputs.tag run: npm publish From 639f0b0ce0e70d441de1c3c41a076e7c7eba4470 Mon Sep 17 00:00:00 2001 From: Albert Hernandez Pellicer Date: Sat, 24 Feb 2024 15:41:32 +0100 Subject: [PATCH 5/6] ci: remove if condition --- .github/actions/setup-node/action.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/actions/setup-node/action.yml b/.github/actions/setup-node/action.yml index 7d0a5ca5..d41df40e 100644 --- a/.github/actions/setup-node/action.yml +++ b/.github/actions/setup-node/action.yml @@ -16,7 +16,6 @@ runs: using: "composite" steps: - name: Authenticate npm 🔑 - if: steps.changelog.outputs.tag shell: bash run: echo "//registry.npmjs.org/:_authToken=${{ inputs.npm_token }}" > ~/.npmrc - name: Cache Dependencies ⌛️ From 6b25081baef2c2a79aa74abac726d7ad3b1bf966 Mon Sep 17 00:00:00 2001 From: Albert Hernandez Pellicer Date: Sat, 24 Feb 2024 15:41:55 +0100 Subject: [PATCH 6/6] ci: just setup node if there was a tag --- .github/workflows/release.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index eb8a651d..8da6f33c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -38,6 +38,7 @@ jobs: git push -f origin $major git push -f origin $minor - name: Setup Node ⚙️ + if: steps.changelog.outputs.tag uses: ./.github/actions/setup-node with: npm_token: ${{ secrets.NPM_TOKEN }}