A
A
Alex2020-10-22 18:46:01
bash
Alex, 2020-10-22 18:46:01

How to get version number from console output?

To build the project, the command
npm run push_production
The whole project is built on GitHub Action is provided.
During execution, many other commands are launched, after which the entire project is uploaded to the production, and the line is displayed in the console:
Created version N.
I want to get the version number from the output and create the corresponding release on GitHub.

I tried doing it like this:

- id: push-production
      run: echo "::set-output name=PUSH_RESULT::$(npm run push_production)"
      shell: bash
    
    - run: echo PUSH_RESULT:${{ steps.push-production.outputs.PUSH_RESULT }}


But in the console it is displayed only PUSH_RESULT:for some reason the result of the assembly is not saved to a variable, from which it would be possible to pull out the version number later.

Full action.yml

name: Deploy to Produtcion

on:
  push:
    branches: [ main ]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/[email protected]
    - uses: actions/[email protected]
      with:
        node-version: 14.x
    - run: npm ci
      
    - name: Create credentials
      env:
        credentials: ${{ secrets.GOOGLE_CREDENTIALS }}
      run: echo $credentials >> ~/.clasprc.json
      
    - id: push-production
      run: echo "::set-output name=PUSH_RESULT::$(npm run push_production)"
      shell: bash
    
    - run: echo PUSH_RESULT:${{ steps.push-production.outputs.PUSH_RESULT }} 
      
    - id: created-version
      env: 
        PUSH_RESULT: ${{ steps.push-production.outputs.PUSH_RESULT }}
      run: echo "::set-output name=CREATED_VERSION::$( $PUSH_RESULT | grep -oE "Created version [0-9]+" | grep -oE "[0-9]+")"
      shell: bash
      
    - run: echo CREATED_VERSION:${{ steps.created-version.outputs.CREATED_VERSION }}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Valentin Sudakov, 2020-12-16
@svsd_val

Perhaps you have a version number displayed in STD error, try reading from it or redirect all streams to STD out

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question