-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add GitHub Actions CI/CD workflows and local test runner #11
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
2 commits
Select commit
Hold shift + click to select a range
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,70 @@ | ||
| name: CI | ||
|
|
||
| "on": | ||
| push: | ||
| branches: | ||
| - develop | ||
| - "feature/**" | ||
| - "fix/**" | ||
| - "hotfix/**" | ||
| pull_request: | ||
| branches: | ||
| - develop | ||
| - master | ||
|
|
||
| jobs: | ||
| validate-branch: | ||
| name: Validate Branch Name | ||
| runs-on: ubuntu-latest | ||
| if: github.event_name == 'pull_request' | ||
| steps: | ||
| - name: Check branch naming convention | ||
| env: | ||
| BRANCH: ${{ github.head_ref }} | ||
| run: | | ||
| if [[ ! "$BRANCH" =~ ^(feature|fix|hotfix)/.+ ]] && [[ "$BRANCH" != "develop" ]]; then | ||
| echo "::error::Branch '$BRANCH' does not follow naming conventions." | ||
| echo "::error::PR source branches must be 'develop' or prefixed with 'feature/', 'fix/', or 'hotfix/'." | ||
| exit 1 | ||
| fi | ||
| echo "Branch '$BRANCH' follows naming conventions." | ||
|
|
||
| build-and-test: | ||
| name: Build & Test (${{ matrix.framework }}) | ||
| needs: validate-branch | ||
| # Run on push events (validate-branch skipped) OR on valid PRs (validate-branch succeeded) | ||
| if: always() && (needs.validate-branch.result == 'success' || needs.validate-branch.result == 'skipped') | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| framework: ["net8.0", "net9.0", "net10.0"] | ||
| steps: | ||
| - uses: actions/checkout@v5 | ||
| - name: Setup .NET | ||
| uses: actions/setup-dotnet@v5 | ||
| with: | ||
| dotnet-version: | | ||
| 8.0.x | ||
| 9.0.x | ||
| 10.0.x | ||
| - name: Restore | ||
| run: dotnet restore src/System.Text.Json.Stream.CI.slnf | ||
| - name: Build | ||
| run: dotnet build src/System.Text.Json.Stream.CI.slnf --no-restore --configuration Release -p:GeneratePackageOnBuild=false | ||
| - name: Test (${{ matrix.framework }}) | ||
| run: | | ||
| dotnet test src/System.Text.Json.Stream.Tests/System.Text.Json.Stream.Tests.csproj \ | ||
| --no-build --no-restore \ | ||
| --configuration Release --framework ${{ matrix.framework }} \ | ||
| --logger "trx;LogFileName=test-results-${{ matrix.framework }}.trx" | ||
| - name: Upload test results | ||
| uses: actions/upload-artifact@v7 | ||
| if: always() | ||
| # continue-on-error is intentionally true: when running locally via act, ACTIONS_RUNTIME_TOKEN | ||
| # is not available and upload-artifact always fails. Using env.ACT == 'true' trips actionlint | ||
| # (ACT is not a standard GitHub context variable), so we keep the unconditional true here. | ||
| continue-on-error: true | ||
|
gragra33 marked this conversation as resolved.
|
||
| with: | ||
| name: test-results-${{ matrix.framework }} | ||
| path: "**/*.trx" | ||
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,88 @@ | ||
| name: Release | ||
|
|
||
| "on": | ||
| push: | ||
| branches: | ||
| - master | ||
|
|
||
| jobs: | ||
| release: | ||
| name: Build, Test & Publish to NuGet | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write | ||
| steps: | ||
| - uses: actions/checkout@v5 | ||
| with: | ||
| fetch-depth: 0 | ||
| - name: Setup .NET | ||
| uses: actions/setup-dotnet@v5 | ||
| with: | ||
| dotnet-version: | | ||
| 8.0.x | ||
| 9.0.x | ||
| 10.0.x | ||
| - name: Restore | ||
| run: dotnet restore src/System.Text.Json.Stream.CI.slnf | ||
| - name: Build | ||
| run: dotnet build src/System.Text.Json.Stream.CI.slnf --no-restore --configuration Release -p:GeneratePackageOnBuild=false | ||
| - name: Test (net8.0) | ||
| run: | | ||
| dotnet test src/System.Text.Json.Stream.Tests/System.Text.Json.Stream.Tests.csproj \ | ||
| --no-build --no-restore --configuration Release --framework net8.0 | ||
| - name: Test (net9.0) | ||
| run: | | ||
| dotnet test src/System.Text.Json.Stream.Tests/System.Text.Json.Stream.Tests.csproj \ | ||
| --no-build --no-restore --configuration Release --framework net9.0 | ||
| - name: Test (net10.0) | ||
| run: | | ||
| dotnet test src/System.Text.Json.Stream.Tests/System.Text.Json.Stream.Tests.csproj \ | ||
| --no-build --no-restore --configuration Release --framework net10.0 | ||
| - name: Extract version from csproj | ||
| id: version | ||
| run: | | ||
| VERSION=$(grep -m1 '<Version>' src/System.Text.Json.Stream/System.Text.Json.Stream.csproj \ | ||
| | sed 's/.*<Version>//;s/<\/Version>.*//' \ | ||
| | tr -d '[:space:]') | ||
| echo "version=$VERSION" >> $GITHUB_OUTPUT | ||
| echo "tag=v$VERSION" >> $GITHUB_OUTPUT | ||
| echo "Resolved version: $VERSION" | ||
| - name: Check if this version was already released | ||
| id: tag_check | ||
| run: | | ||
| if git ls-remote --tags origin "refs/tags/v${{ steps.version.outputs.version }}" | grep -q .; then | ||
| echo "exists=true" >> $GITHUB_OUTPUT | ||
| else | ||
| echo "exists=false" >> $GITHUB_OUTPUT | ||
| fi | ||
| - name: Pack NuGet package | ||
| if: steps.tag_check.outputs.exists == 'false' | ||
| run: | | ||
| dotnet pack src/System.Text.Json.Stream/System.Text.Json.Stream.csproj \ | ||
| --no-build --configuration Release --output ./artifacts | ||
| - name: Create GitHub Release | ||
| if: steps.tag_check.outputs.exists == 'false' | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| run: | | ||
| gh release create "${{ steps.version.outputs.tag }}" \ | ||
| --title "Release ${{ steps.version.outputs.tag }}" \ | ||
| --generate-notes \ | ||
| ./artifacts/Utf8JsonAsyncStreamReader.${{ steps.version.outputs.version }}.nupkg \ | ||
| ./artifacts/Utf8JsonAsyncStreamReader.${{ steps.version.outputs.version }}.snupkg | ||
| - name: Push Utf8JsonAsyncStreamReader to NuGet.org | ||
| if: steps.tag_check.outputs.exists == 'false' | ||
| run: | | ||
| dotnet nuget push \ | ||
| "./artifacts/Utf8JsonAsyncStreamReader.${{ steps.version.outputs.version }}.nupkg" \ | ||
| --api-key ${{ secrets.NUGET_API_KEY }} \ | ||
| --source https://api.nuget.org/v3/index.json \ | ||
| --skip-duplicate | ||
| - name: Push Utf8JsonAsyncStreamReader symbols to NuGet.org | ||
| if: steps.tag_check.outputs.exists == 'false' | ||
| run: | | ||
| dotnet nuget push \ | ||
| "./artifacts/Utf8JsonAsyncStreamReader.${{ steps.version.outputs.version }}.snupkg" \ | ||
| --api-key ${{ secrets.NUGET_API_KEY }} \ | ||
| --source https://api.nuget.org/v3/index.json \ | ||
| --skip-duplicate |
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.