diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml new file mode 100644 index 0000000..d4ab26a --- /dev/null +++ b/.github/workflows/dotnet.yml @@ -0,0 +1,98 @@ +name: CI/CD for .NET REST API and Angular Frontend + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + build-and-test: + runs-on: ubuntu-latest + + services: + mysql: + image: mysql:5.7 + ports: + - 3306:3306 + options: >- + --health-cmd="mysqladmin ping --silent" + --health-interval=10s + --health-timeout=5s + --health-retries=3 + env: + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: testdb + + strategy: + matrix: + dotnet-version: ['6.x'] + node-version: ['16.x'] + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + # Set up .NET + - name: Setup .NET + uses: actions/setup-dotnet@v2 + with: + dotnet-version: ${{ matrix.dotnet-version }} + + - name: Restore .NET dependencies + run: dotnet restore ./Server/MotoDev # Specify the folder for the .NET app here + + - name: Build .NET project + run: dotnet build ./Server/MotoDev --no-restore --configuration Release # Specify the folder for the .NET app here + + - name: Run .NET tests + run: dotnet test ./Server/MotoDev --no-build --verbosity normal # Specify the folder for the .NET app here + + # Set up Node.js + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + + - name: Install Angular dependencies + run: npm install + working-directory: ./Client/MotoDev # Specify the folder for the Angular app here + + - name: Run Angular tests + run: npm test -- --watch=false --browsers=ChromeHeadless + working-directory: ./Client/MotoDev # Specify the folder for the Angular app here + + - name: Build Angular project + run: npm run build -- --prod + working-directory: ./Client/MotoDev # Specify the folder for the Angular app here + + deploy: + runs-on: ubuntu-latest + needs: build-and-test + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup .NET + uses: actions/setup-dotnet@v2 + with: + dotnet-version: '6.x' + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: '16.x' + + - name: Install dependencies and build Angular project + run: | + npm install + npm run build -- --prod + working-directory: ./Client/MotoDev # Specify the folder for the Angular app here + + - name: Publish .NET API + run: | + dotnet publish ./Server/MotoDev -c Release -o publish # Specify the folder for the .NET app here + # Add your deployment script here (e.g., copy files to a server or upload to a cloud service)