Skip to content

Update hw25-ci-cd.yml #16

Update hw25-ci-cd.yml

Update hw25-ci-cd.yml #16

Workflow file for this run

name: workflow.yml
on:
push:
branches:
- 'hw25-ci-cd/**'
jobs:
version:
name: Version
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v1.1.1
with:
versionSpec: '5.x'
- name: Determine Version
id: version
uses: gittools/actions/gitversion/execute@v1.1.1
unit-tests:
name: Unit Tests
if: false # Remove this line to enable the job
needs:
- version
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.x'
- name: Restore Dependencies
working-directory: './hw25-ci-cd/src'
run: dotnet restore
- name: Run Unit Tests
working-directory: './hw25-ci-cd/src'
run: dotnet test --filter FullyQualifiedName\!~IntegrationTests
integration-tests:
name: Integration Tests
if: false # Remove this line to enable the job
needs:
- version
- unit-tests
runs-on: ubuntu-latest
services:
mongo:
image: mongo:7.0.11
ports:
- 27017:27017
options: >-
--health-cmd "echo 'db.runCommand("ping").ok' | mongosh --quiet"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.x'
- name: Restore Dependencies
working-directory: './hw25-ci-cd/src'
run: dotnet restore
- name: Run Integration Tests
working-directory: './hw25-ci-cd/src'
run: dotnet test --filter FullyQualifiedName\!~UnitTests
build-and-push-docker-image:
name: Build and Push Docker Image
needs:
- version
# - unit-tests
# - integration-tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build Docker Image
env:
Version: ${{ steps.version.outputs.fullSemVer }}
working-directory: './hw25-ci-cd/src/webapi'
run: docker build -t hw25-webapi:${{ env.Version }} .
- name: Tag Docker Image
env:
Version: ${{ steps.version.outputs.fullSemVer }}
run: docker tag hw25-webapi:${{ env.Version }} ${{ secrets.DOCKERHUB_USERNAME }}/hw25-webapi:${{ env.Version }}
- name: Push Docker Image
env:
Version: ${{ steps.version.outputs.fullSemVer }}
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/hw25-webapi:${{ env.Version }}