简体   繁体   中英

How to setup shared github action workflow with secrets and node modules

I have a main job like the below and two other parallel jobs are dependent on the first job including secret generation and node module installation like secret setup and install node module.

在此处输入图像描述

I tried to make it work with needs but all the environment setup is gone with needs . And reusable workflow seems to just setup keys.

name: build
on: [push]
jobs:
   codepull:
      runs-on: ubuntu-latest
      steps:

         - uses: actions/setup-node@v3
           with:
           node-version: '16.16.0'
         
         - name: install node module
           run |
             yarn

          - name: secrets
           run |
             yarn secrets

       codepull-ios:
           - name: build ios
             run |
                ...

    codepull-ios:
       runs-on: ubuntu-latest
       steps:
           ...

    codepull-android:
       runs-on: ubuntu-latest
       steps:
           ...

I checked reusable workflow but those seems only for setting up env variables.

Anyone tried to do similar things?

jobs runs in it's own environment so do not share nothing by default. By you can define jobs output and use it in the dependant job, like:

name: build
on: [push]
jobs:
   codepull:
      runs-on: ubuntu-latest
      outputs: # define here the job output
        one-secret: ${{ steps.secret.outputs.my-secret }}
      steps:

         - uses: actions/setup-node@v3
           with:
           node-version: '16.16.0'
         
         - name: install node module
           run |
             yarn

          - name: secrets
            id: secret
           run |
             yarn secrets

             secretkey=$(cat password.txt) # stupid example to take some var from somewhere
             echo "::set-output name=my-secret::$secretkey"


       codepull-ios:
           - name: build ios
             run |
                ...

    codepull-ios:
       runs-on: ubuntu-latest
       needs: 
         - codepull
       steps:
         -run:
           echo needs.codepull.outputs.one-secret # use the secrets
           ...

    codepull-android:
       runs-on: ubuntu-latest
       steps:
           ...

Some link to the doc about jobs output

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM