Lakatoi
Lakatoi

Reputation: 27

Run command taking output from previous step on GitHub actions

I'm trying to make a GitHub action that builds a Hugo website, deploys it on Pinata and saves the output hash of this last step to a txt file. I managed to achieve the first and second steps. And, for the third one, I've been trying to do it by running an "echo" command. However, I get this message: "You have an error in your yaml syntax on line 36"

How do I run the script taking the output from the step identified as "ipfs-pin"?

Here's my code:

name: deploy
 on:
  push:
   branches: [ main ]
   pull_request:
   branches: [ main ]
   workflow_dispatch:
jobs:
 build:
  runs-on: ubuntu-latest
   steps:
   - uses: actions/checkout@master
   - uses: jakejarvis/hugo-build-action@master
     with:
      args: --minify --buildDrafts
   - uses: anantaramdas/[email protected]
     id: ipfs-pin
      with:
       pin-name: '[my-pin-name]'
       path: './public'
       pinata-api-key: [API Key]
       pinata-secret-api-key: [secret API Key]
       verbose: true
       remove-old: true
  saves-hash-on-file:
   runs-on: ubuntu-latest
    steps:
  - uses: actions/checkout@v2
  - uses: actions/setup-node@v2
    with:
      node-version: '14'
  - run: echo ${{steps.build.ipfs-pin.hash}} > /.github/ipfs-hash.txt

Upvotes: 2

Views: 10203

Answers (1)

GuiFalourd
GuiFalourd

Reputation: 22920

First

It seems your indentation has a problem, I reproduced the workflow to correct it without returning error when pushing the workflow on the repository:

name: Deploy

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest
    outputs:
      hash: ${{ steps.ipfs-pin.outputs.hash }}
    steps:
      - uses: actions/checkout@master
      - uses: jakejarvis/hugo-build-action@master
        with:
          args: --minify --buildDrafts
      - uses: anantaramdas/[email protected]
        id: ipfs-pin
        with:
          pin-name: '[my-pin-name]'
          path: './public'
          pinata-api-key: '[API Key]'
          pinata-secret-api-key: '[secret API Key]'
          verbose: true
          remove-old: true

  saves-hash-on-file:
    runs-on: ubuntu-latest
    needs: [build]
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v2
        with:
          node-version: '14'
      - run: echo ${{steps.build.outputs.hash}} > /.github/ipfs-hash.txt

Second

As you can see on the workflow above, I added the outputs field at the job1 (build) level, without this you can't share the output on other jobs.

Reference about outputs

Moreover, to share outputs between jobs, you will have to add the needs: [build] line at the job2 (saves-hash-on-file) level.

Note: I couldn't run it successfully as I don't have any credential to test, but it should work if you copy/paste the workflow I shared using your credentials.

Upvotes: 3

Related Questions