pulumi / actions

Deploy continuously to your cloud of choice, using your favorite language, Pulumi, and GitHub!
Apache License 2.0
258 stars 73 forks source link

Github action error: Pulumi SDK has not been installed #1260

Closed nidiekma closed 3 months ago

nidiekma commented 3 months ago

What happened?

I try to run pulumi preview in my github action like this:

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest

    steps:
      - name: Check out the repository
        uses: actions/checkout@v3

      - name: Set up Node.js
        uses: actions/setup-node@v3
        with:
          node-version: "20"

      - name: Deploy to AWS with pulumi
        uses: pulumi/actions@v5
        with:
          command: preview
          stack-name: freelance-app/freelance-dev
          work-dir: ./pulumi
        env:
          PULUMI_ACCESS_TOKEN: ${{ secrets.PULUMI_ACCESS_TOKEN }}

And get the error:

Pulumi version 3.129.0 is already installed on this machine. Skipping download
Logging into the Pulumi Cloud backend.
pulumi preview on freelance-app/freelance-dev
  /home/runner/work/_actions/pulumi/actions/v5/webpack:/pulumi-github-action/node_modules/@pulumi/pulumi/automation/errors.js:77
                      : new CommandError(result);
  ^
  CommandError: code: -2
   stdout: 
   stderr: Command failed with exit code 255: pulumi preview --exec-agent pulumi/actions@v5 --color auto --exec-kind auto.local --event-log /tmp/automation-logs-preview-1SLrLh/eventlog.txt --stack freelance-app/freelance-dev --non-interactive
  [resource plugin awsx-2.12.3] installing
  [resource plugin synced-folder-0.11.1] installing
  [resource plugin aws-5.42.0] installing
  [resource plugin aws-6.[37](https://github.com/ResoluteError/freelance/actions/runs/10496871562/job/29078457760#step:5:38).1] installing
  [resource plugin aws-6.41.0] installing
  Previewing update (freelance-app/freelance-dev)
  View Live: https://app.pulumi.com/freelance-app/freelance-app/freelance-dev/previews/bb83d5e5-57ab-4e15-979f-5e522b074fc4
  @ Previewing update..................
  @ Previewing update....
      pulumi:pulumi:Stack freelance-app-freelance-dev  error: an unhandled error occurred: It looks like the Pulumi SDK has not been installed. Have you run pulumi install?
      pulumi:pulumi:Stack freelance-app-freelance-dev  1 error
  Diagnostics:
    pulumi:pulumi:Stack (freelance-app-freelance-dev):
      error: an unhandled error occurred: It looks like the Pulumi SDK has not been installed. Have you run pulumi install?
   err?: Error: Command failed with exit code 255: pulumi preview --exec-agent pulumi/actions@v5 --color auto --exec-kind auto.local --event-log /tmp/automation-logs-preview-1SLrLh/eventlog.txt --stack freelance-app/freelance-dev --non-interactive
  [resource plugin awsx-2.12.3] installing
  [resource plugin synced-folder-0.11.1] installing
  [resource plugin aws-5.42.0] installing
  [resource plugin aws-6.37.1] installing
  [resource plugin aws-6.[41](https://github.com/ResoluteError/freelance/actions/runs/10496871562/job/29078457760#step:5:42).0] installing
  Previewing update (freelance-app/freelance-dev)
  View Live: https://app.pulumi.com/freelance-app/freelance-app/freelance-dev/previews/bb83d5e5-57ab-4e15-979f-5e522b074fc4
  @ Previewing update..................
  @ Previewing update....
      pulumi:pulumi:Stack freelance-app-freelance-dev  error: an unhandled error occurred: It looks like the Pulumi SDK has not been installed. Have you run pulumi install?
      pulumi:pulumi:Stack freelance-app-freelance-dev  1 error
  Diagnostics:
    pulumi:pulumi:Stack (freelance-app-freelance-dev):
      error: an unhandled error occurred: It looks like the Pulumi SDK has not been installed. Have you run pulumi install?
      at Object.createCommandError (/home/runner/work/_actions/pulumi/actions/v5/webpack:/pulumi-github-action/node_modules/@pulumi/pulumi/automation/errors.js:77:1)
      at /home/runner/work/_actions/pulumi/actions/v5/webpack:/pulumi-github-action/node_modules/@pulumi/pulumi/automation/cmd.js:201:1
      at Generator.throw (<anonymous>)
      at rejected (/home/runner/work/_actions/pulumi/actions/v5/webpack:/pulumi-github-action/node_modules/@pulumi/pulumi/automation/cmd.js:19:1)
      at processTicksAndRejections (node:internal/process/task_queues:95:5)

Example

See github actions above and output above

Output of pulumi about

CLI          
warning: Failed to get information about the Pulumi program's dependencies: failed to run "/opt/hostedtoolcache/node/20.16.0/x64/bin/npm ls --json --depth=0": exit status 1
warning: Failed to get information about the current stack: No current stack
Version      3.129.0
Go Version   go1.22.6
Go Compiler  gc
Plugins
KIND      NAME    VERSION
language  nodejs  unknown
Host     
OS       ubuntu
Version  22.04
Arch     x[8](https://github.com/ResoluteError/freelance/actions/runs/10497126241/job/29079251661#step:5:9)6_64
This project is written in nodejs: executable='/opt/hostedtoolcache/node/20.16.0/x64/bin/node' version='v20.16.0'
Backend        
Name           pulumi.com
URL            https://app.pulumi.com
User           Unknown
Organizations  
Token type     personal
Pulumi locates its logs in /tmp by default

Additional context

No response

Contributing

Vote on this issue by adding a šŸ‘ reaction. To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

julienp commented 3 months ago

I think you need to install your nodejs dependencies before the pulumi/actions step, for example

- name: Installing dependencies
  run: npm ci # or yarn install, pnpm install, ... depending on your package manager
  working-directory: ./pulumi # depending on where your pulumi project lives

Could you check if that resolves the issue?

Somewhat related, a while ago we added the pulumi install command. We can't use that in a step before the pulumi/actions step because the Pulumi CLI is not installed yet at that point, but maybe the pulumi/actions step itself should have an option to run that for you šŸ¤”

nidiekma commented 3 months ago

I'm using a monorepo with npm workspaces and thought i correctly configured it but just to be double sure i made another npm install step inside the pulumi folder (i already had one in the root folder, just missed the code out for it in this issue, my bad). So my actions file looks like this:

steps:
      - name: Check out the repository
        uses: actions/checkout@v3

      - name: Set up Node.js
        uses: actions/setup-node@v3
        with:
          node-version: "20"

      - name: Install dependencies
        run: npm install

      - name: Install dependencies in pulumi folder
        run: |
          cd pulumi
          npm install

      - name: Deploy to AWS with pulumi
        uses: pulumi/actions@v5
        with:
          command: preview
          stack-name: freelance-app/freelance-dev
          work-dir: ./pulumi
        env:
          PULUMI_ACCESS_TOKEN: ${{ secrets.PULUMI_ACCESS_TOKEN }}

So now i get the error:

Logging in using access token from PULUMI_ACCESS_TOKEN
Previewing update (freelance-app/freelance-dev)
View Live: https://app.pulumi.com/freelance-app/freelance-app/freelance-dev/previews/e[9](https://github.com/ResoluteError/freelance/actions/runs/10504168288/job/29099037145#step:7:10)83641a-3f6b-46b4-b978-0ae4f2764ed5
[resource plugin docker-4.5.4] installing
[resource plugin aws-5.42.0] installing
[resource plugin aws-6.41.0] installing
[resource plugin aws-6.37.1] installing
@ Previewing update..................
@ Previewing update.....
    pulumi:pulumi:Stack freelance-app-freelance-dev running 
@ Previewing update............
    pulumi:providers:aws default_6_41_0  error: pulumi:providers:aws resource 'default_6_41_0' has a problem: No valid credential sources found.
    pulumi:pulumi:Stack freelance-app-freelance-dev  
    pulumi:providers:aws default_6_41_0  1 error
Diagnostics:
  pulumi:providers:aws (default_6_41_0):
    error: pulumi:providers:aws resource 'default_6_41_0' has a problem: No valid credential sources found.
    Please see https://www.pulumi.com/registry/packages/aws/installation-configuration/ for more information about providing credentials.
    NEW: You can use Pulumi ESC to set up dynamic credentials with AWS OIDC to ensure the correct and valid credentials are used.
    Learn more: https://www.pulumi.com/registry/packages/aws/installation-configuration/#dynamically-generate-credentials-via-pulumi-esc
Error: Process completed with exit code [25](https://github.com/ResoluteError/freelance/actions/runs/10504168288/job/29099037145#step:7:26)5.

But that seems to be another issue and with the authentication and not the strange "Pulumi SDK not isntalled" error i got first and dont understand. So that one seems to come from a wrong package.json configuration on my side. Thanks for the hint, otherwise i would still believe that it is just a bug inside the pulumi action and not a misconfiguration from my package.json.

I will close this issues, thanks!