|
1 |
| -name: CI |
| 1 | +name: CI & Release |
2 | 2 | on:
|
3 |
| - - push |
4 |
| - - pull_request |
| 3 | + # Build on pushes to release branches |
| 4 | + push: |
| 5 | + branches: ["main"] |
| 6 | + # Build on pull requests targeting release branches |
| 7 | + pull_request: |
| 8 | + branches: ["main"] |
| 9 | + workflow_dispatch: |
| 10 | + inputs: |
| 11 | + release: |
| 12 | + description: Release new version |
| 13 | + required: true |
| 14 | + default: false |
| 15 | + type: boolean |
| 16 | + |
5 | 17 | jobs:
|
6 |
| - test: |
7 |
| - runs-on: ${{ matrix.platform }} |
8 |
| - name: Node.js ${{ matrix.node-version }} / ${{ matrix.platform }} |
9 |
| - strategy: |
10 |
| - fail-fast: false |
11 |
| - matrix: |
12 |
| - platform: [ubuntu-latest, macos-latest, windows-latest] |
13 |
| - node-version: |
14 |
| - - 16 |
| 18 | + log-the-inputs: |
| 19 | + name: Log inputs |
| 20 | + runs-on: ubuntu-latest |
| 21 | + steps: |
| 22 | + - run: | |
| 23 | + echo "Inputs: $INPUTS" |
| 24 | + env: |
| 25 | + INPUTS: ${{ toJSON(inputs) }} |
| 26 | +
|
| 27 | + build: |
| 28 | + name: Lint & Build |
| 29 | + runs-on: ubuntu-latest |
15 | 30 | steps:
|
16 | 31 | - name: Set git to use LF
|
17 | 32 | run: |
|
18 | 33 | git config --global core.autocrlf false
|
19 | 34 | git config --global core.eol lf
|
20 |
| - - uses: actions/checkout@v2 |
21 |
| - - uses: actions/setup-node@v1 |
| 35 | + - uses: actions/checkout@v3 |
| 36 | + - uses: actions/setup-node@v3 |
| 37 | + with: |
| 38 | + node-version: lts/* |
| 39 | + cache: npm |
| 40 | + - run: npm ci |
| 41 | + - run: npm run lint --if-present |
| 42 | + - run: npm run prepublishOnly |
| 43 | + |
| 44 | + test: |
| 45 | + name: Test |
| 46 | + needs: build |
| 47 | + strategy: |
| 48 | + matrix: |
| 49 | + os: [ macos-latest, ubuntu-latest ] |
| 50 | + node: [ lts/*, current ] |
| 51 | + runs-on: ${{ matrix.os }} |
| 52 | + steps: |
| 53 | + - uses: actions/checkout@v3 |
| 54 | + - uses: actions/setup-node@v3 |
| 55 | + with: |
| 56 | + node-version: ${{ matrix.node }} |
| 57 | + cache: npm |
| 58 | + - run: npm ci |
| 59 | + - run: npm test --if-present |
| 60 | + |
| 61 | + release: |
| 62 | + name: Semantic release |
| 63 | + needs: test |
| 64 | + runs-on: ubuntu-latest |
| 65 | + # only run if opt-in during workflow_dispatch |
| 66 | + if: inputs.release == true |
| 67 | + steps: |
| 68 | + - uses: actions/checkout@v3 |
| 69 | + with: |
| 70 | + # Need to fetch entire commit history to |
| 71 | + # analyze every commit since last release |
| 72 | + fetch-depth: 0 |
| 73 | + - uses: actions/setup-node@v3 |
22 | 74 | with:
|
23 |
| - node-version: ${{ matrix.node-version }} |
24 |
| - - run: npm install |
25 |
| - - run: npm run lint |
26 |
| - - run: npm run build |
27 |
| - #- run: npm test |
| 75 | + node-version: lts/* |
| 76 | + cache: npm |
| 77 | + - run: npm ci |
| 78 | + # Branches that will release new versions are defined in .releaserc.json |
| 79 | + - run: npx semantic-release --dry-run |
| 80 | + # Don't allow interrupting the release step if the job is cancelled, as it can lead to an inconsistent state |
| 81 | + # e.g. git tags were pushed but it exited before `npm publish` |
| 82 | + if: always() |
| 83 | + env: |
| 84 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 85 | + NPM_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }} |
0 commit comments