|
| 1 | +name: Node CI |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, reopened, synchronize] |
| 6 | + |
| 7 | +concurrency: |
| 8 | + # Note that the `teardown-pr-preview` workflow needs the same group name |
| 9 | + # to cancel the running `ci` workflows |
| 10 | + group: ${{ github.workflow }}-${{ github.event.number }} |
| 11 | + cancel-in-progress: true |
| 12 | + |
| 13 | +jobs: |
| 14 | + lint: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + |
| 17 | + strategy: |
| 18 | + matrix: |
| 19 | + node-version: [18.x] |
| 20 | + |
| 21 | + steps: |
| 22 | + - name: Fetch commit count |
| 23 | + env: |
| 24 | + PR_COMMIT_COUNT: ${{ github.event.pull_request.commits }} |
| 25 | + run: | |
| 26 | + echo "FETCH_DEPTH=$(($PR_COMMIT_COUNT + 1))" >> $GITHUB_ENV |
| 27 | +
|
| 28 | + - uses: actions/checkout@v4 |
| 29 | + with: |
| 30 | + fetch-depth: ${{ env.FETCH_DEPTH }} |
| 31 | + |
| 32 | + - name: Use Node.js ${{ matrix.node-version }} |
| 33 | + uses: actions/setup-node@v4 |
| 34 | + with: |
| 35 | + node-version: ${{ matrix.node-version }} |
| 36 | + |
| 37 | + - name: Cache node modules |
| 38 | + id: cache-dep |
| 39 | + uses: actions/cache@v3 |
| 40 | + env: |
| 41 | + cache-name: cache-node-modules |
| 42 | + with: |
| 43 | + path: node_modules |
| 44 | + key: ${{ runner.os }}-lint-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} |
| 45 | + |
| 46 | + - name: Install dependencies |
| 47 | + if: steps.cache-dep.outputs.cache-hit != 'true' |
| 48 | + run: npm ci |
| 49 | + |
| 50 | + - name: Collect changed files |
| 51 | + run: | |
| 52 | + mkdir ~/tmp/ |
| 53 | + git diff ${{ github.event.pull_request.base.sha }} ${{ github.sha }} --diff-filter=ACM --name-only --relative '*src/**/*.ts' > ~/tmp/changed_files |
| 54 | + echo -e "Changed files: \n$(cat ~/tmp/changed_files)" |
| 55 | +
|
| 56 | + - name: Lint |
| 57 | + run: npx eslint $(cat ~/tmp/changed_files) |
| 58 | + |
| 59 | + build: |
| 60 | + runs-on: ubuntu-latest |
| 61 | + |
| 62 | + strategy: |
| 63 | + matrix: |
| 64 | + node-version: [18.x] |
| 65 | + |
| 66 | + steps: |
| 67 | + - uses: actions/checkout@v4 |
| 68 | + |
| 69 | + - name: Use Node.js ${{ matrix.node-version }} |
| 70 | + uses: actions/setup-node@v4 |
| 71 | + with: |
| 72 | + node-version: ${{ matrix.node-version }} |
| 73 | + |
| 74 | + - name: Cache node modules |
| 75 | + id: cache-dep |
| 76 | + uses: actions/cache@v3 |
| 77 | + env: |
| 78 | + cache-name: cache-node-modules |
| 79 | + with: |
| 80 | + path: node_modules |
| 81 | + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} |
| 82 | + |
| 83 | + - name: Install dependencies |
| 84 | + if: steps.cache-dep.outputs.cache-hit != 'true' |
| 85 | + run: npm ci |
| 86 | + |
| 87 | + - name: Unit Test |
| 88 | + run: npm run test |
| 89 | + |
| 90 | + - name: Build release |
| 91 | + run: npm run release |
0 commit comments