.github/workflows/nodejs.yml

Summary

Maintainability
Test Coverage
name: 'CI: ยต'

on: [ push ]

jobs:
  lint-changelog:
    name: Lint changelog file
    runs-on: ubuntu-latest
    steps:
      - name: Check out code
        uses: actions/checkout@v3
      - name: Lint changelog file
        uses: avto-dev/markdown-lint@v1
        with:
          rules: './.github/workflows/lint/rules/changelog.cjs'
          config: '/lint/config/changelog.yml'
          args: './CHANGELOG.md'

  lint-code:
    runs-on: ubuntu-latest
    name: testing on Node
    strategy:
      matrix:
        node-version: [ 18.x ]

    steps:
      - uses: actions/checkout@v3

      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node-version }}

      - name: Get npm cache directory
        id: npm-cache
        run: |
          echo "dir=$(npm config get cache)" >> $GITHUB_OUTPUT

      - uses: actions/cache@v3
        with:
          path: ${{ steps.npm-cache.outputs.dir }}
          key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }}
          restore-keys: |
            ${{ runner.os }}-node-

      - run: yarn install
      - run: yarn lint
        env:
          CI: true

  testing-on-node:
    runs-on: ubuntu-latest
    name: testing on Node
    needs: [ lint-changelog, lint-code ]
    strategy:
      matrix:
        node-version: [ 19.x,20.x,21.x ]

    steps:
      - uses: actions/checkout@v3

      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node-version }}

      - name: Get npm cache directory
        id: npm-cache
        run: |
          echo "dir=$(npm config get cache)" >> $GITHUB_OUTPUT

      - uses: actions/cache@v3
        with:
          path: ${{ steps.npm-cache.outputs.dir }}
          key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }}
          restore-keys: |
            ${{ runner.os }}-node-

      - run: yarn install
      - run: yarn test
        env:
          CI: true

  npm-publish:
    runs-on: ubuntu-latest
    needs: [ lint-changelog, testing-on-node ]
    if: ${{ startsWith(github.ref, 'refs/tags/v') }}
    steps:
      - uses: actions/checkout@v3
      # Setup .npmrc file to publish to npm
      - uses: actions/setup-node@v3
        with:
          node-version: '16.x'
          registry-url: 'https://registry.npmjs.org'
      - run: npm install
      # Publish to npm
      - run: npm publish --access public
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
#
#  npm-publish-fake:
#    name: npm-publish
#    needs: [lint-changelog, testing-on-node]
#    runs-on: ubuntu-latest
#    steps:
#      - uses: actions/checkout@v2
#      - name: Publish if version has been updated
#        uses: pascalgn/npm-publish-action@1.3.6
#        with: # All of theses inputs are optional
#          tag_name: "v%s"
#          tag_message: "v%s"
#          commit_pattern: "^Release (\\S+)"
#          workspace: "."
#          publish_command: "yarn"
#          publish_args: "--non-interactive"
#        env: # More info about the environment variables in the README
#          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Leave this as is, it's automatically generated
#          NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} # You need to set this in your repo settings