mathiasvr / command-output

GitHub action that runs a command and store its output
MIT License
41 stars 10 forks source link

Add regex param to capture only a portion of stdout? #9

Open jacksonthall22 opened 11 months ago

jacksonthall22 commented 11 months ago

Thank you for creating this action, I'm using it right now in a workflow and it works great.

Perhaps a useful feature would be the ability to pass a regular expression that captures only a part of stdout / stderr into a third variable. For example, see my code below where I'm using two steps to accomplish this (workflow file here). It's not that bad, but it seems like there should be a better way.

- name: Create preview channel
  uses: mathiasvr/command-output@v2.0.0
  id: create_preview
  with:
    run: firebase hosting:channel:create ${{ github.event.pull_request.number }}
  env:
      FIREBASE_CLI_EXPERIMENTS: webframeworks
      FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
  # Output should look like this:
  # 
  # +  hosting:channel: Channel <pr_number> has been created on site <project_id>.
  # +  hosting:channel: Channel <pr_number> will expire at <timestamp>.
  # +  hosting:channel: Channel URL: https://<project_id>--<pr_number>-<random_hash>.web.app
  # 
  # To deploy to this channel, use firebase hosting:channel:deploy <pr_number>.

- name: Get preview channel URL from stdout
  uses: mathiasvr/command-output@v2.0.0
  id: preview_url
  with:
    run: echo '${{ steps.create_preview.outputs.stdout }}' | perl -ne 'print "$1\n" if /(https:\/\/[^\s]+\.web\.app)/'
  # Output: https://<project_id>--<pr_number>-<random_hash>.web.app