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
65 changes: 62 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,10 @@ jobs:
default_branch="${{ github.event.repository.default_branch }}"
echo "Default branch is: $default_branch"

# fetch and checkout default branch to make change there
# create a new branch from default branch to avoid push-to-protected-branch issues
git fetch origin $default_branch
git checkout $default_branch
branch_name="ci/bump-version-${{ steps.vars.outputs.version }}"
git checkout -b "$branch_name" origin/$default_branch || git checkout -b "$branch_name"

current=$(grep -oPm1 "(?<=<Version>)[^<]+" "$csproj" || true)
echo "Current csproj version: ${current}"
Expand All @@ -157,14 +158,72 @@ jobs:

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"
git push --set-upstream origin "$branch_name" || echo "Push failed"

echo "branch_name=${branch_name}" >> $GITHUB_OUTPUT
else
echo "CSProj already matches tag version"
fi

- name: Create Pull Request for version update
uses: actions/github-script@v7
env:
VERSION: ${{ steps.vars.outputs.version }}
TAG: ${{ steps.vars.outputs.tag }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const headBranch = `ci/bump-version-${process.env.VERSION}`;
const base = `${{ github.event.repository.default_branch }}`;
const owner = context.repo.owner;
const repo = context.repo.repo;
const title = `chore: set package version to ${process.env.VERSION} (tag ${process.env.TAG})`;
const body = `This PR updates TenJames.CompMap.csproj version to ${process.env.VERSION} (created by release workflow for tag ${process.env.TAG}).`;

// Check for existing open PR from the same head
const existing = await github.pulls.list({ owner, repo, head: `${owner}:${headBranch}`, state: 'open' });
if (existing.data && existing.data.length > 0) {
console.log(`Found existing PR: ${existing.data[0].html_url}`);
} else {
const pr = await github.pulls.create({ owner, repo, title, head: headBranch, base, body });
console.log(`Created PR: ${pr.data.html_url}`);
}

- name: Pack
run: |
dotnet pack TenJames.CompMap/TenJames.CompMap/TenJames.CompMap.csproj -c Release -o ./nupkgs /p:PackageVersion=${{ steps.vars.outputs.version }}

- name: Find generated nupkg
id: find_pkg
run: |
set -e
pkg=$(ls ./nupkgs/*.nupkg | head -n1 || true)
if [ -z "$pkg" ]; then
echo "No nupkg found in ./nupkgs"
exit 1
fi
echo "package_path=$pkg" >> $GITHUB_OUTPUT
echo "package_name=$(basename $pkg)" >> $GITHUB_OUTPUT

- name: Create GitHub Release for tag
id: create_release
uses: actions/create-release@v1
with:
tag_name: ${{ steps.vars.outputs.tag }}
release_name: ${{ steps.vars.outputs.tag }}
body: Release for tag ${{ steps.vars.outputs.tag }}
draft: false
prerelease: false
token: ${{ secrets.GITHUB_TOKEN }}

- name: Upload nupkg to Release
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ steps.find_pkg.outputs.package_path }}
asset_name: ${{ steps.find_pkg.outputs.package_name }}
asset_content_type: application/octet-stream

- name: Publish to NuGet
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
Expand Down
11 changes: 0 additions & 11 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,6 @@ A workflow was added at `.github/workflows/ci.yml` to automate verification and

- 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:

Expand Down
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.4</Version>
<Version>0.0.5</Version>
<Title>Compiletime Mapper</Title>
<Description>Map your object on compile time</Description>
<PackageProjectUrl>https://github.com/Ten-James/CompMap</PackageProjectUrl>
Expand Down