From 9bc00ccc972f3557a41436cba518f5101102322d Mon Sep 17 00:00:00 2001 From: Mariusz Nowak Date: Mon, 5 Jun 2023 12:02:19 +0200 Subject: [PATCH] ci: CI setup --- .github/workflows/integrate.yml | 187 ++++++++++++++++++++++++++++++++ .github/workflows/publish.yml | 59 ++++++++++ .github/workflows/validate.yml | 184 +++++++++++++++++++++++++++++++ package.json | 1 + 4 files changed, 431 insertions(+) create mode 100644 .github/workflows/integrate.yml create mode 100644 .github/workflows/publish.yml create mode 100644 .github/workflows/validate.yml diff --git a/.github/workflows/integrate.yml b/.github/workflows/integrate.yml new file mode 100644 index 00000000..3c7abc1a --- /dev/null +++ b/.github/workflows/integrate.yml @@ -0,0 +1,187 @@ +# master only + +name: Integrate + +on: + push: + branches: [master] + +env: + SLS_IGNORE_WARNING: "*" + FORCE_COLOR: 1 + +jobs: + linuxNode16: + name: "[Linux] Node.js v16: Unit tests" + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Retrieve dependencies from cache + id: cacheNpm + uses: actions/cache@v2 + with: + path: | + ~/.npm + node_modules + key: npm-v16-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }} + restore-keys: npm-v16-${{ runner.os }}-${{ github.ref }}- + + - name: Install Node.js and npm + uses: actions/setup-node@v1 + with: + node-version: 16.x + + - name: Install dependencies + if: steps.cacheNpm.outputs.cache-hit != 'true' + run: | + npm update --no-save + npm update --save-dev --no-save + - name: Unit tests + run: npm test + + linuxNode18: + name: "[Linux] Node.js v18: Unit tests" + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Retrieve dependencies from cache + id: cacheNpm + uses: actions/cache@v2 + with: + path: | + ~/.npm + node_modules + key: npm-v18-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }} + restore-keys: npm-v18-${{ runner.os }}-${{ github.ref }}- + + - name: Install Node.js and npm + uses: actions/setup-node@v1 + with: + node-version: 17.x + + - name: Install dependencies + if: steps.cacheNpm.outputs.cache-hit != 'true' + run: | + npm update --no-save + npm update --save-dev --no-save + + - name: Unit tests + run: npm test + + linuxNode14: + name: "[Linux] Node.js v14: Unit tests" + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Retrieve dependencies from cache + id: cacheNpm + uses: actions/cache@v2 + with: + path: | + ~/.npm + node_modules + key: npm-v14-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }} + restore-keys: npm-v14-${{ runner.os }}-${{ github.ref }}- + + - name: Install Node.js and npm + uses: actions/setup-node@v1 + with: + node-version: 14.x + + - name: Install dependencies + if: steps.cacheNpm.outputs.cache-hit != 'true' + run: | + npm update --no-save + npm update --save-dev --no-save + - name: Unit tests + run: npm test + + linuxNode12: + name: "[Linux] Node.js v12: Unit tests" + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Retrieve dependencies from cache + id: cacheNpm + uses: actions/cache@v2 + with: + path: | + ~/.npm + node_modules + key: npm-v12-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }} + restore-keys: npm-v12-${{ runner.os }}-${{ github.ref }}- + + - name: Install Node.js and npm + uses: actions/setup-node@v1 + with: + node-version: 12.x + + - name: Install dependencies + if: steps.cacheNpm.outputs.cache-hit != 'true' + run: | + npm update --no-save + npm update --save-dev --no-save + - name: Unit tests + run: npm test + + linuxNode10: + name: "[Linux] Node.js v10: Unit tests" + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Retrieve dependencies from cache + id: cacheNpm + uses: actions/cache@v2 + with: + path: | + ~/.npm + node_modules + key: npm-v10-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }} + restore-keys: npm-v10-${{ runner.os }}-${{ github.ref }}- + + - name: Install Node.js and npm + uses: actions/setup-node@v1 + with: + node-version: 10.x + + - name: Install dependencies + if: steps.cacheNpm.outputs.cache-hit != 'true' + run: | + npm update --no-save + npm update --save-dev --no-save + - name: Unit tests + run: npm test + + tagIfNewVersion: + name: Tag if new version + runs-on: ubuntu-latest + needs: [linuxNode16, linuxNode18, linuxNode14, linuxNode12, linuxNode10] + steps: + - name: Checkout repository + uses: actions/checkout@v2 + with: + # Ensure to have complete history of commits pushed with given push operation + # It's loose and imperfect assumption that no more than 30 commits will be pushed at once + fetch-depth: 30 + # Tag needs to be pushed with real user token, otherwise pushed tag won't trigger the actions workflow + # Hence we're passing 'serverless-ci' user authentication token + token: ${{ secrets.USER_GITHUB_TOKEN }} + - name: Tag if new version + if: github.event.before != '0000000000000000000000000000000000000000' # Skip on first commit + run: | + NEW_VERSION=`git diff -U0 ${{ github.event.before }} package.json | grep '"version": "' | tail -n 1 | grep -oE "[0-9]+\.[0-9]+\.[0-9]+"` || : + if [ -n "$NEW_VERSION" ]; + then + git tag v$NEW_VERSION + git push --tags + fi diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000..46f553e6 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,59 @@ +# Version tags only + +name: Publish + +on: + push: + tags: + - v[0-9]+.[0-9]+.[0-9]+ + +jobs: + publish: + name: Publish + runs-on: ubuntu-latest + env: + # It'll work with secrets.GITHUB_TOKEN (which is provided by GitHub unconditionally) + # Still then release author would be "github-actions" + GITHUB_TOKEN: ${{ secrets.USER_GITHUB_TOKEN }} + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Retrieve dependencies from cache + uses: actions/cache@v2 + with: + path: | + ~/.npm + node_modules + key: npm-v16-${{ runner.os }}-refs/heads/master-${{ hashFiles('package.json') }} + + - name: Install Node.js and npm + uses: actions/setup-node@v1 + with: + node-version: 16.x + registry-url: https://registry.npmjs.org + + - name: Build + run: npm run build + + - name: Publish new version + # Note: Setting NODE_AUTH_TOKEN as job|workspace wide env var won't work + # as it appears actions/setup-node sets own value + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + run: npm publish + + # Normally we have a guarantee that deps are already there, still it may not be the case when: + # - `master` build for same commit failed (and we still pushed tag manually) + # - We've pushed tag manually before `master` build finalized + - name: Install dependencies + if: steps.cacheNpm.outputs.cache-hit != 'true' + run: | + npm update --no-save + npm update --save-dev --no-save + + - name: Publish release notes + run: | + TEMP_ARRAY=($(echo $GITHUB_REF | tr "/" "\n")) + TAG=${TEMP_ARRAY[@]: -1} + npx github-release-from-cc-changelog $TAG diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml new file mode 100644 index 00000000..2811e2bb --- /dev/null +++ b/.github/workflows/validate.yml @@ -0,0 +1,184 @@ +# PR's only + +name: Validate + +on: + pull_request: + branches: [master] + +env: + FORCE_COLOR: 1 + +jobs: + linuxNode16: + name: "[Linux] Node.js 16: Lint, Unit tests" + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v2 + with: + # For commitlint purpose ensure to have complete list of PR commits + # It's loose and imperfect assumption that PR has no more than 30 commits + fetch-depth: 30 + + - name: Retrieve last master commit (for `git diff` purposes) + run: | + git checkout -b pr + git fetch --prune --depth=30 origin +refs/heads/master:refs/remotes/origin/master + git checkout master + git checkout pr + + - name: Retrieve dependencies from cache + id: cacheNpm + uses: actions/cache@v2 + with: + path: | + ~/.npm + node_modules + key: npm-v16-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }} + restore-keys: | + npm-v16-${{ runner.os }}-${{ github.ref }}- + npm-v16-${{ runner.os }}-refs/heads/master- + + - name: Install Node.js and npm + uses: actions/setup-node@v1 + with: + node-version: 16.x + + - name: Install dependencies + if: steps.cacheNpm.outputs.cache-hit != 'true' + run: | + npm update --no-save + npm update --save-dev --no-save + - name: Validate lint rules + run: npm run lint + - name: Unit tests + run: npm test + + linuxNode17: + name: "[Linux] Node.js v18: Unit tests" + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Retrieve dependencies from cache + id: cacheNpm + uses: actions/cache@v2 + with: + path: | + ~/.npm + node_modules + key: npm-v18-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }} + restore-keys: | + npm-v18-${{ runner.os }}-${{ github.ref }}- + npm-v18-${{ runner.os }}-refs/heads/master- + + - name: Install Node.js and npm + uses: actions/setup-node@v1 + with: + node-version: 17.x + + - name: Install dependencies + if: steps.cacheNpm.outputs.cache-hit != 'true' + run: | + npm update --no-save + npm update --save-dev --no-save + - name: Unit tests + run: npm test + + linuxNode14: + name: "[Linux] Node.js v14: Unit tests" + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Retrieve dependencies from cache + id: cacheNpm + uses: actions/cache@v2 + with: + path: | + ~/.npm + node_modules + key: npm-v14-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }} + restore-keys: | + npm-v14-${{ runner.os }}-${{ github.ref }}- + npm-v14-${{ runner.os }}-refs/heads/master- + + - name: Install Node.js and npm + uses: actions/setup-node@v1 + with: + node-version: 14.x + + - name: Install dependencies + if: steps.cacheNpm.outputs.cache-hit != 'true' + run: | + npm update --no-save + npm update --save-dev --no-save + - name: Unit tests + run: npm test + + linuxNode12: + name: "[Linux] Node.js v12: Unit tests" + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Retrieve dependencies from cache + id: cacheNpm + uses: actions/cache@v2 + with: + path: | + ~/.npm + node_modules + key: npm-v12-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }} + restore-keys: | + npm-v12-${{ runner.os }}-${{ github.ref }}- + npm-v12-${{ runner.os }}-refs/heads/master- + + - name: Install Node.js and npm + uses: actions/setup-node@v1 + with: + node-version: 12.x + + - name: Install dependencies + if: steps.cacheNpm.outputs.cache-hit != 'true' + run: | + npm update --no-save + npm update --save-dev --no-save + - name: Unit tests + run: npm test + + linuxNode10: + name: "[Linux] Node.js v10: Unit tests" + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Retrieve dependencies from cache + id: cacheNpm + uses: actions/cache@v2 + with: + path: | + ~/.npm + node_modules + key: npm-v10-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }} + restore-keys: | + npm-v10-${{ runner.os }}-${{ github.ref }}- + npm-v10-${{ runner.os }}-refs/heads/master- + + - name: Install Node.js and npm + uses: actions/setup-node@v1 + with: + node-version: 10.x + + - name: Install dependencies + if: steps.cacheNpm.outputs.cache-hit != 'true' + run: | + npm update --no-save + npm update --save-dev --no-save + - name: Unit tests + run: npm test diff --git a/package.json b/package.json index 850c51ce..752433ac 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ "@types/jest": "24.0.12", "@types/lodash": "4.14.123", "@types/node": "12.6.2", + "github-release-from-cc-changelog": "^2.3.0", "jest": "24.5.0", "mock-fs": "4.9.0", "rimraf": "2.6.3",