简体   繁体   English

如何使用秘密和节点模块设置共享 github 操作工作流

[英]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 .我试图让它与needs一起工作,但所有环境设置都随着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:通过您可以定义作业 output 并在相关作业中使用它,例如:

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一些关于作业 output的文档的链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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