Merge branch 'master' into production #44
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: dotnet test | |
on: | |
push: | |
branches: [production, test, dev] | |
env: | |
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true | |
DOTNET_CLI_TELEMETRY_OPTOUT: true | |
DOTNET_NOLOGO: true | |
jobs: | |
build: | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
os: [ubuntu-20.04] | |
dotnet-version: ['8.0.x'] | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Setup .NET SDK | |
uses: actions/setup-dotnet@v2 | |
with: | |
dotnet-version: ${{ matrix.dotnet-version }} | |
- name: Install dependencies | |
run: dotnet restore | |
- name: Build | |
run: dotnet build --configuration Release --no-restore | |
- name: Extract branch name | |
shell: bash | |
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})" | |
id: extract_branch | |
- name: Extract short SHA | |
shell: bash | |
run: echo "##[set-output name=short_sha;]$(echo ${GITHUB_SHA} | cut -c1-8)" | |
id: extract_short_sha | |
- name: Test | |
run: dotnet test --configuration Release --filter 'FullyQualifiedName!~Fakemail.IntegrationTests' --no-restore --verbosity normal --logger trx --results-directory "TestResults-${{ matrix.dotnet-version }}" | |
#- name: Upload test results | |
# uses: actions/upload-artifact@v3 | |
# with: | |
# name: test-results-${{ matrix.dotnet-version }} | |
# path: TestResults-${{ matrix.dotnet-version }} | |
# if: ${{ always() }} | |
- name: Dotnet publish | |
run: | | |
rm -rf Fakemail.Web/bin/Release/8.0/publish | |
rm -rf Fakemail.Api/bin/Release/net8.0/publish | |
rm -rf Fakemail.Services/bin/Release/net8.0/publish | |
dotnet publish -p:PublishProfile=FolderProfile --configuration Release -p:DebugType=None -p:DebugSymbols=false Fakemail.Web | |
dotnet publish -p:PublishProfile=FolderProfile --configuration Release -p:DebugType=None -p:DebugSymbols=false Fakemail.Api | |
dotnet publish -p:PublishProfile=FolderProfile --configuration Release -p:DebugType=None -p:DebugSymbols=false Fakemail.Services | |
- name: Create deployment artifact | |
run: | | |
rm -rf fakemail-deployment | |
mkdir -p fakemail-deployment/common/runtimes | |
mkdir fakemail-deployment/api | |
mkdir fakemail-deployment/web | |
mkdir fakemail-deployment/services | |
# delete the runtimes that are not used | |
mv Fakemail.Web/bin/Release/net8.0/publish/runtimes/linux-x64 fakemail-deployment/common/runtimes | |
mv Fakemail.Web/bin/Release/net8.0/publish/runtimes/linux-arm64 fakemail-deployment/common/runtimes | |
rm -rf Fakemail.Web/bin/Release/net8.0/publish/runtimes | |
rm -rf Fakemail.Api/bin/Release/net8.0/publish/runtimes | |
rm -rf Fakemail.Services/bin/Release/net8.0/publish/runtimes | |
# web specific files | |
mv Fakemail.Web/bin/Release/net8.0/publish/*.json fakemail-deployment/web | |
mv Fakemail.Web/bin/Release/net8.0/publish/*.config fakemail-deployment/web | |
mv Fakemail.Web/bin/Release/net8.0/publish/Fakemail.Web.* fakemail-deployment/web | |
mv Fakemail.Web/bin/Release/net8.0/publish/wwwroot fakemail-deployment/web | |
# api specific files | |
mv Fakemail.Api/bin/Release/net8.0/publish/*.json fakemail-deployment/api | |
mv Fakemail.Api/bin/Release/net8.0/publish/*.config fakemail-deployment/api | |
mv Fakemail.Api/bin/Release/net8.0/publish/Fakemail.Api.* fakemail-deployment/api | |
# services specific files | |
mv Fakemail.Services/bin/Release/net8.0/publish/*.json fakemail-deployment/services | |
mv Fakemail.Services/bin/Release/net8.0/publish/Fakemail.Services.* fakemail-deployment/services | |
# everything else is common | |
mv Fakemail.Web/bin/Release/net8.0/publish/* fakemail-deployment/common | |
mv Fakemail.Api/bin/Release/net8.0/publish/* fakemail-deployment/common | |
mv Fakemail.Services/bin/Release/net8.0/publish/* fakemail-deployment/common | |
mv fakemail-deployment fakemail-deployment.${{ steps.extract_branch.outputs.branch }}.${{ steps.extract_short_sha.outputs.short_sha }} | |
tar -zcvf fakemail-deployment.${{ steps.extract_branch.outputs.branch }}.${{ steps.extract_short_sha.outputs.short_sha }}.tgz fakemail-deployment.${{ steps.extract_branch.outputs.branch }}.${{ steps.extract_short_sha.outputs.short_sha }} | |
# Upload deployment artifact, but without secrets | |
# TODO: only upload production deployments | |
#- name: Upload deployment artifact | |
# uses: actions/upload-artifact@v3 | |
# with: | |
# name: fakemail-deployment.${{ steps.extract_branch.outputs.branch }}.${{ steps.extract_short_sha.outputs.short_sha }} | |
# path: fakemail-deployment.${{ steps.extract_branch.outputs.branch }}.${{ steps.extract_short_sha.outputs.short_sha }}.tgz | |
# Now recreate artifact with secrets | |
- uses: microsoft/variable-substitution@v1 | |
with: | |
files: '**/appsettings.json' | |
env: | |
Jwt.Secret: ${{ secrets.FAKEMAIL_API_JWT_SECRET }} | |
- name: Create deployment artifact with secrets | |
run: | | |
rm -rf fakemail-deployment.${{ steps.extract_branch.outputs.branch }}.${{ steps.extract_short_sha.outputs.short_sha }}.tgz | |
tar -zcvf fakemail-deployment.${{ steps.extract_branch.outputs.branch }}.${{ steps.extract_short_sha.outputs.short_sha }}.tgz fakemail-deployment.${{ steps.extract_branch.outputs.branch }}.${{ steps.extract_short_sha.outputs.short_sha }} | |
- name: Set deploy host | |
run: | | |
if [[ $GITHUB_REF == 'refs/heads/dev' ]]; then | |
echo "DEPLOY_HOST=fakemail.stream" >> "$GITHUB_ENV" | |
elif [[ $GITHUB_REF == 'refs/heads/test' ]]; then | |
echo "DEPLOY_HOST=test.fakemail.stream" >> "$GITHUB_ENV" | |
elif [[ $GITHUB_REF == 'refs/heads/production' ]]; then | |
echo "DEPLOY_HOST=fakemail.stream" >> "$GITHUB_ENV" | |
else | |
echo DEPLOY_HOST='' >> "$GITHUB_ENV" | |
fi | |
- name: copy file via ssh | |
uses: appleboy/scp-action@master | |
with: | |
host: ${{ env.DEPLOY_HOST }} | |
username: ${{ secrets.FAKEMAIL_DEPLOY_USER }} | |
key: ${{ secrets.FAKEMAIL_DEPLOY_SSH_KEY }} | |
source: "fakemail-deployment.${{ steps.extract_branch.outputs.branch }}.${{ steps.extract_short_sha.outputs.short_sha }}.tgz" | |
target: "${{ secrets.FAKEMAIL_DEPLOY_PATH }}" | |
- name: run deploy command | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ env.DEPLOY_HOST }} | |
username: ${{ secrets.FAKEMAIL_DEPLOY_USER }} | |
key: ${{ secrets.FAKEMAIL_DEPLOY_SSH_KEY }} | |
script: /home/fakemail/deploy.sh fakemail-deployment.${{ steps.extract_branch.outputs.branch }}.${{ steps.extract_short_sha.outputs.short_sha }} |