Skip to content

Commit

Permalink
Drastically simply JWK download
Browse files Browse the repository at this point in the history
Our backend at https://sponsorlink.devlooped.com/jwk basically does the same we were doing in MSBuild before: download from GH the JWT and extract the JWK info. Since the backend needs to be up anyway, just simplify the build and use it.
  • Loading branch information
kzu committed Jul 22, 2024
1 parent b6f3a0f commit de1b927
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 76 deletions.
39 changes: 1 addition & 38 deletions samples/dotnet/SponsorLink.Analyzer.targets
Original file line number Diff line number Diff line change
Expand Up @@ -187,44 +187,7 @@ partial class SponsorLink
</Target>

<Target Name="DownloadDevloopedJwk" BeforeTargets="GetAssemblyAttributes" Inputs="$(MSBuildProjectFullPath)" Outputs="$(MSBuildProjectDirectory)\$(BaseIntermediateOutputPath)devlooped.jwk">
<Exec Command="pwsh --version" ContinueOnError="true" IgnoreExitCode="true">
<Output TaskParameter="ExitCode" PropertyName="PwshExitCode" />
</Exec>
<Exec Command="jq --version" ContinueOnError="true" IgnoreExitCode="true">
<Output TaskParameter="ExitCode" PropertyName="JqExitCode" />
</Exec>
<Exec Command="curl --version" ContinueOnError="true" IgnoreExitCode="true">
<Output TaskParameter="ExitCode" PropertyName="CurlExitCode" />
</Exec>

<PropertyGroup>
<JwkDownload Condition="'$(PwshExitCode)' != '0' or '$(JqExitCode)' != '0'">true</JwkDownload>
<CurlDownload Condition="'$(CurlExitCode)' == '0'">true</CurlDownload>
</PropertyGroup>

<!-- Special case for Windows with no curl (and no pwsh/jq), super legacy -->
<Exec Command="powershell -nop -C &quot;invoke-restmethod https://sponsorlink.devlooped.com/jwk -outfile $(MSBuildProjectDirectory)\$(BaseIntermediateOutputPath)devlooped.jwk&quot;"
EchoOff="true"
Condition="'$(JwkDownload)' == 'true' and '$(CurlDownload)' != '0'" />

<!-- General JWK download case for all OSes, when no pwsh/jq is available -->
<Exec Command="curl --output $(MSBuildProjectDirectory)\$(BaseIntermediateOutputPath)devlooped.jwk https://sponsorlink.devlooped.com/jwk"
EchoOff="true"
Condition="'$(JwkDownload)' == 'true' and '$(CurlDownload)' == '0'" />

<!-- Base case when pwsh+jq are available, download from github -->
<Exec Command="pwsh -NonInteractive -NoProfile -File '$(MSBuildThisFileDirectory)jwk.ps1'"
Condition="'$(JwkDownload)' != 'true'"
ConsoleToMSBuild="true"
EchoOff="true">
<Output TaskParameter="ConsoleOutput" PropertyName="RawJwk" />
<Output TaskParameter="ExitCode" PropertyName="MSBuildLastExitCode" />
</Exec>
<Error Text="$(RawJwk)" Condition="'$(JwkDownload)' != 'true' and '$(MSBuildLastExitCode)' != '0'" />
<WriteLinesToFile File="$(MSBuildProjectDirectory)\$(BaseIntermediateOutputPath)devlooped.jwk"
Lines="$(RawJwk)"
Overwrite="true"
Condition="'$(JwkDownload)' != 'true'" />
<Exec Command="curl --silent --output $(MSBuildProjectDirectory)\$(BaseIntermediateOutputPath)devlooped.jwk https://sponsorlink.devlooped.com/jwk" />
</Target>

<Target Name="ReadDevloopedJwk" DependsOnTargets="DownloadDevloopedJwk" BeforeTargets="GetAssemblyAttributes">
Expand Down
39 changes: 1 addition & 38 deletions samples/dotnet/SponsorLink/SponsorLink.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,44 +65,7 @@ partial class SponsorLink

<!-- Keep in sync with ..\SponsorLink.Analyzer.targets -->
<Target Name="DownloadDevloopedJwk" BeforeTargets="GetAssemblyAttributes" Inputs="$(MSBuildProjectFullPath)" Outputs="$(MSBuildProjectDirectory)\$(BaseIntermediateOutputPath)devlooped.jwk">
<Exec Command="pwsh --version" ContinueOnError="true" IgnoreExitCode="true">
<Output TaskParameter="ExitCode" PropertyName="PwshExitCode" />
</Exec>
<Exec Command="jq --version" ContinueOnError="true" IgnoreExitCode="true">
<Output TaskParameter="ExitCode" PropertyName="JqExitCode" />
</Exec>
<Exec Command="curl --version" ContinueOnError="true" IgnoreExitCode="true">
<Output TaskParameter="ExitCode" PropertyName="CurlExitCode" />
</Exec>

<PropertyGroup>
<JwkDownload Condition="'$(PwshExitCode)' != '0' or '$(JqExitCode)' != '0'">true</JwkDownload>
<CurlDownload Condition="'$(CurlExitCode)' == '0'">true</CurlDownload>
</PropertyGroup>

<!-- Special case for Windows with no curl (and no pwsh/jq), super legacy -->
<Exec Command="powershell -nop -C &quot;invoke-restmethod https://sponsorlink.devlooped.com/jwk -outfile $(MSBuildProjectDirectory)\$(BaseIntermediateOutputPath)devlooped.jwk&quot;"
EchoOff="true"
Condition="'$(JwkDownload)' == 'true' and '$(CurlDownload)' != '0'" />

<!-- General JWK download case for all OSes, when no pwsh/jq is available -->
<Exec Command="curl --output $(MSBuildProjectDirectory)\$(BaseIntermediateOutputPath)devlooped.jwk https://sponsorlink.devlooped.com/jwk"
EchoOff="true"
Condition="'$(JwkDownload)' == 'true' and '$(CurlDownload)' == '0'" />

<!-- Base case when pwsh+jq are available, download from github -->
<Exec Command="pwsh -NonInteractive -NoProfile -File '$(MSBuildThisFileDirectory)jwk.ps1'"
Condition="'$(JwkDownload)' != 'true'"
ConsoleToMSBuild="true"
EchoOff="true">
<Output TaskParameter="ConsoleOutput" PropertyName="RawJwk" />
<Output TaskParameter="ExitCode" PropertyName="MSBuildLastExitCode" />
</Exec>
<Error Text="$(RawJwk)" Condition="'$(JwkDownload)' != 'true' and '$(MSBuildLastExitCode)' != '0'" />
<WriteLinesToFile File="$(MSBuildProjectDirectory)\$(BaseIntermediateOutputPath)devlooped.jwk"
Lines="$(RawJwk)"
Overwrite="true"
Condition="'$(JwkDownload)' != 'true'" />
<Exec Command="curl --silent --output $(MSBuildProjectDirectory)\$(BaseIntermediateOutputPath)devlooped.jwk https://sponsorlink.devlooped.com/jwk" />
</Target>

<Target Name="ReadDevloopedJwk" DependsOnTargets="DownloadDevloopedJwk" BeforeTargets="GetAssemblyAttributes">
Expand Down

0 comments on commit de1b927

Please sign in to comment.