繁体   English   中英

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

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

我有一个像下面这样的主要工作,另外两个并行工作依赖于第一个工作,包括秘密生成和节点模块安装,如秘密设置和安装节点模块。

在此处输入图像描述

我试图让它与needs一起工作,但所有环境设置都随着needs而消失。 可重用的工作流程似乎只是设置密钥。

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:
           ...

我检查了可重用的工作流程,但这些似乎仅用于设置环境变量。

有人尝试做类似的事情吗?

作业在它自己的环境中运行,因此默认情况下不共享任何内容。 通过您可以定义作业 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:
           ...

一些关于作业 output的文档的链接

暂无
暂无

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

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