Skip to content

Merge pull request #74 from myarichuk/chore/convenience-functions-utf… #179

Merge pull request #74 from myarichuk/chore/convenience-functions-utf…

Merge pull request #74 from myarichuk/chore/convenience-functions-utf… #179

Workflow file for this run

name: CI & CD
on:
push:
branches:
- main
pull_request:
branches:
- main
permissions:
contents: write
jobs:
build_and_test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
8.0.x
9.0.x
10.0.x
dotnet-quality: preview
- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v3.0.0
with:
versionSpec: '5.x'
- name: Determine Version
id: gitversion
uses: gittools/actions/gitversion/execute@v3.0.0
with:
useConfigFile: true
- name: Restore dependencies
run: dotnet restore SharpArena.sln
- name: Build
run: dotnet build SharpArena.sln --no-restore -c Release /p:Version=${{ steps.gitversion.outputs.AssemblySemVer }} /p:InformationalVersion=${{ steps.gitversion.outputs.InformationalVersion }}
- name: Test
run: dotnet test SharpArena.sln --no-build -c Release --verbosity normal
- name: Check Tag Exists
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
id: check_tag
run: |
if git ls-remote --tags origin | grep -q "refs/tags/v${{ steps.gitversion.outputs.SemVer }}$"; then
echo "Tag v${{ steps.gitversion.outputs.SemVer }} already exists. Skipping."
echo "TAG_EXISTS=true" >> $GITHUB_ENV
else
echo "TAG_EXISTS=false" >> $GITHUB_ENV
fi
- name: Generate Release Notes
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && env.TAG_EXISTS != 'true'
run: |
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
if [ -z "$PREV_TAG" ]; then
git log --pretty=format:"- %s" | grep -E "^- (feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)" > RELEASE_NOTES.txt || echo "Initial release" > RELEASE_NOTES.txt
else
git log ${PREV_TAG}..HEAD --pretty=format:"- %s" | grep -E "^- (feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)" > RELEASE_NOTES.txt || echo "No semantic changes" > RELEASE_NOTES.txt
fi
- name: Tag Repository
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && env.TAG_EXISTS != 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag v${{ steps.gitversion.outputs.SemVer }}
git push origin v${{ steps.gitversion.outputs.SemVer }}
- name: Pack
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && env.TAG_EXISTS != 'true'
run: dotnet pack src/SharpArena/SharpArena.csproj -c Release --no-build /p:PackageVersion=${{ steps.gitversion.outputs.NuGetVersionV2 }} -o ./artifacts
- name: Create Release
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && env.TAG_EXISTS != 'true'
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ steps.gitversion.outputs.SemVer }}
name: Release v${{ steps.gitversion.outputs.SemVer }}
generate_release_notes: true
files: ./artifacts/*.nupkg
- name: Push to NuGet
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && env.TAG_EXISTS != 'true'
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
run: |
if [ -n "$NUGET_API_KEY" ]; then
dotnet nuget push ./artifacts/*.nupkg -k $NUGET_API_KEY -s https://api.nuget.org/v3/index.json --skip-duplicate
else
echo "NUGET_API_KEY is empty. Skipping NuGet push."
fi