Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: CI

on:
push:
branches:
- develop
- "feature/**"
- "fix/**"
- "hotfix/**"
pull_request:
branches:
- develop
- master

# Declared here so actionlint can validate env.RUNNING_LOCALLY references below.
# ci-cd-test-run.ps1 passes --env RUNNING_LOCALLY=true to act; on real GitHub Actions
# the variable is empty so upload-artifact runs and failures are fatal.
env:
RUNNING_LOCALLY: ""

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
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
steps:
- uses: actions/checkout@v5

- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: |
10.0.x

- name: Restore
run: dotnet restore Blazing.Json.Queryable.slnx

- name: Build
run: dotnet build Blazing.Json.Queryable.slnx --no-restore --configuration Release -p:GeneratePackageOnBuild=false

- name: Test
run: |
dotnet test tests/Blazing.Json.Queryable.Tests/Blazing.Json.Queryable.Tests.csproj \
--no-build --no-restore \
--configuration Release \
--logger "trx;LogFileName=test-results.trx"

- name: Upload test results
uses: actions/upload-artifact@v7
# Skipped when running locally (ci-cd-test-run.ps1 passes --env RUNNING_LOCALLY=true to act).
# On real GitHub Actions RUNNING_LOCALLY is empty → step runs; upload failures are fatal.
if: always() && env.RUNNING_LOCALLY == ''
with:
name: test-results
path: "**/*.trx"
99 changes: 99 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: Release

on:
push:
branches:
- master

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false

jobs:
release:
name: Build, Test & Publish to NuGet
runs-on: ubuntu-latest
Comment thread
gragra33 marked this conversation as resolved.
permissions:
contents: write
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0

- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: |
10.0.x

- name: Restore
run: dotnet restore Blazing.Json.Queryable.slnx

- name: Build
run: dotnet build Blazing.Json.Queryable.slnx --no-restore --configuration Release -p:GeneratePackageOnBuild=false

- name: Test
run: |
dotnet test tests/Blazing.Json.Queryable.Tests/Blazing.Json.Queryable.Tests.csproj \
--no-build --no-restore \
--configuration Release

- name: Extract version from project file
id: version
run: |
VERSION=$(grep -m1 '<Version>' src/Blazing.Json.Queryable/Blazing.Json.Queryable.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

Comment thread
gragra33 marked this conversation as resolved.
- name: Fail if this version was already released
if: steps.tag_check.outputs.exists == 'true'
run: |
echo "::error::Release tag ${{ steps.version.outputs.tag }} already exists. Bump the project version before pushing to master."
exit 1

- name: Pack NuGet package
if: steps.tag_check.outputs.exists == 'false'
run: |
dotnet pack src/Blazing.Json.Queryable/Blazing.Json.Queryable.csproj \
--no-build --no-restore --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/Blazing.Json.Queryable.${{ steps.version.outputs.version }}.nupkg \
./artifacts/Blazing.Json.Queryable.${{ steps.version.outputs.version }}.snupkg

- name: Push Blazing.Json.Queryable to NuGet.org
if: steps.tag_check.outputs.exists == 'false'
run: |
dotnet nuget push \
"./artifacts/Blazing.Json.Queryable.${{ steps.version.outputs.version }}.nupkg" \
--api-key ${{ secrets.NUGET_API_KEY }} \
--source https://api.nuget.org/v3/index.json \
--skip-duplicate

- name: Push Blazing.Json.Queryable symbols to NuGet.org
if: steps.tag_check.outputs.exists == 'false'
run: |
dotnet nuget push \
"./artifacts/Blazing.Json.Queryable.${{ steps.version.outputs.version }}.snupkg" \
--api-key ${{ secrets.NUGET_API_KEY }} \
--source https://api.nuget.org/v3/index.json \
--skip-duplicate
Loading