From 48e94c673578605e00805b83d6defc5d10461db0 Mon Sep 17 00:00:00 2001 From: James Date: Fri, 14 Nov 2025 20:49:58 +0100 Subject: [PATCH 1/4] cicd --- .github/workflows/ci.yml | 191 ++++++++++++++++++ .gitignore | 3 +- .idea/.idea.TenJames.CompMap/.idea/.gitignore | 13 -- .../.idea/copilot.data.migration.agent.xml | 6 - .../.idea/copilot.data.migration.ask.xml | 6 - .../copilot.data.migration.ask2agent.xml | 6 - .../.idea/copilot.data.migration.edit.xml | 6 - .../.idea/encodings.xml | 4 - .../.idea/indexLayout.xml | 8 - .../inspectionProfiles/Project_Default.xml | 12 -- .idea/.idea.TenJames.CompMap/.idea/vcs.xml | 6 - Readme.md | 36 ++++ 12 files changed, 229 insertions(+), 68 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .idea/.idea.TenJames.CompMap/.idea/.gitignore delete mode 100644 .idea/.idea.TenJames.CompMap/.idea/copilot.data.migration.agent.xml delete mode 100644 .idea/.idea.TenJames.CompMap/.idea/copilot.data.migration.ask.xml delete mode 100644 .idea/.idea.TenJames.CompMap/.idea/copilot.data.migration.ask2agent.xml delete mode 100644 .idea/.idea.TenJames.CompMap/.idea/copilot.data.migration.edit.xml delete mode 100644 .idea/.idea.TenJames.CompMap/.idea/encodings.xml delete mode 100644 .idea/.idea.TenJames.CompMap/.idea/indexLayout.xml delete mode 100644 .idea/.idea.TenJames.CompMap/.idea/inspectionProfiles/Project_Default.xml delete mode 100644 .idea/.idea.TenJames.CompMap/.idea/vcs.xml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..bca1154 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,191 @@ +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 "(?<=)[^<]+" "$csproj" || true) + if [ -z "$version" ]; then + echo "No 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}|${new_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 + + - name: Comment on PR with new version + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const pr = context.payload.pull_request.number; + const version = "${{ steps.bump.outputs.new_version }}"; + await github.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: pr, + body: `CI bumped package version to ${version}` + }); + + 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 "(?<=)[^<]+" "$csproj" || true) + echo "Current csproj version: ${current}" + echo "Desired version: ${VERSION}" + + if [ "${current}" != "${VERSION}" ]; then + if grep -q "" "$csproj"; then + sed -i "s|.*|${VERSION}|" "$csproj" + else + # insert Version element after the first PropertyGroup using perl to avoid quoting issues + perl -0777 -pe "s/(\s*)/$1 ${VERSION}<\/Version>\n/s if !//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 diff --git a/.gitignore b/.gitignore index add57be..39c9242 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ bin/ obj/ /packages/ riderModule.iml -/_ReSharper.Caches/ \ No newline at end of file +/_ReSharper.Caches/ +.idea/ diff --git a/.idea/.idea.TenJames.CompMap/.idea/.gitignore b/.idea/.idea.TenJames.CompMap/.idea/.gitignore deleted file mode 100644 index bbe0ece..0000000 --- a/.idea/.idea.TenJames.CompMap/.idea/.gitignore +++ /dev/null @@ -1,13 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Rider ignored files -/modules.xml -/contentModel.xml -/projectSettingsUpdater.xml -/.idea.TenJames.CompMap.iml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/.idea/.idea.TenJames.CompMap/.idea/copilot.data.migration.agent.xml b/.idea/.idea.TenJames.CompMap/.idea/copilot.data.migration.agent.xml deleted file mode 100644 index 4ea72a9..0000000 --- a/.idea/.idea.TenJames.CompMap/.idea/copilot.data.migration.agent.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/.idea.TenJames.CompMap/.idea/copilot.data.migration.ask.xml b/.idea/.idea.TenJames.CompMap/.idea/copilot.data.migration.ask.xml deleted file mode 100644 index 7ef04e2..0000000 --- a/.idea/.idea.TenJames.CompMap/.idea/copilot.data.migration.ask.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/.idea.TenJames.CompMap/.idea/copilot.data.migration.ask2agent.xml b/.idea/.idea.TenJames.CompMap/.idea/copilot.data.migration.ask2agent.xml deleted file mode 100644 index 1f2ea11..0000000 --- a/.idea/.idea.TenJames.CompMap/.idea/copilot.data.migration.ask2agent.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/.idea.TenJames.CompMap/.idea/copilot.data.migration.edit.xml b/.idea/.idea.TenJames.CompMap/.idea/copilot.data.migration.edit.xml deleted file mode 100644 index 8648f94..0000000 --- a/.idea/.idea.TenJames.CompMap/.idea/copilot.data.migration.edit.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/.idea.TenJames.CompMap/.idea/encodings.xml b/.idea/.idea.TenJames.CompMap/.idea/encodings.xml deleted file mode 100644 index df87cf9..0000000 --- a/.idea/.idea.TenJames.CompMap/.idea/encodings.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/.idea.TenJames.CompMap/.idea/indexLayout.xml b/.idea/.idea.TenJames.CompMap/.idea/indexLayout.xml deleted file mode 100644 index 7b08163..0000000 --- a/.idea/.idea.TenJames.CompMap/.idea/indexLayout.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/.idea.TenJames.CompMap/.idea/inspectionProfiles/Project_Default.xml b/.idea/.idea.TenJames.CompMap/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index 06bb031..0000000 --- a/.idea/.idea.TenJames.CompMap/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/.idea.TenJames.CompMap/.idea/vcs.xml b/.idea/.idea.TenJames.CompMap/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/.idea.TenJames.CompMap/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/Readme.md b/Readme.md index 1e32257..f674ed9 100644 --- a/Readme.md +++ b/Readme.md @@ -125,3 +125,39 @@ services.AddTransient(); 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. + +--- From 437f10dac265f9e885c28c7fcd0c74477a44f4b4 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 14 Nov 2025 19:52:58 +0000 Subject: [PATCH 2/4] ci: bump version to 0.0.3 [skip ci] --- TenJames.CompMap/TenJames.CompMap/TenJames.CompMap.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TenJames.CompMap/TenJames.CompMap/TenJames.CompMap.csproj b/TenJames.CompMap/TenJames.CompMap/TenJames.CompMap.csproj index 707a176..bb1493f 100644 --- a/TenJames.CompMap/TenJames.CompMap/TenJames.CompMap.csproj +++ b/TenJames.CompMap/TenJames.CompMap/TenJames.CompMap.csproj @@ -14,7 +14,7 @@ - 0.0.2 + 0.0.3 Compiletime Mapper Map your object on compile time https://github.com/Ten-James/CompMap From ff07c5a4bdd77e81ccfad02748c2be23a94cfa98 Mon Sep 17 00:00:00 2001 From: James Date: Fri, 14 Nov 2025 20:58:59 +0100 Subject: [PATCH 3/4] no comments --- .github/workflows/ci.yml | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bca1154..61607ba 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -95,20 +95,6 @@ jobs: echo "new_version=${new_version}" >> $GITHUB_OUTPUT - - name: Comment on PR with new version - uses: actions/github-script@v7 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - const pr = context.payload.pull_request.number; - const version = "${{ steps.bump.outputs.new_version }}"; - await github.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: pr, - body: `CI bumped package version to ${version}` - }); - publish: name: Pack, update csproj and publish on tag if: startsWith(github.ref, 'refs/tags/') @@ -175,7 +161,6 @@ jobs: 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 }} From 026891bd4bbed6b83a3a8595aa6919e07dbeb83b Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 14 Nov 2025 20:00:27 +0000 Subject: [PATCH 4/4] ci: bump version to 0.0.4 [skip ci] --- TenJames.CompMap/TenJames.CompMap/TenJames.CompMap.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TenJames.CompMap/TenJames.CompMap/TenJames.CompMap.csproj b/TenJames.CompMap/TenJames.CompMap/TenJames.CompMap.csproj index bb1493f..0ea6af7 100644 --- a/TenJames.CompMap/TenJames.CompMap/TenJames.CompMap.csproj +++ b/TenJames.CompMap/TenJames.CompMap/TenJames.CompMap.csproj @@ -14,7 +14,7 @@ - 0.0.3 + 0.0.4 Compiletime Mapper Map your object on compile time https://github.com/Ten-James/CompMap