Pulumi GitHub Action pulumi/actions@v2: error: It looks like the Pulumi SDK has not been installed. Have you run npm install or yarn install?

Pulumi GitHub Action pulumi/actions@v2: error: It looks like the Pulumi SDK has not been installed. Have you run npm install or yarn install?

我在工作on a project that uses Pulumi to provision some infrastructure pieces on Azure. I switched to the new pulumi/actions@v2 Action which was released recently

我的 GitHub 操作流程如下所示:

name: pulumi-preview-up

on: [push]

env:
  ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }}
  ARM_CLIENT_ID: ${{ secrets.ARM_CLIENT_ID }}
  ARM_CLIENT_SECRET: ${{ secrets.ARM_CLIENT_SECRET }}
  ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}
  PULUMI_ACCESS_TOKEN: ${{ secrets.PULUMI_ACCESS_TOKEN }}

jobs:
  preview-up-destroy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - name: Install Pulumi CLI
        uses: pulumi/action-install-pulumi-cli@v1.0.1

      - uses: pulumi/actions@v2
        with:
          command: preview
          stack-name: dev

现在我遇到了以下错误(参见 the full GHA logs here):

  Error: code: 255
   stdout: Previewing update (github-638882160)
  
  View Live: https://app.pulumi.com/jonashackt/scmbreakoutpulumi/github-638882160/previews/450a1f61-549d-4669-a7de-d8da8fc622f7
  
      pulumi:pulumi:Stack scmbreakoutpulumi-github-638882160  error: It looks like the Pulumi SDK has not been installed. Have you run npm install or yarn install?
      pulumi:pulumi:Stack scmbreakoutpulumi-github-638882160  1 message
   
  Diagnostics:
    pulumi:pulumi:Stack (scmbreakoutpulumi-github-638882160):
      error: It looks like the Pulumi SDK has not been installed. Have you run npm install or yarn install?
   
  
   stderr: error: failed to load language plugin nodejs: could not read plugin [/home/runner/.pulumi/bin/pulumi-language-nodejs] stdout: EOF
  
   err?: 

新的 Pulumi v2 GitHub Action 使用 new Pulumi Automation API. As the docs state:

This means that there is no supporting functionality for npm or pip installs. This functionality should be deferred to the correct GitHub Marketplace actions that support it.

这意味着配置 pulumi/actionspulumi/action-install-pulumi-cli 操作已经不够了(正如我们习惯使用 Pulumi v1 操作一样)。我们还需要自己设置语言特定的GitHub Action 环境 - 并且需要自己安装相应的依赖项 - 之前 使用 pulumi/actions!

假设使用 JavaScript/Typscript 样式的 Pulumi,我们需要添加 actions/setup-node 操作,然后还要添加 运行 一个 npm install。在我们的 workflow.yml 中,它看起来像这样:

name: pulumi-preview-up

on: [push]

env:
  ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }}
  ARM_CLIENT_ID: ${{ secrets.ARM_CLIENT_ID }}
  ARM_CLIENT_SECRET: ${{ secrets.ARM_CLIENT_SECRET }}
  ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}
  PULUMI_ACCESS_TOKEN: ${{ secrets.PULUMI_ACCESS_TOKEN }}

jobs:
  preview-up-destroy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - name: In order to use the Pulumi v2 action, we need to setup the Pulumi project specific language environment
        uses: actions/setup-node@v2
        with:
          node-version: '14'

      - name: After setting up the Pulumi project specific language environment, we need to install the dependencies also
        run: npm install

      - name: Install Pulumi CLI
        uses: pulumi/action-install-pulumi-cli@v1.0.1

      - uses: pulumi/actions@v2
        with:
          command: preview
          stack-name: dev

如果选择其他语言JavaScript/TypeScript,您还需要设置匹配环境。文档显示 examples for Python, Go and .Net also.