trigger GitHub actions #5
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: .NET CI/CD | |
on: | |
push: | |
branches: [ master ] | |
jobs: | |
build_test: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
with: | |
ref: master | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: '7.0.x' | |
- name: Restore Dependencies | |
run: dotnet restore | |
- name: Build | |
run: dotnet build -c Release --no-restore | |
- name: Test | |
run: dotnet test ./APITests/APITests.csproj -c Release --verbosity normal -e ConnectionStrings__DefaultConnection="${{ secrets.DEV_TEST_CONNECTION_STRING }}" | |
publish: | |
needs: build_test | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
with: | |
ref: master | |
- name: Login to DockerHub | |
uses: docker/login-action@v3 | |
with: | |
username: stagecodes | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Build and Push Docker Image | |
run: | | |
docker build -t stagecodes/otr-api-prod . | |
docker push stagecodes/otr-api-prod | |
deploy: | |
needs: publish | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
with: | |
ref: master | |
- name: Create .env files | |
run: | | |
echo "${{ secrets.PROD_APP_ENV }}" > app.env | |
echo "${{ secrets.PROD_DB_ENV }}" > db.env | |
- name: Copy files to server | |
uses: appleboy/scp-action@master | |
with: | |
host: ${{ secrets.PROD_SSH_HOST }} | |
username: ${{ secrets.PROD_SSH_USER }} | |
key: ${{ secrets.PROD_SSH_KEY }} | |
source: "app.env,db.env,docker-compose-prod.yml" | |
target: "~/otr-api/" | |
- name: Deploy | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.PROD_SSH_HOST }} | |
username: ${{ secrets.PROD_SSH_USER }} | |
key: ${{ secrets.PROD_SSH_KEY }} | |
script: | | |
cd ~/otr-api | |
docker compose pull | |
docker compose -f docker-compose-prod.yml up -d --build |