Skip to content

Commit 1d82722

Browse files
feat: Add PR pipeline to allow contribution without Nuget Feed access (#720)
## Description This plans to fix the broken pipelines caused by being run on `pull_request` actions and not `pull_request_target`. Contributors shouldn't need access to the nuget feed in order to contribute. Currently, without `pull_request_target` you're not able to get passing checks, even if they should be passing. --------- Co-authored-by: Benjamin Michaelis <[email protected]>
1 parent 9131941 commit 1d82722

File tree

18 files changed

+20727
-35
lines changed

18 files changed

+20727
-35
lines changed

.github/workflows/Build-Test-And-Deploy.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ name: Build, Test, and Deploy EssentialCSharp.Web
33
on:
44
push:
55
branches: ["main"]
6-
pull_request:
7-
branches: ["main"]
86
workflow_dispatch:
97

108
permissions:
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: PR Build and Test EssentialCSharp.Web
2+
3+
on:
4+
pull_request:
5+
branches: ["main"]
6+
workflow_dispatch:
7+
8+
jobs:
9+
build-and-test:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
14+
- name: Set up .NET Core
15+
uses: actions/setup-dotnet@v4
16+
with:
17+
global-json-file: global.json
18+
19+
- name: Set up dependency caching for faster builds
20+
uses: actions/cache@v4
21+
id: nuget-cache
22+
with:
23+
path: |
24+
~/.nuget/packages
25+
${{ github.workspace }}/**/obj/project.assets.json
26+
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
27+
restore-keys: |
28+
${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
29+
${{ runner.os }}-nuget-
30+
31+
- name: Restore with dotnet
32+
run: dotnet restore /p:AccessToNugetFeed=false
33+
34+
- name: Build with dotnet
35+
run: dotnet build --configuration Release --no-restore /p:AccessToNugetFeed=false
36+
37+
- name: Run .NET Tests
38+
run: dotnet test --no-build --configuration Release
39+
40+
- name: Set up Docker Buildx
41+
uses: docker/setup-buildx-action@v3
42+
43+
- name: Build Container Image
44+
uses: docker/build-push-action@v6
45+
with:
46+
file: ./EssentialCSharp.Web/Dockerfile
47+
context: .
48+
outputs: type=docker,dest=${{ github.workspace }}/essentialcsharpwebimage.tar
49+
cache-from: type=gha
50+
cache-to: type=gha,mode=max
51+
build-args: ACCESS_TO_NUGET_FEED=false

.github/workflows/codeql.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ jobs:
3535

3636
- name: Set up .NET Core
3737
uses: actions/setup-dotnet@v4
38-
with:
39-
global-json-file: global.json
40-
source-url: https://pkgs.dev.azure.com/intelliTect/_packaging/EssentialCSharp/nuget/v3/index.json
41-
env:
42-
NUGET_AUTH_TOKEN: ${{secrets.AZURE_DEVOPS_PAT}}
4338

4439
- name: Set up dependency caching for faster builds
4540
uses: actions/cache@v4
@@ -55,8 +50,8 @@ jobs:
5550
5651
- name: Restore with dotnet
5752
run: |
58-
dotnet restore
59-
dotnet build --configuration Release --no-restore --no-incremental
53+
dotnet restore /p:AccessToNugetFeed=false
54+
dotnet build --configuration Release --no-restore --no-incremental /p:AccessToNugetFeed=false
6055
6156
- name: Perform CodeQL Analysis
6257
uses: github/codeql-action/analyze@v3

Directory.Packages.props

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
44
<CentralPackageTransitivePinningEnabled>false</CentralPackageTransitivePinningEnabled>
55
<ToolingPackagesVersion>1.1.1.4632</ToolingPackagesVersion>
6-
<AccessToNugetFeed>true</AccessToNugetFeed>
6+
<AccessToNugetFeed>false</AccessToNugetFeed>
77
<RestoreSources>
88
https://api.nuget.org/v3/index.json;
99
</RestoreSources>
@@ -16,6 +16,8 @@
1616
<PackageVersion Include="ContentFeedNuget" Version="$(ToolingPackagesVersion)" />
1717
</ItemGroup>
1818
<ItemGroup>
19+
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" />
20+
<PackageVersion Include="Microsoft.CodeAnalysis.Common" Version="4.8.0" />
1921
<PackageVersion Include="EssentialCSharp.Shared.Models" Version="$(ToolingPackagesVersion)" />
2022
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.10" />
2123
<PackageVersion Include="AspNet.Security.OAuth.GitHub" Version="8.3.0" />
@@ -38,4 +40,4 @@
3840
<PackageVersion Include="xunit" Version="2.9.3" />
3941
<PackageVersion Include="xunit.runner.visualstudio" Version="3.0.1" />
4042
</ItemGroup>
41-
</Project>
43+
</Project>

EssentialCSharp.Web/Dockerfile

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@ WORKDIR /app
55
EXPOSE 8080
66
EXPOSE 8081
77

8-
FROM mcr.microsoft.com/dotnet/sdk:9.0.102 AS build
8+
FROM mcr.microsoft.com/dotnet/sdk:8.0.101 AS build
9+
ARG ACCESS_TO_NUGET_FEED=true
10+
ENV ACCESS_TO_NUGET_FEED=$ACCESS_TO_NUGET_FEED
911
RUN sh -c "$(curl -fsSL https://aka.ms/install-artifacts-credprovider.sh)"
1012
WORKDIR /src
1113
COPY . .
1214
RUN --mount=type=secret,id=nuget_auth_token \
13-
auth_token=$(cat /run/secrets/nuget_auth_token) && \
14-
export VSS_NUGET_EXTERNAL_FEED_ENDPOINTS="{\"endpointCredentials\": [{\"endpoint\":\"https://pkgs.dev.azure.com/intelliTect/_packaging/EssentialCSharp/nuget/v3/index.json\", \"password\":\"$auth_token\"}]}" && \
15-
dotnet restore "EssentialCSharp.Web.sln" && \
16-
dotnet build "EssentialCSharp.Web.sln" -c Release --no-restore && \
15+
if [ "$ACCESS_TO_NUGET_FEED" = "true" ]; then \
16+
auth_token=$(cat /run/secrets/nuget_auth_token) && \
17+
export VSS_NUGET_EXTERNAL_FEED_ENDPOINTS="{\"endpointCredentials\": [{\"endpoint\":\"https://pkgs.dev.azure.com/intelliTect/_packaging/EssentialCSharp/nuget/v3/index.json\", \"password\":\"$auth_token\"}]}"; \
18+
fi && \
19+
dotnet restore "EssentialCSharp.Web.sln" -p:AccessToNugetFeed=$ACCESS_TO_NUGET_FEED && \
20+
dotnet build "EssentialCSharp.Web.sln" -c Release --no-restore -p:AccessToNugetFeed=$ACCESS_TO_NUGET_FEED && \
1721
dotnet publish "EssentialCSharp.Web.sln" -c Release -p:PublishDir=/app/publish -p:UseAppHost=false --no-build
1822

1923
FROM base AS final

EssentialCSharp.Web/EssentialCSharp.Web.csproj

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Web">
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
22
<PropertyGroup>
33
<TargetFramework>net8.0</TargetFramework>
44
</PropertyGroup>
55
<ItemGroup>
6-
<PlaceholderHtmlFile Include="$(ProjectDir)Placeholders/*.html" />
7-
<PlaceholderJsonFile Include="$(ProjectDir)Placeholders/*.json" />
6+
<PlaceholderChapterOneHtmlFile Include="$(ProjectDir)/Placeholders/Chapters/01/Pages/*.html" />
7+
<PlaceholderChapterTwoHtmlFile Include="$(ProjectDir)/Placeholders/Chapters/02/Pages/*.html" />
8+
<PlaceholderSitemapJsonFile Include="$(ProjectDir)/Placeholders/sitemap.json" />
9+
<PlaceholderGuidelinesJsonFile Include="$(ProjectDir)/Placeholders/guidelines.json" />
810
</ItemGroup>
911

1012
<ItemGroup Condition="$(AccessToNugetFeed)">
@@ -20,6 +22,7 @@
2022
<PackageReference Include="Microsoft.AspNetCore.Authentication.MicrosoftAccount" />
2123
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" />
2224
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" />
25+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" />
2326
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" />
2427
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools">
2528
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
@@ -40,8 +43,10 @@
4043
</Content>
4144
</ItemGroup>
4245
<Target Condition="!$(AccessToNugetFeed)" Name="CopyPlaceholderContent" BeforeTargets="Build">
43-
<Copy SourceFiles="@(PlaceholderJsonFile)" DestinationFolder="$(ProjectDir)/Chapters/" SkipUnchangedFiles="true" />
44-
<Copy SourceFiles="@(PlaceholderHtmlFile)" DestinationFolder="$(ProjectDir)/Chapters/01/Pages/" SkipUnchangedFiles="true" />
46+
<Copy SourceFiles="@(PlaceholderSitemapJsonFile)" DestinationFolder="$(ProjectDir)/Chapters/" SkipUnchangedFiles="true" />
47+
<Copy SourceFiles="@(PlaceholderGuidelinesJsonFile)" DestinationFolder="$(ProjectDir)/Guidelines/" SkipUnchangedFiles="true" />
48+
<Copy SourceFiles="@(PlaceholderChapterOneHtmlFile)" DestinationFolder="$(ProjectDir)/Chapters/01/Pages/" SkipUnchangedFiles="true" />
49+
<Copy SourceFiles="@(PlaceholderChapterTwoHtmlFile)" DestinationFolder="$(ProjectDir)/Chapters/02/Pages/" SkipUnchangedFiles="true" />
4550
</Target>
4651

4752
<PropertyGroup>

EssentialCSharp.Web/Placeholders/01.html

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)