Skip to content

Merge branch 'develop' #12

Merge branch 'develop'

Merge branch 'develop' #12

name: Build and Publish NuGet
on:
push:
branches:
- main
- develop
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v3.2.1
with:
versionSpec: '6.x'
- name: Determine Version
id: gitversion
uses: gittools/actions/gitversion/execute@v3.2.1
- name: Set package version
id: version
run: |
if [ "${{ github.ref }}" = "refs/heads/main" ]; then
echo "packageVersion=${{ steps.gitversion.outputs.majorMinorPatch }}" >> "$GITHUB_OUTPUT"
else
echo "packageVersion=${{ steps.gitversion.outputs.fullSemVer }}" >> "$GITHUB_OUTPUT"
fi
- name: Display Version
run: echo "Version ${{ steps.version.outputs.packageVersion }}"
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '10.0.x'
- name: Restore
run: dotnet restore src/Umbraco.Community.ValidationAttributes.csproj
- name: Build
run: dotnet build src/Umbraco.Community.ValidationAttributes.csproj --configuration Release --no-restore -p:Version="${{ steps.version.outputs.packageVersion }}"
- name: Pack
run: dotnet pack src/Umbraco.Community.ValidationAttributes.csproj --configuration Release --no-build --output ./artifacts -p:PackageVersion="${{ steps.version.outputs.packageVersion }}"
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: nuget-package
path: ./artifacts/*.nupkg
- name: Push to NuGet
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop')
run: dotnet nuget push ./artifacts/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
- name: Create GitHub Release
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop')
uses: actions/github-script@v7
with:
script: |
const version = '${{ steps.version.outputs.packageVersion }}';
const isPrerelease = '${{ github.ref }}' === 'refs/heads/develop';
const branch = isPrerelease ? 'develop' : 'main';
const { data: commits } = await github.rest.repos.listCommits({
owner: context.repo.owner,
repo: context.repo.repo,
sha: branch,
per_page: 50
});
const lastRelease = await github.rest.repos.getLatestRelease({
owner: context.repo.owner,
repo: context.repo.repo
}).catch(() => null);
const since = lastRelease?.data?.created_at;
const relevantCommits = since
? commits.filter(c => new Date(c.commit.committer.date) > new Date(since))
: commits;
const notes = relevantCommits
.map(c => `- ${c.commit.message.split('\n')[0]}`)
.join('\n');
await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: `v${version}`,
name: `v${version}`,
body: `## What's Changed\n\n${notes}\n\n**NuGet:** [Umbraco.Community.ValidationAttributes v${version}](https://www.nuget.org/packages/Umbraco.Community.ValidationAttributes/${version})`,
draft: false,
prerelease: isPrerelease
});