Last active
October 6, 2021 12:19
-
-
Save aliasadidev/cfb283613456e4430a2d96a9caecf38e to your computer and use it in GitHub Desktop.
Revisions
-
aliasadidev revised this gist
Oct 6, 2021 . No changes.There are no files selected for viewing
-
aliasadidev revised this gist
Oct 6, 2021 . 1 changed file with 14 additions and 14 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -56,16 +56,16 @@ if($isUpdate -eq $false) { } # go to the project directory cd $ProjectPath # run dotnet restore dotnet restore --disable-parallel write-host "restore finished" -ForegroundColor green # publish api project to publish directory dotnet publish -c Release -o ./publish write-host "publish finished" -ForegroundColor green # check app pool is running @@ -77,19 +77,19 @@ if($isUpdate -eq $false) { write-host "sevice is stopped" -ForegroundColor green # make a delay Start-Sleep -s 7 } #start syncing files write-host "start syncing files" -ForegroundColor green (robocopy $ProjectPublishPath $WORKER_SERIVCE_PATH /s /mir /purge); if ($lastexitcode -eq 0) { write-host 'Robocopy succeeded' } else { write-host $lastexitcode } # check app pool is running # if service is stoped, then run it @@ -104,7 +104,7 @@ if($isUpdate -eq $false) { # update last-commit.txt file Set-Content .\last-commit.txt $currentLastCommitHash write-host "publish finished" -ForegroundColor green } -
aliasadidev revised this gist
Oct 6, 2021 . No changes.There are no files selected for viewing
-
aliasadidev revised this gist
Oct 6, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -16,7 +16,7 @@ $ProjectPath = '.\ShopApi\' # project publish directory path $ProjectPublishPath = Join-Path -Path '.\' -ChildPath "publish" # go to the project directory cd $ProjectPath # checkout branch to dev # -
aliasadidev revised this gist
Oct 6, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ # simple ci with powershell # log everything in git-log-file-{datetime}.log $logFile = ".\git-log-file-$([System.Datetime]::Now.ToString("yyyy-MM-dd-HH-mm-ss")).log" Start-Transcript -Path $logFile -
aliasadidev revised this gist
Oct 6, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ # simple ci with powershell # log everything in git-log-file-{datetime} $logFile = ".\git-log-file-$([System.Datetime]::Now.ToString("yyyy-MM-dd-HH-mm-ss")).log" -
aliasadidev revised this gist
Oct 6, 2021 . 1 changed file with 0 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,3 @@ # log everything in git-log-file-{datetime} $logFile = ".\git-log-file-$([System.Datetime]::Now.ToString("yyyy-MM-dd-HH-mm-ss")).log" @@ -110,5 +109,3 @@ if($isUpdate -eq $false) { } Stop-Transcript -
aliasadidev created this gist
Oct 6, 2021 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,114 @@ ```powershell # log everything in git-log-file-{datetime} $logFile = ".\git-log-file-$([System.Datetime]::Now.ToString("yyyy-MM-dd-HH-mm-ss")).log" Start-Transcript -Path $logFile # app pool name $WORKER_SERVICE_NAME = '{App_Pool_Name}' # app directory path $WORKER_SERIVCE_PATH = 'D:\wwwroot\{App_Pool_Name}' # project root directory path $ProjectPath = '.\ShopApi\' # project publish directory path $ProjectPublishPath = Join-Path -Path '.\' -ChildPath "publish" # go to project directory cd $ProjectPath # checkout branch to dev # write-host "checkout branch to dev" -ForegroundColor Cyan (git checkout dev -f) # removes staged and working directory changes in the server (git reset --hard) # pull dev branch # write-host "pull dev branch" -ForegroundColor Cyan (git pull) # get latest commit hash code $currentLastCommitHash = (git log dev -1 --pretty=format:"%H") write-host "latest hash code:$currentLastCommitHash" -ForegroundColor Cyan # move to ci root directory cd .. # read latest commit hash code from last-commit.txt file $lastCommitHash = Get-Content .\last-commit.txt # compare the current commit hash with previous the commit hash $isUpdate = $currentLastCommitHash -eq $lastCommitHash # dev branch is updated? write-host "is updated: $isUpdate" -ForegroundColor Cyan; # publish new version if($isUpdate -eq $false) { # remove the publish directory in the project if(Test-Path $ProjectPublishPath){ Remove-Item -path $ProjectPublishPath -r -ErrorAction SilentlyContinue } # go to the project directory cd $ProjectPath # run dotnet restore dotnet restore --disable-parallel write-host "restore finished" -ForegroundColor green # publish api project to publish directory dotnet publish -c Release -o ./publish write-host "publish finished" -ForegroundColor green # check app pool is running # if service is running, then stop it if((Get-WebAppPoolState -Name $WORKER_SERVICE_NAME).Value -ne 'Stopped'){ write-host "sevice is running" -ForegroundColor green # stop the app pool Stop-WebAppPool -Name $WORKER_SERVICE_NAME write-host "sevice is stopped" -ForegroundColor green # make a delay Start-Sleep -s 7 } #start syncing files write-host "start syncing files" -ForegroundColor green (robocopy $ProjectPublishPath $WORKER_SERIVCE_PATH /s /mir /purge); if ($lastexitcode -eq 0) { write-host 'Robocopy succeeded' } else { write-host $lastexitcode } # check app pool is running # if service is stoped, then run it if((Get-WebAppPoolState -Name $WORKER_SERVICE_NAME).Value -ne 'Started'){ Start-WebAppPool -Name $WORKER_SERVICE_NAME write-host "service is started" -ForegroundColor green } # back to root directory cd .. # update last-commit.txt file Set-Content .\last-commit.txt $currentLastCommitHash write-host "publish finished" -ForegroundColor green } Stop-Transcript ```