githubcontinuous-integrationgithub-actionsactiongithub-api

Wrong YAML syntax for github actions


Screenshot of error

Trying out github actions to auto publish an npm package but its showing these errors I don't know what's wrong. I have used my own name and email in the code instead of this dummy data shown in the attached screenshot. And yes I have already set the secret value NPM_PUBLISH_TOKEN.

#.github/workflows/auto-publish.yml
- uses: actions/setup-node@v3
  with:
    node-version: '16.x'
    registry-url: 'https://registry.npmjs.org'

- name: Bump version & push
  run: |
    git config --global user.name 'Automated publish'
    git config --global user.email 'naeem-gg@users.noreply.github.com'

    # Update the version in package.json, and commit & tag the change:
    npm version patch # YMMV - you might want the semver level as a workflow input

    git push && git push --tags
    
- run: npm publish
  env:
    NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}

Solution

  • The workflow definition is missing a few required elements. Please see below.

    1. trigger is required - on: - I added a push trigger to main and master as I do not know your default branch
    2. permissions are optional but I added them here because by default a workflow can access a repo as read-only.
    3. Checkout step is also optional but because you are pushing changes, you need to checkout the repo

    I did not edit the shell script as I am not sure what specific files you want to add before you commit and push.

    #.github/workflows/auto-publish.yml
    name: auto-publish
    
    on:
      push:
        branches:
          - main
          - master
    
    permissions:
      contents: write
    
    jobs:
      auto-puplish:
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v4
          - uses: actions/setup-node@v3
            with:
              node-version: '16.x'
              registry-url: 'https://registry.npmjs.org'
    
          - name: Bump version & push
            run: |
              git config --global user.name 'Automated publish'
              git config --global user.email 'naeem-gg@users.noreply.github.com'
    
              # Update the version in package.json, and commit & tag the change:
              npm version patch # YMMV - you might want the semver level as a workflow input
    
              git push && git push --tags
    
          - run: npm publish
            env:
              NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}