|
| 1 | +name: Check & Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ master ] |
| 6 | + pull_request: |
| 7 | + branches: [ master ] |
| 8 | + |
| 9 | +jobs: |
| 10 | + test: |
| 11 | + name: Test |
| 12 | + if: ${{ !contains(github.event.head_commit.message, '[skip ci]') }} |
| 13 | + runs-on: ubuntu-latest |
| 14 | + |
| 15 | + strategy: |
| 16 | + fail-fast: false |
| 17 | + matrix: |
| 18 | + node-version: [ 12, 14, 15, 16 ] |
| 19 | + |
| 20 | + steps: |
| 21 | + - uses: actions/checkout@v2 |
| 22 | + - name: Use Node.js ${{ matrix.node-version }} |
| 23 | + uses: actions/setup-node@v2 |
| 24 | + with: |
| 25 | + node-version: ${{ matrix.node-version }} |
| 26 | + - name: Cache node_modules |
| 27 | + uses: actions/cache@v2 |
| 28 | + with: |
| 29 | + path: '**/node_modules' |
| 30 | + key: ${{ runner.os }}-${{ matrix.node-version }}-modules-${{ hashFiles('**/package-lock.json') }} |
| 31 | + - name: Update NPM |
| 32 | + run: npm install --no-audit -g npm@latest |
| 33 | + - name: Install Dependencies |
| 34 | + run: npm ci --no-audit |
| 35 | + - name: Run Tests |
| 36 | + run: npm test |
| 37 | + |
| 38 | + build: |
| 39 | + name: Build |
| 40 | + runs-on: ubuntu-latest |
| 41 | + |
| 42 | + steps: |
| 43 | + - uses: actions/checkout@v2 |
| 44 | + - name: Use Node.js 16 |
| 45 | + uses: actions/setup-node@v2 |
| 46 | + with: |
| 47 | + node-version: 16 |
| 48 | + - name: Cache node_modules |
| 49 | + uses: actions/cache@v2 |
| 50 | + with: |
| 51 | + path: '**/node_modules' |
| 52 | + key: ${{ runner.os }}-${{ matrix.node-version }}-modules-${{ hashFiles('**/package-lock.json') }} |
| 53 | + - name: Update NPM |
| 54 | + run: npm install --no-audit -g npm@latest |
| 55 | + - name: Install Dependencies |
| 56 | + run: npm ci --no-audit |
| 57 | + - run: npm run build |
| 58 | + |
| 59 | + lint: |
| 60 | + name: Lint |
| 61 | + runs-on: ubuntu-latest |
| 62 | + |
| 63 | + steps: |
| 64 | + - uses: actions/checkout@v2 |
| 65 | + - name: Use Node.js 16 |
| 66 | + uses: actions/setup-node@v2 |
| 67 | + with: |
| 68 | + node-version: 16 |
| 69 | + - name: Cache node_modules |
| 70 | + uses: actions/cache@v2 |
| 71 | + with: |
| 72 | + path: '**/node_modules' |
| 73 | + key: ${{ runner.os }}-${{ matrix.node-version }}-modules-${{ hashFiles('**/package-lock.json') }} |
| 74 | + - name: Install Dependencies |
| 75 | + run: npm ci --no-audit |
| 76 | + - run: npm run lint |
| 77 | + |
| 78 | + publish: |
| 79 | + name: Publish to NPM |
| 80 | + if: github.ref == 'refs/heads/master' |
| 81 | + needs: [ test, build, lint ] |
| 82 | + runs-on: ubuntu-latest |
| 83 | + steps: |
| 84 | + - uses: actions/checkout@v2 |
| 85 | + with: |
| 86 | + token: ${{ secrets.GH_TOKEN }} |
| 87 | + fetch-depth: 0 # we need to pull everything to allow lerna to detect what packages changed |
| 88 | + ref: master |
| 89 | + - uses: actions/setup-node@v2 |
| 90 | + with: |
| 91 | + node-version: 16 |
| 92 | + - name: Cache node_modules |
| 93 | + uses: actions/cache@v2 |
| 94 | + with: |
| 95 | + path: '**/node_modules' |
| 96 | + key: ${{ runner.os }}-${{ matrix.node-version }}-modules-${{ hashFiles('**/package-lock.json') }} |
| 97 | + - name: Check for changes |
| 98 | + id: changed_packages |
| 99 | + run: | |
| 100 | + echo "::set-output name=changed_packages::$(npx lerna changed -p | wc -l | xargs)" |
| 101 | + - name: Release |
| 102 | + if: steps.changed_packages.outputs.changed_packages != '0' |
| 103 | + run: | |
| 104 | + git config --global user.name 'Apify Release Bot' |
| 105 | + git config --global user.email 'noreply@apify.com' |
| 106 | + echo "access=public" >> .npmrc |
| 107 | + echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> .npmrc |
| 108 | + npm ci --no-audit |
| 109 | + npm run build |
| 110 | + git checkout -- . |
| 111 | + npx lerna publish --contents dist --yes --no-verify-access |
| 112 | + npm ci --no-audit # reinstall to have updated lock file |
| 113 | + npx lerna ls --json | npx ts-node -T scripts/sync-root-changelog.ts |
| 114 | + git commit -am 'chore: update root lock file and changelog [skip ci]' |
| 115 | + git push |
| 116 | + env: |
| 117 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 118 | + GIT_USER: "noreply@apify.com:${{ secrets.GH_TOKEN }}" |
| 119 | + GH_TOKEN: ${{ secrets.GH_TOKEN }} |
| 120 | + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
0 commit comments