Create new release #24
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 --configuration Release --no-build --output ./publish | |
# Run EF migrations | |
- name: Run EF migrations | |
run: dotnet ef migrations script --project src/Migrators/Migrators.MSSQL/Migrators.MSSQL.csproj --startup-project src/Server.UI/Server.UI.csproj --no-build --configuration Release --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 . | |
# Generate tag and release names based on date | |
- name: Set Release Version | |
id: set_release_version | |
run: | | |
TAG_NAME="v$(date +'%Y%m%d%H%M%S')" | |
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 based on date and time.' | |
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 |