|
| 1 | +name: Node CI |
| 2 | + |
| 3 | +# Push tests pushes; PR tests merges |
| 4 | +on: [ push, pull_request ] |
| 5 | + |
| 6 | +defaults: |
| 7 | + run: |
| 8 | + shell: bash |
| 9 | + |
| 10 | +jobs: |
| 11 | + |
| 12 | + # Test the build |
| 13 | + build: |
| 14 | + # Setup |
| 15 | + runs-on: ${{ matrix.os }} |
| 16 | + strategy: |
| 17 | + matrix: |
| 18 | + node-version: [ 14.x ] |
| 19 | + os: [ ubuntu-latest ] |
| 20 | + |
| 21 | + # Go |
| 22 | + steps: |
| 23 | + - name: Check out repo |
| 24 | + uses: actions/checkout@v2 |
| 25 | + |
| 26 | + - name: Set up Node.js |
| 27 | + uses: actions/setup-node@v2 |
| 28 | + with: |
| 29 | + node-version: ${{ matrix.node-version }} |
| 30 | + |
| 31 | + - name: Env |
| 32 | + run: | |
| 33 | + echo "Event name: ${{ github.event_name }}" |
| 34 | + echo "Git ref: ${{ github.ref }}" |
| 35 | + echo "GH actor: ${{ github.actor }}" |
| 36 | + echo "SHA: ${{ github.sha }}" |
| 37 | + VER=`node --version`; echo "Node ver: $VER" |
| 38 | + VER=`npm --version`; echo "npm ver: $VER" |
| 39 | +
|
| 40 | + - name: Install |
| 41 | + run: npm install |
| 42 | + |
| 43 | + - name: Test |
| 44 | + run: npm test |
| 45 | + env: |
| 46 | + CI: true |
| 47 | + |
| 48 | + - name: Notify |
| 49 | + uses: sarisia/actions-status-discord@v1 |
| 50 | + # Only fire alert once |
| 51 | + if: github.ref == 'refs/heads/main' && failure() && matrix.node-version == '14.x' && matrix.os == 'ubuntu-latest' |
| 52 | + with: |
| 53 | + webhook: ${{ secrets.DISCORD_WEBHOOK }} |
| 54 | + title: "build and test" |
| 55 | + color: 0x222222 |
| 56 | + username: GitHub Actions |
| 57 | + |
| 58 | + # ----- Only git tag testing + package publishing beyond this point ----- # |
| 59 | + |
| 60 | + # Publish to package registries |
| 61 | + publish: |
| 62 | + # Setup |
| 63 | + needs: build |
| 64 | + if: startsWith(github.ref, 'refs/tags/v') |
| 65 | + runs-on: ubuntu-latest |
| 66 | + |
| 67 | + # Go |
| 68 | + steps: |
| 69 | + - name: Check out repo |
| 70 | + uses: actions/checkout@v2 |
| 71 | + |
| 72 | + - name: Set up Node.js |
| 73 | + uses: actions/setup-node@v1 |
| 74 | + with: |
| 75 | + node-version: 14 |
| 76 | + registry-url: https://registry.npmjs.org/ |
| 77 | + |
| 78 | + - name: Install |
| 79 | + run: npm i |
| 80 | + |
| 81 | + # Publish to npm |
| 82 | + - name: Publish @RC to npm |
| 83 | + if: contains(github.ref, 'RC') |
| 84 | + run: npm publish --tag RC |
| 85 | + env: |
| 86 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 87 | + |
| 88 | + - name: Publish @latest to npm |
| 89 | + if: contains(github.ref, 'RC') == false #'!contains()'' doesn't work lol |
| 90 | + run: npm publish |
| 91 | + env: |
| 92 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 93 | + |
| 94 | + # Set up Node again, this time using GitHub as the publish target |
| 95 | + - name: Set up Node.js |
| 96 | + uses: actions/setup-node@v1 |
| 97 | + with: |
| 98 | + node-version: 14 |
| 99 | + registry-url: https://npm.pkg.github.com/ |
| 100 | + |
| 101 | + - name: Notify |
| 102 | + uses: sarisia/actions-status-discord@v1 |
| 103 | + if: always() |
| 104 | + with: |
| 105 | + webhook: ${{ secrets.DISCORD_WEBHOOK }} |
| 106 | + title: "npm publish" |
| 107 | + color: 0x222222 |
| 108 | + username: GitHub Actions |
0 commit comments