From d0f9fa7ee2657fbc77beb69e7bdbb084cbe3661c Mon Sep 17 00:00:00 2001 From: D056966 Date: Mon, 6 Oct 2025 11:30:12 +0200 Subject: [PATCH 1/4] chore(ci): use GitHub Actions --- .github/workflows/_init.yml | 54 ++++++++++++++++++++++++++++++++++ .github/workflows/_release.yml | 46 +++++++++++++++++++++++++++++ .github/workflows/_test.yml | 39 ++++++++++++++++++++++++ .github/workflows/dev.yml | 20 +++++++++++++ .github/workflows/release.yml | 29 ++++++++++++++++++ package.json | 4 +-- 6 files changed, 190 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/_init.yml create mode 100644 .github/workflows/_release.yml create mode 100644 .github/workflows/_test.yml create mode 100644 .github/workflows/dev.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/_init.yml b/.github/workflows/_init.yml new file mode 100644 index 0000000..550a522 --- /dev/null +++ b/.github/workflows/_init.yml @@ -0,0 +1,54 @@ +name: Initialize build + +on: + workflow_call: + outputs: + NODE_VERSION: + value: ${{ jobs.init.outputs.NODE_VERSION }} + NODE_CACHE_KEY: + value: ${{ jobs.init.outputs.NODE_CACHE_KEY }} + +jobs: + init: + name: Initialize build + runs-on: ubuntu-latest + + outputs: + NODE_VERSION: ${{ steps.node-version.outputs.NODE_VERSION }} + NODE_CACHE_KEY: ${{ steps.node-cache-key.outputs.NODE_CACHE_KEY }} + + steps: + - name: Checkout code + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5 + with: + fetch-depth: 0 + + - name: Get node version + id: node-version + run: echo ::set-output name=NODE_VERSION::$(cat .nvmrc) + + - name: Get node cache key + id: node-cache-key + run: echo ::set-output name=NODE_CACHE_KEY::npm-${{ steps.node-version.outputs.NODE_VERSION }}-${{ hashFiles('**/package.json') }} + + - name: Cache dependencies + id: cache-node-modules + uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4 + with: + path: node_modules + key: ${{ steps.node-cache-key.outputs.NODE_CACHE_KEY }} + + - name: Setup node + if: steps.cache-node-modules.outputs.cache-hit != 'true' + uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5 + with: + node-version: ${{ steps.node-version.outputs.NODE_VERSION }} + + - name: Install dependencies + if: steps.cache-node-modules.outputs.cache-hit != 'true' + run: npm install + + - name: Log results + run: | + echo "NODE_VERSION: ${{ steps.node-version.outputs.NODE_VERSION }}" + echo "NODE_CACHE_KEY: ${{ steps.node-cache-key.outputs.NODE_CACHE_KEY }}" diff --git a/.github/workflows/_release.yml b/.github/workflows/_release.yml new file mode 100644 index 0000000..d5ff6c7 --- /dev/null +++ b/.github/workflows/_release.yml @@ -0,0 +1,46 @@ +name: Release package + +on: + workflow_call: + inputs: + NODE_VERSION: + type: string + required: true + NODE_CACHE_KEY: + type: string + required: true + + secrets: + SEMANTIC_RELEASE_NPM_TOKEN: + required: true + SEMANTIC_RELEASE_GH_TOKEN: + required: true + +jobs: + test: + name: Release package + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5 + + - name: Load dependencies from cache + uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4 + with: + path: node_modules + key: ${{ inputs.NODE_CACHE_KEY }} + + - name: Setup node + uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5 + with: + node-version: ${{ inputs.NODE_VERSION }} + + - name: Run build + run: npm run build + + - name: Run release + run: npm run release + env: + NPM_TOKEN: ${{ secrets.SEMANTIC_RELEASE_NPM_TOKEN }} + GH_TOKEN: ${{ secrets.SEMANTIC_RELEASE_GH_TOKEN }} diff --git a/.github/workflows/_test.yml b/.github/workflows/_test.yml new file mode 100644 index 0000000..860012d --- /dev/null +++ b/.github/workflows/_test.yml @@ -0,0 +1,39 @@ +name: Run tests + +on: + workflow_call: + inputs: + NODE_VERSION: + type: string + required: true + NODE_CACHE_KEY: + type: string + required: true + +jobs: + test: + name: Run tests + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + test: [lint, test] + + steps: + - name: Checkout code + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5 + + - name: Load dependencies from cache + uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4 + with: + path: node_modules + key: ${{ inputs.NODE_CACHE_KEY }} + + - name: Setup node + uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5 + with: + node-version: "${{ inputs.NODE_VERSION }}" + + - name: Run ${{ matrix.test }} test + run: npm run ${{ matrix.test }} diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml new file mode 100644 index 0000000..251d40a --- /dev/null +++ b/.github/workflows/dev.yml @@ -0,0 +1,20 @@ +name: Development + +on: + push: + branches: [ '*', '*/*', '**', '!master', '!main' ] + pull_request: + branches: [ master, main ] + +jobs: + init: + name: Init + uses: ./.github/workflows/_init.yml + + test: + name: Test + uses: ./.github/workflows/_test.yml + needs: [ init ] + with: + NODE_VERSION: ${{ needs.init.outputs.NODE_VERSION }} + NODE_CACHE_KEY: ${{ needs.init.outputs.NODE_CACHE_KEY }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..212db50 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,29 @@ +name: Release + +on: + push: + branches: [master, main] + +jobs: + init: + name: Init + uses: ./.github/workflows/_init.yml + + test: + name: Test + uses: ./.github/workflows/_test.yml + needs: [init] + with: + NODE_VERSION: ${{ needs.init.outputs.NODE_VERSION }} + NODE_CACHE_KEY: ${{ needs.init.outputs.NODE_CACHE_KEY }} + + release: + name: Release + uses: ./.github/workflows/_release.yml + needs: [init, test] + with: + NODE_VERSION: ${{ needs.init.outputs.NODE_VERSION }} + NODE_CACHE_KEY: ${{ needs.init.outputs.NODE_CACHE_KEY }} + secrets: + SEMANTIC_RELEASE_NPM_TOKEN: ${{ secrets.NPM_PUBLISHER_TOKEN }} + SEMANTIC_RELEASE_GH_TOKEN: ${{ secrets.SEMANTIC_RELEASE_GH_TOKEN }} diff --git a/package.json b/package.json index 2e97045..4baefd4 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "scripts": { "test": "npm run test:unit", "test:unit": "NODE_ENV=test mocha --reporter spec --ui bdd $(find . -name \"*.spec.js\" -not -path \"./node_modules/*\")", - "code-style": "eslint --fix .", + "lint": "eslint --fix .", "validate-commit-msg": "validate-commit-msg", "semantic-release": "semantic-release", "audit": "better-npm-audit audit" @@ -30,7 +30,7 @@ "node": ">=20" }, "pre-commit": [ - "code-style", + "lint", "validate-commit-msg" ], "homepage": "https://github.com/emartech/suite-js-sdk", From d4ef3530d193dd75621f310a5c192a36c2282f9f Mon Sep 17 00:00:00 2001 From: D056966 Date: Mon, 6 Oct 2025 11:33:46 +0200 Subject: [PATCH 2/4] chore(docs): update readme --- README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/README.md b/README.md index 7ee2c2e..34dc746 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,5 @@ # suite-js-sdk -[![Codeship Status for emartech/suite-js-sdk](https://codeship.com/projects/754d4680-a546-0132-cbce-72e52541da30/status?branch=master)](https://codeship.com/projects/66642) -[![Dependency Status](https://david-dm.org/emartech/suite-js-sdk.svg)](https://david-dm.org/emartech/suite-js-sdk) - Simple Javascript wrapper for the Emarsys API. > Important: This library does not support WSSE authentication. It is intended only to be used by Emarsys add-ons and internal services. From 860a7d5ae4294e846982411b34393fb9dc11bcc4 Mon Sep 17 00:00:00 2001 From: D056966 Date: Mon, 6 Oct 2025 11:37:21 +0200 Subject: [PATCH 3/4] chore(ci): don't trigger on normal branch pushes --- .github/workflows/dev.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml index 251d40a..0e17de7 100644 --- a/.github/workflows/dev.yml +++ b/.github/workflows/dev.yml @@ -1,10 +1,8 @@ name: Development on: - push: - branches: [ '*', '*/*', '**', '!master', '!main' ] pull_request: - branches: [ master, main ] + branches: [master, main] jobs: init: @@ -14,7 +12,7 @@ jobs: test: name: Test uses: ./.github/workflows/_test.yml - needs: [ init ] + needs: [init] with: NODE_VERSION: ${{ needs.init.outputs.NODE_VERSION }} NODE_CACHE_KEY: ${{ needs.init.outputs.NODE_CACHE_KEY }} From 3816a99b970573efc28e64740c1f279e3bdc38a1 Mon Sep 17 00:00:00 2001 From: D056966 Date: Mon, 6 Oct 2025 11:44:25 +0200 Subject: [PATCH 4/4] chore(ci): use `secrets: inherit` --- .github/workflows/_release.yml | 10 ++-------- .github/workflows/release.yml | 4 +--- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/.github/workflows/_release.yml b/.github/workflows/_release.yml index d5ff6c7..84349dd 100644 --- a/.github/workflows/_release.yml +++ b/.github/workflows/_release.yml @@ -10,12 +10,6 @@ on: type: string required: true - secrets: - SEMANTIC_RELEASE_NPM_TOKEN: - required: true - SEMANTIC_RELEASE_GH_TOKEN: - required: true - jobs: test: name: Release package @@ -42,5 +36,5 @@ jobs: - name: Run release run: npm run release env: - NPM_TOKEN: ${{ secrets.SEMANTIC_RELEASE_NPM_TOKEN }} - GH_TOKEN: ${{ secrets.SEMANTIC_RELEASE_GH_TOKEN }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_PUBLISHER_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 212db50..a9050bd 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -24,6 +24,4 @@ jobs: with: NODE_VERSION: ${{ needs.init.outputs.NODE_VERSION }} NODE_CACHE_KEY: ${{ needs.init.outputs.NODE_CACHE_KEY }} - secrets: - SEMANTIC_RELEASE_NPM_TOKEN: ${{ secrets.NPM_PUBLISHER_TOKEN }} - SEMANTIC_RELEASE_GH_TOKEN: ${{ secrets.SEMANTIC_RELEASE_GH_TOKEN }} + secrets: inherit