|
| 1 | +--- |
| 2 | +# This workflow will run tests using node and then publish a package to GitHub Packages on push events to master. |
| 3 | +# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages |
| 4 | + |
| 5 | +name: CI |
| 6 | + |
| 7 | +on: |
| 8 | + pull_request: |
| 9 | + branches: |
| 10 | + - master |
| 11 | + types: |
| 12 | + - opened |
| 13 | + - synchronize |
| 14 | + - reopened |
| 15 | + push: |
| 16 | + branches: |
| 17 | + - master |
| 18 | + |
| 19 | +concurrency: |
| 20 | + group: "${{ github.workflow }}-${{ github.ref }}" |
| 21 | + cancel-in-progress: true |
| 22 | + |
| 23 | +jobs: |
| 24 | + setup_release: |
| 25 | + name: Setup Release |
| 26 | + outputs: |
| 27 | + publish_release: ${{ steps.setup_release.outputs.publish_release }} |
| 28 | + release_body: ${{ steps.setup_release.outputs.release_body }} |
| 29 | + release_commit: ${{ steps.setup_release.outputs.release_commit }} |
| 30 | + release_generate_release_notes: ${{ steps.setup_release.outputs.release_generate_release_notes }} |
| 31 | + release_tag: ${{ steps.setup_release.outputs.release_tag }} |
| 32 | + release_version: ${{ steps.setup_release.outputs.release_version }} |
| 33 | + runs-on: ubuntu-latest |
| 34 | + steps: |
| 35 | + - name: Checkout |
| 36 | + uses: actions/checkout@v4 |
| 37 | + |
| 38 | + - name: Setup Release |
| 39 | + id: setup_release |
| 40 | + uses: LizardByte/[email protected] |
| 41 | + with: |
| 42 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 43 | + |
| 44 | + build: |
| 45 | + runs-on: ubuntu-latest |
| 46 | + steps: |
| 47 | + - name: Checkout |
| 48 | + uses: actions/checkout@v4 |
| 49 | + |
| 50 | + - name: Setup node |
| 51 | + uses: actions/setup-node@v4 |
| 52 | + with: |
| 53 | + node-version: latest |
| 54 | + |
| 55 | + - name: Install dependencies |
| 56 | + run: npm install |
| 57 | + |
| 58 | + - name: Test |
| 59 | + id: test |
| 60 | + env: |
| 61 | + FORCE_COLOR: true |
| 62 | + run: | |
| 63 | + npm test |
| 64 | +
|
| 65 | + - name: Build |
| 66 | + env: |
| 67 | + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} |
| 68 | + run: npm run build |
| 69 | + |
| 70 | + - name: Upload test results to Codecov |
| 71 | + # any except canceled or skipped |
| 72 | + if: >- |
| 73 | + always() && |
| 74 | + (steps.test.outcome == 'success' || steps.test.outcome == 'failure') && |
| 75 | + startsWith(github.repository, 'LizardByte/') |
| 76 | + uses: codecov/test-results-action@v1 |
| 77 | + with: |
| 78 | + fail_ci_if_error: true |
| 79 | + files: ./junit.xml,!./cache |
| 80 | + token: ${{ secrets.CODECOV_TOKEN }} |
| 81 | + verbose: true |
| 82 | + |
| 83 | + - name: Upload coverage |
| 84 | + # any except canceled or skipped |
| 85 | + if: >- |
| 86 | + always() && |
| 87 | + (steps.test.outcome == 'success' || steps.test.outcome == 'failure') && |
| 88 | + startsWith(github.repository, 'LizardByte/') |
| 89 | + uses: codecov/codecov-action@v5 |
| 90 | + with: |
| 91 | + disable_search: true |
| 92 | + fail_ci_if_error: true |
| 93 | + files: ./coverage/coverage-final.json |
| 94 | + token: ${{ secrets.CODECOV_TOKEN }} |
| 95 | + verbose: true |
| 96 | + |
| 97 | + publish-gpr: |
| 98 | + if: ${{ needs.setup_release.outputs.publish_release == 'true' }} |
| 99 | + needs: |
| 100 | + - setup_release |
| 101 | + - build |
| 102 | + runs-on: ubuntu-latest |
| 103 | + permissions: |
| 104 | + contents: read |
| 105 | + id-token: write # required for provenance |
| 106 | + packages: write |
| 107 | + strategy: |
| 108 | + fail-fast: false |
| 109 | + matrix: |
| 110 | + include: |
| 111 | + - registry-url: "https://npm.pkg.github.com" |
| 112 | + extra-args: "" |
| 113 | + - registry-url: "https://registry.npmjs.org" |
| 114 | + extra-args: "--provenance --access public" |
| 115 | + steps: |
| 116 | + - name: Checkout |
| 117 | + uses: actions/checkout@v4 |
| 118 | + |
| 119 | + - name: Setup node |
| 120 | + uses: actions/setup-node@v4 |
| 121 | + with: |
| 122 | + node-version: latest |
| 123 | + registry-url: ${{ matrix.registry-url }} |
| 124 | + scope: '@lizardbyte' |
| 125 | + |
| 126 | + - name: Update package.json |
| 127 | + run: | |
| 128 | + npm version ${{ needs.setup_release.outputs.release_version }} --no-git-tag-version |
| 129 | +
|
| 130 | + - name: Install dependencies |
| 131 | + run: npm install |
| 132 | + |
| 133 | + - name: Build |
| 134 | + run: npm run build |
| 135 | + |
| 136 | + - name: Set token |
| 137 | + id: token |
| 138 | + run: | |
| 139 | + # if github registry, use GITHUB_TOKEN |
| 140 | + if [ "${{ matrix.registry-url }}" == "https://npm.pkg.github.com" ]; then |
| 141 | + echo "NODE_AUTH_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_OUTPUT |
| 142 | + else |
| 143 | + echo "NODE_AUTH_TOKEN=${{ secrets.NPM_TOKEN }}" >> $GITHUB_OUTPUT |
| 144 | + fi |
| 145 | +
|
| 146 | + - name: Publish |
| 147 | + run: npm publish ${{ matrix.extra-args }} |
| 148 | + env: |
| 149 | + NODE_AUTH_TOKEN: ${{ steps.token.outputs.NODE_AUTH_TOKEN }} |
0 commit comments