|
| 1 | +name: Check & Release |
| 2 | + |
| 3 | +on: |
| 4 | + # Push to master will deploy a dev version |
| 5 | + push: |
| 6 | + branches: [ master, renovate/** ] |
| 7 | + # PR to master branch will skip deployment |
| 8 | + pull_request: |
| 9 | + branches: [ master ] |
| 10 | + # A release via GitHub releases will deploy the latest version |
| 11 | + release: |
| 12 | + types: [ published ] |
| 13 | + |
| 14 | +jobs: |
| 15 | + # NPM install is done in a separate job and cached to speed up the following jobs. |
| 16 | + build_and_test: |
| 17 | + name: Build & Test |
| 18 | + if: (!contains(github.event.head_commit.message, '[skip ci]') && !contains(github.event.head_commit.message, 'docs:')) |
| 19 | + runs-on: ${{ matrix.os }} |
| 20 | + |
| 21 | + strategy: |
| 22 | + fail-fast: false |
| 23 | + matrix: |
| 24 | + # tests on windows are extremely unstable |
| 25 | + # os: [ ubuntu-latest, windows-2019 ] |
| 26 | + os: [ ubuntu-latest ] |
| 27 | + node-version: [ 16, 18 ] |
| 28 | + |
| 29 | + steps: |
| 30 | + - name: Cancel Workflow Action |
| 31 | + uses: styfle/cancel-workflow-action@0.9.1 |
| 32 | + with: |
| 33 | + access_token: ${{ github.token }} |
| 34 | + |
| 35 | + - name: Checkout repository |
| 36 | + uses: actions/checkout@v3 |
| 37 | + |
| 38 | + - name: Use Node.js ${{ matrix.node-version }} |
| 39 | + uses: actions/setup-node@v3 |
| 40 | + with: |
| 41 | + node-version: ${{ matrix.node-version }} |
| 42 | + cache: 'npm' |
| 43 | + cache-dependency-path: 'package-lock.json' |
| 44 | + |
| 45 | + - uses: microsoft/playwright-github-action@v1 |
| 46 | + |
| 47 | + - name: Turbo cache |
| 48 | + id: turbo-cache |
| 49 | + uses: actions/cache@v2 |
| 50 | + with: |
| 51 | + path: .turbo |
| 52 | + key: turbo-${{ github.job }}-${{ github.ref_name }}-${{ github.sha }} |
| 53 | + restore-keys: | |
| 54 | + turbo-${{ github.job }}-${{ github.ref_name }}- |
| 55 | +
|
| 56 | + - name: Install Dependencies |
| 57 | + run: npm ci |
| 58 | + |
| 59 | + - name: Build |
| 60 | + run: npm run ci:build |
| 61 | + |
| 62 | + - name: Tests |
| 63 | + run: npm test |
| 64 | + |
| 65 | + lint: |
| 66 | + name: Lint |
| 67 | + runs-on: ubuntu-latest |
| 68 | + |
| 69 | + steps: |
| 70 | + - name: Checkout repository |
| 71 | + uses: actions/checkout@v3 |
| 72 | + |
| 73 | + - name: Use Node.js 16 |
| 74 | + uses: actions/setup-node@v3 |
| 75 | + with: |
| 76 | + node-version: 16 |
| 77 | + cache: 'npm' |
| 78 | + cache-dependency-path: 'package-lock.json' |
| 79 | + |
| 80 | + - name: Turbo cache |
| 81 | + id: turbo-cache |
| 82 | + uses: actions/cache@v2 |
| 83 | + with: |
| 84 | + path: .turbo |
| 85 | + key: turbo-${{ github.job }}-${{ github.ref_name }}-${{ github.sha }} |
| 86 | + restore-keys: | |
| 87 | + turbo-${{ github.job }}-${{ github.ref_name }}- |
| 88 | +
|
| 89 | + - name: Install Dependencies |
| 90 | + run: npm ci |
| 91 | + |
| 92 | + - name: ESLint |
| 93 | + run: npm run lint |
| 94 | + |
| 95 | + publish: |
| 96 | + name: Publish |
| 97 | + if: (github.ref == 'refs/heads/master' || github.event_name == 'release') && !contains(github.event.head_commit.message, '[skip ci]') && !contains(github.event.head_commit.message, 'docs:') |
| 98 | + runs-on: ubuntu-latest |
| 99 | + needs: [ lint, build_and_test ] |
| 100 | + steps: |
| 101 | + - name: Checkout Source code |
| 102 | + uses: actions/checkout@v3 |
| 103 | + |
| 104 | + - name: Use Node.js 16 |
| 105 | + uses: actions/setup-node@v3 |
| 106 | + with: |
| 107 | + node-version: 16 |
| 108 | + cache: 'npm' |
| 109 | + cache-dependency-path: 'package-lock.json' |
| 110 | + |
| 111 | + - name: Turbo cache |
| 112 | + id: turbo-cache |
| 113 | + uses: actions/cache@v2 |
| 114 | + with: |
| 115 | + path: .turbo |
| 116 | + key: turbo-${{ github.job }}-${{ github.ref_name }}-${{ github.sha }} |
| 117 | + restore-keys: | |
| 118 | + turbo-${{ github.job }}-${{ github.ref_name }}- |
| 119 | +
|
| 120 | + - name: Install Dependencies |
| 121 | + run: npm ci |
| 122 | + |
| 123 | + - name: Check for changes |
| 124 | + id: changed_packages |
| 125 | + run: | |
| 126 | + echo "::set-output name=changed_packages::$(node ./node_modules/.bin/lerna changed -p | wc -l | xargs)" |
| 127 | +
|
| 128 | + - name: Check for changes 2 |
| 129 | + if: steps.changed_packages.outputs.changed_packages == '0' |
| 130 | + run: | |
| 131 | + echo "no changes detected by lerna" |
| 132 | +
|
| 133 | + - name: Build |
| 134 | + if: steps.changed_packages.outputs.changed_packages != '0' |
| 135 | + run: npm run build |
| 136 | + |
| 137 | + - name: Set Release Tag |
| 138 | + run: echo "RELEASE_TAG=$(if [ ${{ github.event_name }} = release ]; then echo latest; else echo next; fi)" >> $GITHUB_ENV |
| 139 | + |
| 140 | + - name: Release dev version for testing |
| 141 | + if: env.RELEASE_TAG == 'next' && steps.changed_packages.outputs.changed_packages != '0' |
| 142 | + run: | |
| 143 | + git config --global user.name 'Apify Release Bot' |
| 144 | + git config --global user.email 'noreply@apify.com' |
| 145 | + npx turbo run copy --force -- -- --canary --preid=beta |
| 146 | + git commit -am 'chore: bump canary versions [skip ci]' |
| 147 | +
|
| 148 | + echo "access=public" >> .npmrc |
| 149 | + echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> .npmrc |
| 150 | + npm run publish:next -- --yes --no-verify-access |
| 151 | + env: |
| 152 | + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 153 | + GIT_USER: "noreply@apify.com:${{ secrets.GH_TOKEN }}" |
| 154 | + GH_TOKEN: ${{ secrets.GH_TOKEN }} |
0 commit comments