hotfix api response for auctionware #214
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
# This workflow will build a .NET project | |
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net | |
name: .NET Ci with tests | |
on: | |
push: | |
branches: ["main", "dev"] | |
pull_request: | |
branches: ["main", "dev"] | |
jobs: | |
build-and-test: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v4 | |
- name: Set up Docker | |
uses: docker/setup-buildx-action@v3 | |
- name: Install Docker Compose | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y docker-compose | |
- name: Create .env file | |
run: | | |
echo VITE_API_URL=${{ secrets.VITE_API_URL }} >> .env | |
echo CONNECTION_STRING=${{ secrets.CONNECTION_STRING }} >> .env | |
echo POSTGRES_DB=${{ secrets.POSTGRES_DB }} >> .env | |
echo POSTGRES_USER=${{ secrets.POSTGRES_USER }} >> .env | |
echo POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }} >> .env | |
- name: Start services | |
run: | | |
export $(grep -v '^#' .env | xargs) | |
docker-compose --env-file .env -f docker-compose.yml up --build -d | |
- name: Cache Docker layers | |
uses: actions/cache@v4 | |
with: | |
path: /tmp/.docker | |
key: ${{ runner.os }}-docker-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-docker- | |
- name: Cache .NET packages | |
uses: actions/cache@v4 | |
with: | |
path: ~/.nuget/packages | |
key: nuget-${{ runner.os }}-${{ hashFiles('**/*.csproj') }} | |
restore-keys: | | |
nuget-${{ runner.os }}- | |
- name: Install .NET Core SDK | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: "8.0.x" | |
- name: Restore NuGet packages | |
run: dotnet restore | |
- name: Build | |
run: dotnet build -c Release --no-restore | |
- name: Test backend | |
run: dotnet test -c Release --no-build | |
- name: Test frontend | |
run: | | |
cd Frontend | |
npm install | |
npm test | |
deploy: | |
runs-on: ubuntu-latest | |
needs: build-and-test | |
if: github.ref == 'refs/heads/main' | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v4 | |
- name: Set up Docker | |
uses: docker/setup-buildx-action@v3 | |
- name: Install Docker Compose | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y docker-compose | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.HUB_USER }} | |
password: ${{ secrets.HUB_PASSWORD }} | |
- name: Build and Tag Docker Images | |
run: | | |
echo VITE_API_URL=${{ secrets.VITE_API_URL }} >> .env | |
echo CONNECTION_STRING=${{ secrets.CONNECTION_STRING }} >> .env | |
echo POSTGRES_DB=${{ secrets.POSTGRES_DB }} >> .env | |
echo POSTGRES_USER=${{ secrets.POSTGRES_USER }} >> .env | |
echo POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }} >> .env | |
export $(grep -v '^#' .env | xargs) | |
docker-compose --env-file .env -f docker-compose.yml up --build -d | |
docker tag devops-fullstack_backend:latest ${{ secrets.HUB_USER }}/backend:latest | |
docker tag devops-fullstack_frontend:latest ${{ secrets.HUB_USER }}/frontend:latest | |
- name: Push Docker Images | |
run: | | |
docker push ${{ secrets.HUB_USER }}/backend:latest | |
docker push ${{ secrets.HUB_USER }}/frontend:latest | |
docker-compose -f docker-compose.yml push | |
- name: Set up SSH | |
uses: webfactory/ssh-agent@v0.5.1 | |
with: | |
ssh-private-key: ${{ secrets.DEPLOY_KEY }} | |
- name: Deploy to Server | |
run: | | |
ssh -o StrictHostKeyChecking=no ${{secrets.SERVER_USER}}@${{ secrets.SERVER_HOST }} << 'EOF' | |
cd /home/azureuser/DevOps-fullstack | |
export $(grep -v '^#' .env.prod | xargs) | |
docker-compose --env-file .env.prod -f docker-compose.prod.yml up -d | |
EOF | |
create-issue-on-failure: | |
runs-on: ubuntu-latest | |
needs: build-and-test | |
if: failure() | |
steps: | |
- name: Create issue | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const labels = context.job === 'build-and-test' ? ['backend'] : ['frontend']; | |
const issueTitle = `Workflow failed: ${context.workflow}`; | |
const issueBody = `The workflow **${context.workflow}** failed for job **${context.job}**. Please check the logs for more details.`; | |
const { data: issue } = await github.issues.create({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
title: issueTitle, | |
body: issueBody, | |
labels: labels, | |
}); | |
console.log(`Created issue ${issue.number}: ${issue.title}`); |