-
Notifications
You must be signed in to change notification settings - Fork 12
Harden CI: Artifactory OIDC via sdk-actions, NuGet lockfiles, scoped build #146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9579d32
Harden CI: Artifactory OIDC, NuGet lockfiles, tightened permissions
MichaelGHSeg 66bd706
Fix shell injection: pass github.ref_name via env var in deploy workflow
MichaelGHSeg eac9c64
fix(ci): correct Artifactory OIDC provider name and exchange pattern
MichaelGHSeg 835eea8
fix(ci): harden OIDC error redaction to cover all token fields
MichaelGHSeg d4c8bc9
Merge remote-tracking branch 'origin/main' into ci/harden-build-publish
MichaelGHSeg 9c361c3
refactor(ci): use twilio/sdk-actions for Artifactory OIDC
MichaelGHSeg 3f225bf
fix(ci): publish from the deployment environment, where the key lives
MichaelGHSeg 780d847
fix(ci): align the dotnet SDK with the targeted frameworks, scope the…
MichaelGHSeg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| name: CI | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| pull_request: | ||
| branches: [main] | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| id-token: write | ||
| contents: read | ||
|
|
||
| env: | ||
| ARTIFACTORY_URL: ${{ vars.ARTIFACTORY_URL }} | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ${{ github.event.pull_request.head.repo.fork && 'ubuntu-latest' || 'ubuntu-x64' }} | ||
|
|
||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 | ||
|
|
||
| - name: Setup .NET SDK | ||
| uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 # v4 | ||
| with: | ||
| # Tests target net10.0 and net6.0, so both runtimes are needed to | ||
| # execute them; the 10 SDK alone only covers the former. | ||
| dotnet-version: | | ||
| 6.0.x | ||
| 10.0.x | ||
|
|
||
| - name: Configure Artifactory NuGet source | ||
| if: ${{ !github.event.pull_request.head.repo.fork }} | ||
| uses: twilio/sdk-actions/artifactory-oidc@c94e420aa64ea686ff25bb03d4c66cdaf8e523e4 # main | ||
| with: | ||
| ecosystem: dotnet | ||
| provider-name: github-actions-segmentio | ||
|
|
||
| # Scoped to the library and its tests via the solution filter. The sample | ||
| # projects in the .sln include legacy msbuild Xamarin and Unity ones, which | ||
| # dotnet cannot restore or build on a Linux runner at all. | ||
| - name: Restore dependencies | ||
| run: dotnet restore Analytics-CSharp.slnf --locked-mode | ||
|
|
||
| - name: Build | ||
| run: dotnet build Analytics-CSharp.slnf --no-restore | ||
|
|
||
| - name: Test | ||
| run: dotnet test Analytics-CSharp.slnf --no-build --logger "trx;LogFileName=test-results.trx" | ||
|
|
||
| - name: Upload test results | ||
| if: always() | ||
| uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 | ||
| with: | ||
| name: test-results | ||
| path: '**/TestResults/*.trx' | ||
| if-no-files-found: ignore |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| name: Deploy | ||
|
|
||
| on: | ||
| push: | ||
| tags: | ||
| - '[0-9]+.[0-9]+.[0-9]+' | ||
| - '[0-9]+.[0-9]+.[0-9]+-alpha.[0-9]+' | ||
|
|
||
| permissions: | ||
| id-token: write | ||
| contents: read | ||
|
|
||
| env: | ||
| ARTIFACTORY_URL: ${{ vars.ARTIFACTORY_URL }} | ||
|
|
||
| jobs: | ||
| verify: | ||
| runs-on: ubuntu-x64 | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 | ||
|
|
||
| - name: Get tag | ||
| id: tag | ||
| run: echo "version=${GITHUB_REF#refs/tags/}" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Verify tag matches package version | ||
| run: | | ||
| VERSION=$(grep '<Version>' Analytics-CSharp/Analytics-CSharp.csproj | sed "s@.*<Version>\(.*\)</Version>.*@\1@") | ||
| if [ "${{ steps.tag.outputs.version }}" != "$VERSION" ]; then | ||
| echo "::error::Tag ${{ steps.tag.outputs.version }} does not match the package version ($VERSION)" | ||
| exit 1 | ||
| fi | ||
|
|
||
| - name: Setup .NET SDK | ||
| uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 # v4 | ||
| with: | ||
| dotnet-version: '8.0.x' | ||
|
|
||
| - name: Configure Artifactory NuGet source | ||
| uses: twilio/sdk-actions/artifactory-oidc@c94e420aa64ea686ff25bb03d4c66cdaf8e523e4 # main | ||
| with: | ||
| ecosystem: dotnet | ||
| provider-name: github-actions-segmentio | ||
|
|
||
| - name: Restore dependencies | ||
| run: dotnet restore --locked-mode | ||
|
|
||
| - name: Build | ||
| run: dotnet build --no-restore | ||
|
|
||
| - name: Test | ||
| run: dotnet test --no-build | ||
|
|
||
| publish: | ||
| needs: verify | ||
| runs-on: ubuntu-x64 | ||
| # Must be `deployment`: NUGET_API_KEY is an environment secret scoped to it, | ||
| # and environment secrets are invisible to jobs using any other name. | ||
| # Naming a non-existent environment also silently creates an unprotected one. | ||
| environment: deployment | ||
|
|
||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 | ||
|
|
||
| - name: Setup .NET SDK | ||
| uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 # v4 | ||
| with: | ||
| dotnet-version: '8.0.x' | ||
|
|
||
| - name: Configure Artifactory NuGet source | ||
| uses: twilio/sdk-actions/artifactory-oidc@c94e420aa64ea686ff25bb03d4c66cdaf8e523e4 # main | ||
| with: | ||
| ecosystem: dotnet | ||
| provider-name: github-actions-segmentio | ||
|
|
||
| - name: Restore dependencies | ||
| run: dotnet restore --locked-mode | ||
|
|
||
| - name: Pack | ||
| run: dotnet pack --no-restore -c Release | ||
|
|
||
| - name: Push to NuGet.org | ||
| run: | | ||
| dotnet nuget push "**/*.nupkg" \ | ||
| --source https://api.nuget.org/v3/index.json \ | ||
| --api-key ${{ secrets.NUGET_API_KEY }} \ | ||
| --skip-duplicate | ||
|
|
||
| - name: Create GitHub release | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| REF_NAME: ${{ github.ref_name }} | ||
| run: | | ||
| gh release create "$REF_NAME" \ | ||
| --title "$REF_NAME" \ | ||
| --generate-notes | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "solution": { | ||
| "path": "Analytics-CSharp.sln", | ||
| "projects": [ | ||
| "Analytics-CSharp\\Analytics-CSharp.csproj", | ||
| "Tests\\Tests.csproj" | ||
| ] | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.