Skip to content

Commit

Permalink
rework auto publish script
Browse files Browse the repository at this point in the history
  • Loading branch information
lofcz committed Jan 9, 2025
1 parent 998315c commit 10c32ad
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 48 deletions.
121 changes: 74 additions & 47 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,71 @@ jobs:
runs-on: ubuntu-latest

steps:
# Checkout repository with full history
- uses: actions/checkout@v3
with:
fetch-depth: 0

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

# Setup
- name: Install GitVersion
uses: gittools/actions/gitversion/[email protected]
with:
preferLatestVersion: true

# Fetch version
- name: Determine Version
id: gitversion
uses: gittools/actions/gitversion/[email protected]
# Check which projects changed and calculate their new versions
- name: Check Changes and Calculate Versions
id: version_check
run: |
SHOULD_RELEASE="false"
CHANGED_PROJECTS=""
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
# Check each project for changes and update versions
for proj in $(find . -name "*.csproj"); do
PROJECT_NAME=$(basename "$proj")
PROJECT_DIR=$(dirname "$proj")
# Get current version from csproj
CURRENT_VERSION=$(grep -oP '(?<=<Version>).*(?=</Version>)' "$proj" || echo "0.0.0")
# Split version into parts
IFS='.' read -r -a VERSION_PARTS <<< "$CURRENT_VERSION"
MAJOR="${VERSION_PARTS[0]}"
MINOR="${VERSION_PARTS[1]}"
PATCH="${VERSION_PARTS[2]}"
# Check if project has changes since last tag
if [ -z "$LATEST_TAG" ] || ! git diff --quiet $LATEST_TAG HEAD -- "$PROJECT_DIR"; then
# Calculate new version based on release type
case "${{ github.event.inputs.release_type }}" in
"major")
NEW_VERSION="$((MAJOR + 1)).0.0"
;;
"minor")
NEW_VERSION="${MAJOR}.$((MINOR + 1)).0"
;;
"patch")
NEW_VERSION="${MAJOR}.${MINOR}.$((PATCH + 1))"
;;
esac
# Update version in csproj
sed -i "s/<Version>.*<\/Version>/<Version>${NEW_VERSION}<\/Version>/g" "$proj"
CHANGED_PROJECTS="$CHANGED_PROJECTS$PROJECT_NAME -> $NEW_VERSION\n"
SHOULD_RELEASE="true"
fi
done
# Set environment variables for next steps
echo "CHANGED_PROJECTS<<EOF" >> $GITHUB_ENV
echo -e "$CHANGED_PROJECTS" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
echo "SHOULD_RELEASE=$SHOULD_RELEASE" >> $GITHUB_ENV
# Gen release notes
# Generate release notes with commits and changed projects
- name: Generate Release Notes
if: env.SHOULD_RELEASE == 'true'
id: release_notes
run: |
PREVIOUS_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
Expand All @@ -51,47 +94,28 @@ jobs:
echo "RELEASE_NOTES<<EOF" >> $GITHUB_ENV
echo "## What's Changed" >> $GITHUB_ENV
echo "$COMMITS" >> $GITHUB_ENV
echo -e "\n## Updated Projects" >> $GITHUB_ENV
echo "${{ env.CHANGED_PROJECTS }}" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
# Calc new version
- name: Calculate New Version
id: version
run: |
CURRENT_VERSION=${{ steps.gitversion.outputs.semVer }}
IFS='.' read -r -a VERSION_PARTS <<< "$CURRENT_VERSION"
MAJOR="${VERSION_PARTS[0]}"
MINOR="${VERSION_PARTS[1]}"
PATCH="${VERSION_PARTS[2]}"
case "${{ github.event.inputs.release_type }}" in
"major")
NEW_VERSION="$((MAJOR + 1)).0.0"
;;
"minor")
NEW_VERSION="${MAJOR}.$((MINOR + 1)).0"
;;
"patch")
NEW_VERSION="${MAJOR}.${MINOR}.$((PATCH + 1))"
;;
esac
echo "NEW_VERSION=${NEW_VERSION}" >> $GITHUB_ENV
# Update csproj
- name: Update Version
run: |
find . -name "*.csproj" -type f -exec sed -i "s/<Version>.*<\/Version>/<Version>${{ env.NEW_VERSION }}<\/Version>/g" {} \;
# Restore project dependencies
- name: Restore dependencies
if: env.SHOULD_RELEASE == 'true'
run: dotnet restore

# Build solution
- name: Build
if: env.SHOULD_RELEASE == 'true'
run: dotnet build --configuration Release --no-restore

# Create NuGet packages
- name: Pack
if: env.SHOULD_RELEASE == 'true'
run: dotnet pack --configuration Release --no-build --output nupkgs

# Create release
# Create GitHub release
- name: Create Release
if: env.SHOULD_RELEASE == 'true'
id: create_release
uses: actions/create-release@v1
env:
Expand All @@ -103,25 +127,28 @@ jobs:
draft: false
prerelease: false

# Move .nupkg into dist
- name: Upload Release Asset
# Upload NuGet packages as release assets
- name: Upload Release Assets
if: env.SHOULD_RELEASE == 'true'
uses: softprops/action-gh-release@v1
with:
files: ./nupkgs/*.nupkg
tag_name: v${{ env.NEW_VERSION }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# Publish
# Publish packages to NuGet.org
- name: Push to NuGet
if: env.SHOULD_RELEASE == 'true'
run: dotnet nuget push "./nupkgs/*.nupkg" --source "https://api.nuget.org/v3/index.json" --api-key ${{secrets.NUGET_API_KEY}} --skip-duplicate

# Commit
- name: Commit version update
# Commit version updates and create tag
- name: Commit version updates
if: env.SHOULD_RELEASE == 'true'
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add .
git commit -m "Bump version to ${{ env.NEW_VERSION }}"
git commit -m "Update project versions"
git tag -a "v${{ env.NEW_VERSION }}" -m "Release v${{ env.NEW_VERSION }}"
git push --follow-tags
git push --follow-tags
2 changes: 1 addition & 1 deletion FastCloner.Benchmark/BenchArray2d.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace FastCloner.Benchmark;
public class Bench2DArray
{
private int[,] testData;
private const int SIZE = 1000;
private const int SIZE = 100;

[GlobalSetup]
public void Setup()
Expand Down

0 comments on commit 10c32ad

Please sign in to comment.