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
176 changes: 176 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
name: CI

permissions:
contents: write
packages: write

on:
pull_request:
types: [opened, synchronize, reopened]
push:
tags:
- 'v*.*.*'

jobs:
build:
name: Restore, Build and Test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '10.x'

- name: Restore
run: dotnet restore

- name: Build
run: dotnet build TenJames.CompMap.sln -c Release --no-restore

- name: Test (if present)
run: |
if [ -d "TenJames.CompMap/TenJames.CompMap.Tests" ]; then
dotnet test TenJames.CompMap/TenJames.CompMap.Tests -c Release --no-build --verbosity normal
else
echo "No tests found"
fi

bump-version:
name: Bump package version (patch) on PR
if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository }}
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout (full)
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Git
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"

- name: Bump package version (patch) in TenJames.CompMap.csproj
id: bump
run: |
set -e
csproj="TenJames.CompMap/TenJames.CompMap/TenJames.CompMap.csproj"
if [ ! -f "$csproj" ]; then
echo "CSProj not found: $csproj"
exit 0
fi

# extract version like 1.2.3
version=$(grep -oPm1 "(?<=<Version>)[^<]+" "$csproj" || true)
if [ -z "$version" ]; then
echo "No <Version> found in $csproj"
exit 0
fi

echo "Current version: $version"

IFS='.' read -r major minor patch <<< "$version"
if [ -z "$patch" ]; then
echo "Version format unexpected: $version"
exit 1
fi

new_patch=$((patch + 1))
new_version="${major}.${minor}.${new_patch}"

# update the csproj
sed -i "s|<Version>${version}</Version>|<Version>${new_version}</Version>|" "$csproj"

git add "$csproj"
git commit -m "ci: bump version to ${new_version} [skip ci]" || echo "No changes to commit"

# push back to the PR branch
git push origin HEAD:refs/heads/${{ github.event.pull_request.head.ref }} || echo "Push failed (maybe from a fork)"

echo "new_version=${new_version}" >> $GITHUB_OUTPUT

publish:
name: Pack, update csproj and publish on tag
if: startsWith(github.ref, 'refs/tags/')
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '10.x'

- name: Determine package version from tag
id: vars
run: |
TAG=${GITHUB_REF#refs/tags/}
VERSION=${TAG#v}
echo "tag=${TAG}" >> $GITHUB_OUTPUT
echo "version=${VERSION}" >> $GITHUB_OUTPUT

- name: Configure Git for pushing
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"

- name: Update csproj version and push to default branch
env:
VERSION: ${{ steps.vars.outputs.version }}
TAG: ${{ steps.vars.outputs.tag }}
run: |
set -e
csproj="TenJames.CompMap/TenJames.CompMap/TenJames.CompMap.csproj"
if [ ! -f "$csproj" ]; then
echo "CSProj not found: $csproj"
exit 0
fi

default_branch="${{ github.event.repository.default_branch }}"
echo "Default branch is: $default_branch"

# fetch and checkout default branch to make change there
git fetch origin $default_branch
git checkout $default_branch

current=$(grep -oPm1 "(?<=<Version>)[^<]+" "$csproj" || true)
echo "Current csproj version: ${current}"
echo "Desired version: ${VERSION}"

if [ "${current}" != "${VERSION}" ]; then
if grep -q "<Version>" "$csproj"; then
sed -i "s|<Version>.*</Version>|<Version>${VERSION}</Version>|" "$csproj"
else
# insert Version element after the first PropertyGroup using perl to avoid quoting issues
perl -0777 -pe "s/(<PropertyGroup>\s*)/$1 <Version>${VERSION}<\/Version>\n/s if !/<Version>/s" -i "$csproj"
fi

git add "$csproj"
git commit -m "chore: set package version to ${VERSION} (tag ${TAG}) [skip ci]" || echo "No changes to commit"
git push origin $default_branch || echo "Push failed"
else
echo "CSProj already matches tag version"
fi
- name: Pack
run: |
dotnet pack TenJames.CompMap/TenJames.CompMap/TenJames.CompMap.csproj -c Release -o ./nupkgs /p:PackageVersion=${{ steps.vars.outputs.version }}

- name: Publish to NuGet
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
run: |
if [ -z "$NUGET_API_KEY" ]; then
echo "NUGET_API_KEY not set - skipping publish"
exit 0
fi
dotnet nuget push ./nupkgs/*.nupkg -k "$NUGET_API_KEY" -s https://api.nuget.org/v3/index.json --skip-duplicate
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ bin/
obj/
/packages/
riderModule.iml
/_ReSharper.Caches/
/_ReSharper.Caches/
.idea/
13 changes: 0 additions & 13 deletions .idea/.idea.TenJames.CompMap/.idea/.gitignore

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

4 changes: 0 additions & 4 deletions .idea/.idea.TenJames.CompMap/.idea/encodings.xml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/.idea.TenJames.CompMap/.idea/indexLayout.xml

This file was deleted.

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/.idea.TenJames.CompMap/.idea/vcs.xml

This file was deleted.

36 changes: 36 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,39 @@ services.AddTransient<IMapper, BaseMap>();
Add Attributes to your DTO classes and then enjoy the generated mapping methods :)


---

## Continuous Integration (GitHub Actions)

A workflow was added at `.github/workflows/ci.yml` to automate verification and publishing:

- On pull requests (opened/synchronized/reopened):
- Restores, builds the solution and runs tests (if the `TenJames.CompMap.Tests` project exists).
- If the PR branch belongs to the same repository (not a fork), the workflow increments the patch version in `TenJames.CompMap/TenJames.CompMap/TenJames.CompMap.csproj` (e.g. 0.0.2 -> 0.0.3), commits the change and pushes it back to the PR branch, then adds a comment to the PR with the new version. This helps keep package versions unique for CI package artifacts.

- On push of a tag matching `v*.*.*` (for example `v1.2.3`):
- The workflow builds the solution, packs `TenJames.CompMap` with the version taken from the tag (strips a leading `v` if present), and attempts to publish the resulting `.nupkg` to NuGet.org.
- Publishing runs only when a `NUGET_API_KEY` secret is set in the repository settings; otherwise the publish step is skipped.

Notes and requirements:

- Ensure the repository secret `NUGET_API_KEY` is set if you want automatic publishing to NuGet.org.
- The PR auto-bump only runs when the PR head repo equals this repository (forked PRs are skipped to avoid push permission errors).
- The workflow uses `dotnet 10.x` (actions/setup-dotnet@v3). Adjust the SDK version in the workflow if you need a different runtime.

Quick commands (run locally) — fish shell:

```fish
# Build and test locally
dotnet restore
dotnet build TenJames.CompMap.sln -c Release
dotnet test TenJames.CompMap/TenJames.CompMap.Tests -c Release

# Create a tag and push (publish via CI)
git tag v1.2.3
git push origin v1.2.3
```

If you'd prefer bumping major/minor instead of patch in PRs, or if you want bumping to commit via a bot account or a separate branch/PR, I can adapt the workflow.

---
2 changes: 1 addition & 1 deletion TenJames.CompMap/TenJames.CompMap/TenJames.CompMap.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</PropertyGroup>

<PropertyGroup>
<Version>0.0.2</Version>
<Version>0.0.4</Version>
<Title>Compiletime Mapper</Title>
<Description>Map your object on compile time</Description>
<PackageProjectUrl>https://github.com/Ten-James/CompMap</PackageProjectUrl>
Expand Down