簡體   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