From 69f092828b88488a711a2d2ac8f92c05560082ca Mon Sep 17 00:00:00 2001 From: Mariusz Nowak Date: Thu, 7 Apr 2022 18:38:14 +0200 Subject: [PATCH] ci: Switch to reusable workflow configurations --- .github/workflows/integrate.yml | 352 +------------------------------- .github/workflows/publish.yml | 54 +---- .github/workflows/validate.yml | 345 +------------------------------ 3 files changed, 14 insertions(+), 737 deletions(-) diff --git a/.github/workflows/integrate.yml b/.github/workflows/integrate.yml index 602f714f..d8635510 100644 --- a/.github/workflows/integrate.yml +++ b/.github/workflows/integrate.yml @@ -10,351 +10,7 @@ env: 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 - - windowsNode16: - name: "[Windows] Node.js v16: Unit tests" - runs-on: windows-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 - - linuxNode17: - name: "[Linux] Node.js v17: Unit tests on npm package" - 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-v17-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }} - restore-keys: npm-v17-${{ 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: Build local package - run: npm pack - - - name: Unit tests on npm package - run: | - NAME=`cat package.json | grep '"name": "' | grep -oE ": .*" | grep -oE '[^: ",]+'` - VERSION=`cat package.json | grep '"version": "' | grep -oE ": .*" | grep -oE '[^: ",]+'` - tar zxf "${NAME}-${VERSION}.tgz" - cp -R test "package" - ln -s "$(pwd)"/node_modules "package/node_modules" - cd "package" - npm test - - linuxNode14: - name: "[Linux] Node.js v14: Unit tests with coverage" - 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 run coverage - - name: Push coverage - run: npx codecov - - 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 - - linuxNode8: - name: "[Linux] Node.js v8: 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-v8-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }} - restore-keys: npm-v8-${{ runner.os }}-${{ github.ref }}- - - - name: Install Node.js and npm - uses: actions/setup-node@v1 - with: - node-version: 8.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 - - linuxNode6: - name: "[Linux] Node.js v6: 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-v6-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }} - restore-keys: npm-v6-${{ runner.os }}-${{ github.ref }}- - - - name: Install Node.js and npm - uses: actions/setup-node@v1 - with: - node-version: 6.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 - - linuxNode4: - name: "[Linux] Node.js v4: 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-v4-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }} - restore-keys: npm-v4-${{ runner.os }}-${{ github.ref }}- - - - name: Install Node.js and npm - uses: actions/setup-node@v1 - with: - node-version: 4.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 - - linuxNode012: - name: "[Linux] Node.js v0.12: 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-v0.12-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }} - restore-keys: npm-v0.12-${{ runner.os }}-${{ github.ref }}- - - - name: Install Node.js and npm - uses: actions/setup-node@v1 - with: - node-version: "0.12" - - - 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, - windowsNode16, - linuxNode17, - linuxNode14, - linuxNode12, - linuxNode10, - linuxNode8, - linuxNode6, - linuxNode4, - linuxNode012 - ] - 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 + _: + uses: medikoo/github-actions-workflows/.github/workflows/0.12-integrate.yml@main + secrets: + USER_GITHUB_TOKEN: ${{ secrets.USER_GITHUB_TOKEN }} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 5d1690a6..9c23c911 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -7,50 +7,12 @@ on: 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/main-${{ 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 +env: + FORCE_COLOR: 1 - - 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: - # - `main` 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 +jobs: + _: + uses: medikoo/github-actions-workflows/.github/workflows/publish.yml@main + secrets: + USER_GITHUB_TOKEN: ${{ secrets.USER_GITHUB_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 39b45f14..20835ccb 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -10,346 +10,5 @@ env: FORCE_COLOR: 1 jobs: - linuxNode16: - name: "[Linux] Node.js v16: Lint, Formatting, Unit tests" - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - - name: Retrieve last main commit (for `git diff` purposes) - run: | - git checkout -b pr - git fetch --prune --depth=30 origin +refs/heads/main:refs/remotes/origin/main - git checkout main - 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/main- - - - 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 Prettier formatting - run: npm run prettier-check:updated - - name: Validate ESLint rules - run: npm run lint:updated - - name: Unit tests - run: npm test - - windowsNode16: - name: "[Windows] Node.js v16: Unit tests" - runs-on: windows-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 }}- - npm-v16-${{ runner.os }}-refs/heads/main- - - - 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 - - linuxNode17: - name: "[Linux] Node.js v17: Unit tests on npm package" - 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-v17-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }} - restore-keys: | - npm-v17-${{ runner.os }}-${{ github.ref }}- - npm-v17-${{ runner.os }}-refs/heads/main- - - - 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: Build local package - run: npm pack - - - name: Unit tests on npm package - run: | - NAME=`cat package.json | grep '"name": "' | grep -oE ": .*" | grep -oE '[^: ",]+'` - VERSION=`cat package.json | grep '"version": "' | grep -oE ": .*" | grep -oE '[^: ",]+'` - tar zxf "${NAME}-${VERSION}.tgz" - cp -R test "package" - ln -s "$(pwd)"/node_modules "package/node_modules" - cd "package" - npm test - - linuxNode14: - name: "[Linux] Node.js v14: Unit tests with coverage" - 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/main- - - - 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 run coverage - - name: Push coverage - run: npx codecov - - 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/main- - - - 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/main- - - - 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 - - linuxNode8: - name: "[Linux] Node.js v8: 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-v8-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }} - restore-keys: | - npm-v8-${{ runner.os }}-${{ github.ref }}- - npm-v8-${{ runner.os }}-refs/heads/main- - - - name: Install Node.js and npm - uses: actions/setup-node@v1 - with: - node-version: 8.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 - - linuxNode6: - name: "[Linux] Node.js v6: 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-v6-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }} - restore-keys: | - npm-v6-${{ runner.os }}-${{ github.ref }}- - npm-v6-${{ runner.os }}-refs/heads/main- - - - name: Install Node.js and npm - uses: actions/setup-node@v1 - with: - node-version: 6.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 - - linuxNode4: - name: "[Linux] Node.js v4: 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-v4-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }} - restore-keys: | - npm-v4-${{ runner.os }}-${{ github.ref }}- - npm-v4-${{ runner.os }}-refs/heads/main- - - - name: Install Node.js and npm - uses: actions/setup-node@v1 - with: - node-version: 4.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 - - linuxNode012: - name: "[Linux] Node.js v0.12: 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-v0.12-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }} - restore-keys: | - npm-v0.12-${{ runner.os }}-${{ github.ref }}- - npm-v0.12-${{ runner.os }}-refs/heads/main- - - - name: Install Node.js and npm - uses: actions/setup-node@v1 - with: - node-version: "0.12" - - - 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 + _: + uses: medikoo/github-actions-workflows/.github/workflows/0.12-validate.yml@main