Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create deploy-and-update-on-release.yml #9

Merged
merged 3 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions .github/workflows/deploy-and-update-on-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: Deploy and Update on Release
on:
release:
types:
- published
permissions:
packages: write
contents: write
pull-requests: write

jobs:
deploy_and_update:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: master

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'

- name: Build the project
run: dotnet build

- name: Get Release Info
id: get_release_info
shell: bash
run: |
TAG="${{ github.event.release.tag_name }}"
VERSION=${TAG#v}
VERSION=${VERSION%%-*}
echo "TAG=$TAG" >> $GITHUB_ENV
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "Version extracted: $VERSION"
if [[ "$TAG" == *"-stage"* ]]; then
echo "CONFIGUREDSQLCONNECTION_ACTION_CONNECTION=${{ secrets.PART_OF_CONNECTION }}${{ secrets.STAGE_DB_NAME }}" >> $GITHUB_ENV
else
echo "CONFIGUREDSQLCONNECTION_ACTION_CONNECTION=${{ secrets.PART_OF_CONNECTION }}${{ secrets.PROD_DB_NAME }}" >> $GITHUB_ENV
fi

- name: Update .csproj with version and release notes
if: contains(env.TAG, '-stage')
shell: pwsh
run: |
$version = "${{ env.VERSION }}"
$tag = "${{ env.TAG }}"
$repository = "${{ github.repository }}"
Write-Host "Updating .csproj with version $version and PackageReleaseNotes"
[xml]$csproj = Get-Content -Path ./src/DispenserProvider.DataBase/DispenserProvider.DataBase.csproj
$csproj.Project.PropertyGroup.Version = $version
$releaseNotes = "https://github.com/$repository/releases/tag/v$version-prod"
$csproj.Project.PropertyGroup.PackageReleaseNotes = $releaseNotes
$csproj.Save("$(PWD)/src/DispenserProvider.DataBase/DispenserProvider.DataBase.csproj")

- name: Create Pull Request
if: contains(env.TAG, '-stage')
id: create_pr
uses: peter-evans/create-pull-request@v4
with:
commit-message: Update project version and release notes
title: "Update project version to ${{ env.VERSION }}"
body: "This PR updates the .csproj project version to ${{ env.VERSION }} and updates package release notes."
branch: "update-version-${{ env.VERSION }}"
delete-branch: true
add-paths: ./src/DispenserProvider.DataBase/DispenserProvider.DataBase.csproj

- name: Merge Pull Request
if: contains(env.TAG, '-stage') && steps.create_pr.outputs.pull-request-number
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
pr_number="${{ steps.create_pr.outputs.pull-request-number }}"
echo "pr_number=$pr_number"
curl \
-X PUT \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/${{ github.repository }}/pulls/$pr_number/merge" \
-d '{"merge_method": "squash"}'

- name: Deploy EF Core Migrations
run: |
dotnet tool install --global dotnet-ef --version 8.0.0
dotnet tool restore
dotnet ef database update -c DispenserContext -p ./src/DispenserProvider.Migrations/DispenserProvider.Migrations.csproj -s ./src/DispenserProvider.Migrations/DispenserProvider.Migrations.csproj

- name: Package and Push NuGet Package to GitHub Packages
if: contains(env.TAG, '-prod')
run: |
dotnet pack ./src/DispenserProvider.DataBase/DispenserProvider.DataBase.csproj --configuration Release --output nupkg/
nuget push nupkg/*.nupkg -Source https://nuget.pkg.github.com/The-Poolz/index.json -ApiKey ${{ secrets.GITHUB_TOKEN }}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>1.0.0</Version>
<PackageReleaseNotes>https://github.com/The-Poolz/DispenserProvider.DataBase/releases/tag/v1.0.0-prod</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand Down