Skip to content

Refactored Live Events #140

Refactored Live Events

Refactored Live Events #140

name: Build and deploy .NET
on:
push:
branches: [ master ]
jobs:
build-and-push-job-db-cleanup:
runs-on: self-hosted
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Check for changes in Sharecode.Backend.Worker.DbCleanup
id: check_changes
run: |
changes=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} -- Sharecode.Backend.Worker.DbCleanup)
if [ -z "$changes" ]; then
echo "No changes in Sharecode.Backend.Worker.DbCleanup. Skipping the job."
echo "::set-output name=skip-job::true"
fi
- name: Set up .NET 8
uses: actions/setup-dotnet@v1
with:
dotnet-version: '8.0'
- name: Restore Dependencies for Job
run: dotnet restore Sharecode.Backend.Worker.DbCleanup/Sharecode.Backend.Worker.DbCleanup.csproj
if: steps.check_changes.outputs.skip-job != 'true'
- name: Build Job with dotnet
run: dotnet build Sharecode.Backend.Worker.DbCleanup/Sharecode.Backend.Worker.DbCleanup.csproj --configuration Release --no-restore
if: steps.check_changes.outputs.skip-job != 'true'
- name: Publish Job
run: dotnet publish Sharecode.Backend.Worker.DbCleanup/Sharecode.Backend.Worker.DbCleanup.csproj -c Release -o out/Sharecode.Backend.Worker.DbCleanup
if: steps.check_changes.outputs.skip-job != 'true'
- name: Build Job Docker Image
run: |
docker build -t alenalex/sharecode-worker-dbcleanup:master -f Sharecode.Backend.Worker.DbCleanup/Dockerfile .
if: steps.check_changes.outputs.skip-job != 'true'
- name: Docker Login
run: echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
if: github.ref == 'refs/heads/master' && steps.check_changes.outputs.skip-job != 'true'
- name: Push Docker Image
run: |
docker push alenalex/sharecode-worker-dbcleanup:master
if: github.ref == 'refs/heads/master' && steps.check_changes.outputs.skip-job != 'true'
build-and-push-job-outbox-worker:
runs-on: self-hosted
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Set up .NET 8
uses: actions/setup-dotnet@v1
with:
dotnet-version: '8.0'
- name: Inject the latest email-templates
run: |
git clone --single-branch --branch main https://github.com/Share-Code-Development/Email-templates.git email-templates
cp -r email-templates Sharecode.Backend.Worker.Outbox/email-templates
- name: Restore Dependencies for Job
run: dotnet restore Sharecode.Backend.Worker.Outbox/Sharecode.Backend.Worker.Outbox.csproj
- name: Build Job with dotnet
run: dotnet build Sharecode.Backend.Worker.Outbox/Sharecode.Backend.Worker.Outbox.csproj --configuration Release --no-restore
- name: Publish Job
run: dotnet publish Sharecode.Backend.Worker.Outbox/Sharecode.Backend.Worker.Outbox.csproj -c Release -o out/Sharecode.Backend.Worker.Outbox
- name: Build Job Docker Image
run: |
docker build -t alenalex/sharecode-worker-outbox:master -f Sharecode.Backend.Worker.Outbox/Dockerfile .
- name: Docker Login
run: echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
if: github.ref == 'refs/heads/master'
- name: Push Docker Image
run: |
docker push alenalex/sharecode-worker-outbox:master
if: github.ref == 'refs/heads/master'
build-and-push-api:
runs-on: self-hosted
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Set up .NET 8
uses: actions/setup-dotnet@v1
with:
dotnet-version: '8.0'
- name: Restore Dependencies for API
run: dotnet restore Sharecode.Backend.Api/Sharecode.Backend.Api.csproj
- name: Build API with dotnet
run: dotnet build Sharecode.Backend.Api/Sharecode.Backend.Api.csproj --configuration Release --no-restore
- name: Run Code Quality Tests on API
run: dotnet test Sharecode.Backend.UnitTest.CodeQuality/Sharecode.Backend.UnitTest.CodeQuality.csproj
- name: Publish
run: dotnet publish Sharecode.Backend.Api/Sharecode.Backend.Api.csproj -c Release -o out/Sharecode.Backend.Api
- name: Build Docker Image
run: |
docker build -t alenalex/sharecode-api:master -f Sharecode.Backend.Api/Dockerfile .
- name: Docker Login
run: echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
if: github.ref == 'refs/heads/master'
- name: Push Docker Image
run: |
docker push alenalex/sharecode-api:master
if: github.ref == 'refs/heads/master'
deploy:
needs: [
build-and-push-job-outbox-worker,
build-and-push-api,
build-and-push-job-db-cleanup
]
runs-on: self-hosted
steps:
- name: Update docker compose from Github
uses: appleboy/scp-action@master
with:
host: ${{ secrets.VM_HOST }}
username: ${{ secrets.VM_USERNAME }}
password: ${{ secrets.VM_PASSWORD }}
source: "docker-compose.yml"
target: "/home/share-code-develop/"
- name: Deploy to VM
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.VM_HOST }}
username: ${{ secrets.VM_USERNAME }}
password: ${{ secrets.VM_PASSWORD }}
script: |
cd /home/share-code-develop
docker compose pull
docker compose up -d
- name: Clear the existing cache of the application
run: |
sudo apt-get update
sudo apt-get install redis-tools -y
redis-cli -u ${{ secrets.REDIS_CLI_SECRET }} FLUSHALL