Create new release #20
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Create new release | |
on: | |
workflow_dispatch: | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
# Checkout the repository | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
# Check if the branch is main | |
- name: Check branch | |
run: | | |
if [ "${{ github.ref }}" != "refs/heads/main" ]; then | |
echo "This workflow can only be triggered from the main branch." | |
exit 1 | |
fi | |
# Set up .NET environment | |
- name: Set up .NET | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: '8.0.x' # specify the version of .NET you need | |
# Restore dependencies | |
- name: Restore dependencies | |
run: dotnet restore | |
# Restore dotnet tools | |
- name: Restore dotnet tools | |
run: dotnet tool restore | |
# Build the project | |
- name: Build | |
run: dotnet build --configuration Release --no-restore | |
# Run unit tests | |
- name: Test | |
run: dotnet test --configuration Release --no-build --verbosity normal | |
# Publish the build artifacts | |
- name: Publish | |
run: dotnet publish --no-build --configuration Release --output ./publish | |
# Run EF migrations | |
- name: Run EF migrations | |
run: dotnet ef migrations script --no-build --configuration Release --project src/Migrators/Migrators.MSSQL/Migrators.MSSQL.csproj --startup-project src/Server.UI/Server.UI.csproj --context Cfo.Cats.Infrastructure.Persistence.ApplicationDbContext --idempotent -o ./publish/Migration.sql | |
# Compress the build artifacts into a ZIP file | |
- name: Compress build artifacts | |
run: | | |
cd publish | |
zip -r ../build-artifacts.zip . | |
# Read and increment version number | |
- name: Increment Version | |
id: increment_version | |
run: | | |
# Read the current version from the GitHub secret | |
CURRENT_VERSION=${{ secrets.INITIAL_VERSION }} | |
# Split the version into major, minor, and patch | |
IFS='.' read -r -a VERSION_PARTS <<< "$CURRENT_VERSION" | |
MAJOR=${VERSION_PARTS[0]} | |
MINOR=${VERSION_PARTS[1]} | |
PATCH=${VERSION_PARTS[2]} | |
# Increment the patch version | |
PATCH=$((PATCH + 1)) | |
# Form the new version | |
NEW_VERSION="$MAJOR.$MINOR.$PATCH" | |
# Set the new version as an environment variable | |
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV | |
# Generate tag and release names based on the new version | |
- name: Set Release Version | |
id: set_release_version | |
run: | | |
TAG_NAME="v${{ env.NEW_VERSION }}" | |
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV | |
echo "RELEASE_NAME=Release $TAG_NAME" >> $GITHUB_ENV | |
# Create a new release | |
- name: Create Release | |
id: create_release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ env.TAG_NAME }} | |
release_name: ${{ env.RELEASE_NAME }} | |
body: 'Automatic release with incremented version number.' | |
draft: false | |
prerelease: false | |
# Upload build artifacts to the release | |
- name: Upload Release Asset | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./build-artifacts.zip | |
asset_name: build-artifacts.zip | |
asset_content_type: application/zip |