Thanks to visit codestin.com
Credit goes to github.com

Skip to content

refinements

refinements #119

Workflow file for this run

name: Build
on:
push:
branches: [main, develop]
tags: ["v*"]
pull_request:
branches: [main]
env:
DOTNET_VERSION: "8.0.x"
BUILD_CONFIG: "Release"
SOLUTION: "src/Koalas.slnx"
PROJECT: "src/Koalas/Koalas.csproj"
ARTIFACTS_DIR: "./artifacts"
PREVIEW_VERSION: "2.0.0"
jobs:
version:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
suffix: ${{ steps.version.outputs.suffix }}
is_release: ${{ steps.version.outputs.is_release }}
steps:
- name: Extract version from tag or branch
id: version
run: |
if [[ "${{ github.ref }}" == refs/tags/v* ]]; then
# Extract version from tag (e.g., v1.1.0 -> 1.1.0)
VERSION="${{ github.ref_name }}"
VERSION="${VERSION#v}"
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "suffix=" >> $GITHUB_OUTPUT
echo "is_release=true" >> $GITHUB_OUTPUT
elif [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
# Main branch gets a preview version
VERSION="${{ env.PREVIEW_VERSION }}"
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "suffix=-preview-${{ github.run_number }}" >> $GITHUB_OUTPUT
echo "is_release=false" >> $GITHUB_OUTPUT
elif [[ "${{ github.ref }}" == "refs/heads/develop" ]]; then
# Develop branch gets a dev version
VERSION="${{ env.PREVIEW_VERSION }}"
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "suffix=-dev-${{ github.run_number }}" >> $GITHUB_OUTPUT
echo "is_release=false" >> $GITHUB_OUTPUT
else
# Other branches get a branch-specific version
VERSION="${{ env.PREVIEW_VERSION }}"
BRANCH_NAME="${{ github.ref_name }}"
SAFE_BRANCH_NAME=$(echo "$BRANCH_NAME" | sed 's/[^a-zA-Z0-9]/-/g')
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "suffix=-$SAFE_BRANCH_NAME-${{ github.run_number }}" >> $GITHUB_OUTPUT
echo "is_release=false" >> $GITHUB_OUTPUT
fi
echo "Full version will be: ${VERSION}${suffix}"
build:
runs-on: ubuntu-latest
needs: version
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Restore dependencies
run: dotnet restore ${{ env.SOLUTION }}
- name: Build solution
run: |
dotnet build ${{ env.SOLUTION }} \
--configuration ${{ env.BUILD_CONFIG }} \
--no-restore \
-p:Version=${{ needs.version.outputs.version }}${{ needs.version.outputs.suffix }} \
-p:AssemblyVersion=${{ needs.version.outputs.version }} \
-p:FileVersion=${{ needs.version.outputs.version }} \
-p:PackageVersion=${{ needs.version.outputs.version }}${{ needs.version.outputs.suffix }}
- name: Run tests
run: |
dotnet test ${{ env.SOLUTION }} \
--configuration ${{ env.BUILD_CONFIG }} \
--no-build \
--verbosity normal
nuget:
runs-on: ubuntu-latest
needs: [version, build]
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Restore dependencies
run: dotnet restore ${{ env.SOLUTION }}
- name: Build solution
run: |
dotnet build ${{ env.SOLUTION }} \
--configuration ${{ env.BUILD_CONFIG }} \
--no-restore \
-p:Version=${{ needs.version.outputs.version }}${{ needs.version.outputs.suffix }} \
-p:AssemblyVersion=${{ needs.version.outputs.version }} \
-p:FileVersion=${{ needs.version.outputs.version }} \
-p:PackageVersion=${{ needs.version.outputs.version }}${{ needs.version.outputs.suffix }}
- name: Create NuGet package
run: |
dotnet pack ${{ env.PROJECT }} \
--configuration ${{ env.BUILD_CONFIG }} \
--no-build \
--output ${{ env.ARTIFACTS_DIR }} \
-p:Version=${{ needs.version.outputs.version }}${{ needs.version.outputs.suffix }}
- name: Publish to NuGet
if: needs.version.outputs.is_release == 'true'
run: |
dotnet nuget push ${{ env.ARTIFACTS_DIR }}/*.nupkg \
--source https://api.nuget.org/v3/index.json \
--api-key ${{ secrets.NUGET_API_KEY }} \
--skip-duplicate
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: nuget-packages
path: ${{ env.ARTIFACTS_DIR }}/*.nupkg