Skip to content

Commit

Permalink
Add dotnet support
Browse files Browse the repository at this point in the history
  • Loading branch information
danielrbradley committed Jun 17, 2024
1 parent 3fd9369 commit b37555e
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 2 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,11 @@ jobs:
directory: __tests__/programs/random-python
provider: random
providerVersion: '4.16.2'

- name: Test Local Action for dotnet
uses: ./
with:
language: dotnet
directory: __tests__/programs/random-dotnet
provider: random
providerVersion: '4.16.2'
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,13 @@ Thumbs.db

# Ignore built ts files
__tests__/runner/*
__tests__/programs/**/bin
__tests__/programs/**/obj
__tests__/programs/**/Pulumi.*.yaml

# IDE files
.idea
.vscode
*.code-workspace

*.sln
28 changes: 28 additions & 0 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,34 @@ describe('action', () => {
expect(setOutputMock).toHaveBeenCalledTimes(0)
})

it('dotnet setup', async () => {
// Set the action's inputs as return values from core.getInput()
getInputMock.mockImplementation(name => {
switch (name) {
case 'language':
return 'dotnet'
case 'directory':
return '__tests__/programs/random-dotnet'
case 'provider':
return 'random'
case 'providerVersion':
return '4.16.2'
case 'publisher':
return 'pulumi'
default:
return ''
}
})

await main.run()
expect(runMock).toHaveReturned()

expect(setFailedMock).not.toHaveBeenCalled()
expect(errorMock).not.toHaveBeenCalled()
expect(debugMock).toHaveBeenCalled()
expect(setOutputMock).toHaveBeenCalledTimes(0)
})

it('invalid language', async () => {
// Set the action's inputs as return values from core.getInput()
getInputMock.mockImplementation(name => {
Expand Down
14 changes: 14 additions & 0 deletions __tests__/programs/random-dotnet/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Random = Pulumi.Random;

return await Deployment.RunAsync(() =>
{
var username = new Random.RandomPassword("username", new()
{
Length = 256,
});

});

3 changes: 3 additions & 0 deletions __tests__/programs/random-dotnet/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: scratch-yaml
runtime: dotnet
description: A Pulumi YAML program to deploy a serverless application on AWS
14 changes: 14 additions & 0 deletions __tests__/programs/random-dotnet/scratch-yaml.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Pulumi" Version="3.*" />
<PackageReference Include="Pulumi.Random" Version="4.16.2" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions src/verifyRelease.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ async function installPackageVersion(
case 'python':
await installPipPackageVersion(wd, opts)
break
case 'dotnet':
await installDotnetPackageVersion(wd, opts)
break
}
}

Expand Down Expand Up @@ -118,3 +121,28 @@ async function installPipPackageVersion(
throw new Error(`Failed to install requirements.txt`)
}
}

async function installDotnetPackageVersion(
cwd: string,
opts: VerifyReleaseOptions
): Promise<void> {
const packageRef = `${opts.publisher}.${opts.provider}`
const removeCmd = `dotnet remove package ${packageRef}`
core.debug(`Removing any existing dotnet package: ${removeCmd}`)
const removeExec = shell.exec(removeCmd, { cwd })
if (removeExec.code !== 0) {
core.debug(
`Failed to remove ${packageRef}: \n${removeExec.stderr}\n${removeExec.stdout}`
)
}

const packageVersionRef = `${packageRef} --version ${opts.providerVersion}`
const addCmd = `dotnet add package ${packageVersionRef}`
core.debug(`Installing dotnet package: ${addCmd}`)
const addExec = shell.exec(addCmd, { cwd, fatal: true })
if (addExec.code !== 0) {
throw new Error(
`Failed to install ${packageVersionRef}: \n${addExec.stderr}\n${addExec.stdout}`
)
}
}

0 comments on commit b37555e

Please sign in to comment.