Jackie
Jackie

Reputation: 23477

How do I push an npm version using Github Actions?

I have the following github workflow...

name: My workflow
on:
  push:
    branches:
      - 'feature/**'

jobs:
  build:
    name: Install
    runs-on: ${{ matrix.os }}

    strategy:
      matrix:
        os: [ ubuntu-latest ]
        node: [ 16 ]

    steps:
      - name: Checkout service-core
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
          persist-credentials: false

      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v2
        with:
          node-version: ${{ matrix.node-version }}
          cache: 'npm'

      - name: Install Dependencies
        run: npm ci

      - name: Reconfigure git to use HTTP authentication
        run: >
          git config --global url."https://my-user:${{ secrets.USER_TOKEN }}@github.com/".insteadOf
          ssh://[email protected]/

      - name: Setup Vals
        run: |
          git config --global user.email "[email protected]"
          git config --global user.name "my-user"

      - name: Version app
        run: npm version patch

      - name: Commit version
        run: |
          git show
          git push

When I run I see the update...

 diff --git a/package.json b/package.json
index 6469a04..5545f7c 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
-  "version": "0.0.1",
+  "version": "0.0.2",
   "main": "index.js",
   "directories": {

But when it tries to push I see...

fatal: could not read Username for 'https://github.com': No such device or address

What am I missing why is it not seeing the username?

Upvotes: 0

Views: 4615

Answers (1)

dan1st
dan1st

Reputation: 16338

You clone the repository like this:

- name: Checkout service-core
  uses: actions/checkout@v2
  with:
    fetch-depth: 0
    persist-credentials: false

states that credentials won't be saved but you need to know the credentials for pushing.

You can either remove persist-credentials: false or push with ${{ secrets.GITHUB_TOKEN }}:

git push "https://${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}" "${{ github.head_ref }}"

Upvotes: 1

Related Questions