Adding namespaces #337
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: Build CI | |
on: | |
push: | |
branches: | |
- main | |
- 'feature/**' | |
- 'bugfix/**' | |
workflow_dispatch: | |
env: | |
OCTOPUS_PROJECT_NAME: Trident | |
OCTOPUS_FEATURE_BRANCH_CHANNEL: Default | |
OCTOPUS_RELEASE_CHANNEL: Release | |
OCTOPUS_SPACE: Default | |
OCTOPUS_API_KEY: ${{ secrets.OCTOPUSSERVERAPIKEY }} | |
OCTOPUS_URL: ${{ secrets.OCTOPUSSERVERURL }} | |
jobs: | |
build-and-push-application: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
dotnet-version: ['7.0.x'] | |
steps: | |
- uses: actions/checkout@v3 | |
- id: ReleaseNum | |
name: Set Release Number | |
run: | | |
$locationOfProject = "src/Trident.Web/Trident.Web.csproj" | |
$projectContents = Get-Content $locationOfProject | |
$projectAsXML = [xml]$projectContents | |
$versionPrefix = $projectAsXML.Project.PropertyGroup.VersionPrefix | |
Write-Host "The version prefix is $versionPrefix" | |
$branchName = (((${env:GITHUB_REF} -replace "refs/heads/", "") -replace "feature/", "") -replace "bugfix/", "") -replace " ", "" | |
Write-Host "The Branch Name is: $branchName" | |
$channelName = "${env:OCTOPUS_RELEASE_CHANNEL}" | |
Write-Host "The channel name is now $channelName" | |
$versionNumber = "$($versionPrefix).${env:GITHUB_RUN_NUMBER}" | |
Write-Host "The version number is now $versionNumber" | |
if ($branchName -ne "main") | |
{ | |
Write-Host "The branch is not the main branch, using the feature branch settings instead." | |
$channelName = "${env:OCTOPUS_FEATURE_BRANCH_CHANNEL}" | |
Write-Host "The channel name is now $channelName" | |
if ($branchName -like "refs/pull*") | |
{ | |
$versionNumber = "$versionNumber-PullRequest" | |
Write-Host "The version number is now $versionNumber" | |
} | |
else | |
{ | |
$versionNumber = "$versionNumber-$branchName" | |
Write-Host "The version number is now $versionNumber" | |
} | |
} | |
Write-Host "Setting the Output Variable OCTOPUS_CHANNEL to $channelName" | |
Write-Output "OCTOPUS_CHANNEL=$channelName" >> $Env:GITHUB_OUTPUT | |
Write-Host "Setting the Output Variable APP_VERSION to $versionNumber" | |
Write-Output "APP_VERSION=$versionNumber" >> $Env:GITHUB_OUTPUT | |
Write-Host "Setting the Output Variable APP_VERSION_PREFIX to $versionNumber" | |
Write-Output "APP_VERSION_PREFIX=$versionPrefix" >> $Env:GITHUB_OUTPUT | |
shell: pwsh | |
- name: Setup .NET SDK | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: ${{ matrix.dotnet-version }} | |
- name: create artifacts folder | |
run: | | |
mkdir "$GITHUB_WORKSPACE/artifacts" | |
mkdir "$GITHUB_WORKSPACE/artifacts/web" | |
- name: restore dependencies for application | |
working-directory: src | |
run: dotnet restore | |
- name: build website | |
working-directory: src/Trident.Web | |
run: dotnet publish --output "$GITHUB_WORKSPACE/artifacts/web" -c Release --runtime win-x64 --sc false --p:Version=${{ steps.ReleaseNum.outputs.APP_VERSION }} | |
- name: package website | |
id: "website_package" | |
uses: OctopusDeploy/create-zip-package-action@v3 | |
with: | |
package_id: Trident.Web | |
version: ${{ steps.ReleaseNum.outputs.APP_VERSION }} | |
base_path: "artifacts/web" | |
files: "**/*" | |
output_folder: packaged | |
- name: package database | |
id: "database_package" | |
uses: OctopusDeploy/create-zip-package-action@v3 | |
with: | |
package_id: Trident.Database | |
version: ${{ steps.ReleaseNum.outputs.APP_VERSION }} | |
base_path: "db" | |
files: "**/*" | |
output_folder: packaged | |
- name: Upload artifacts to GitHub | |
uses: actions/upload-artifact@v3 | |
with: | |
name: assets-for-download | |
path: packaged | |
- name: Login to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PAT }} | |
- name: build and push website container | |
working-directory: src | |
run: | | |
docker build -f "./Trident.Web/Dockerfile" --tag bobjwalker99/trident:${{ steps.ReleaseNum.outputs.APP_VERSION }} --tag bobjwalker99/trident:${{ steps.ReleaseNum.outputs.APP_VERSION_PREFIX }} --tag bobjwalker99/trident:latest . | |
docker push bobjwalker99/trident:${{ steps.ReleaseNum.outputs.APP_VERSION }} | |
docker push bobjwalker99/trident:${{ steps.ReleaseNum.outputs.APP_VERSION_PREFIX }} | |
docker push bobjwalker99/trident:latest | |
- name: push packages to Octopus | |
uses: OctopusDeploy/push-package-action@v3 | |
with: | |
packages: | | |
packaged/**/*.zip | |
- name: push build information to Octopus | |
uses: OctopusDeploy/push-build-information-action@v3 | |
with: | |
packages: | | |
Trident.Database | |
Trident.Web | |
version: ${{ steps.ReleaseNum.outputs.APP_VERSION }} | |
- name: create release | |
uses: OctopusDeploy/create-release-action@v3 | |
with: | |
project: ${{ env.OCTOPUS_PROJECT_NAME }} | |
channel: ${{ steps.ReleaseNum.outputs.OCTOPUS_CHANNEL }} | |
release_number: ${{ steps.ReleaseNum.outputs.APP_VERSION }} | |
package_version: ${{ steps.ReleaseNum.outputs.APP_VERSION }} |