Skip to content

Commit

Permalink
feat(ci/deploy): Update deploy workflow
Browse files Browse the repository at this point in the history
- Renamed the workflow from "Deploy Preview to Server" to "Deploy to Server"
- Modified the branch filter for push events to include both "main" and "develop"
- Added a matrix strategy for build-package-api and build-package-web jobs
- Updated the artifact names in build-package-api and build-package-web jobs based on the configuration matrix
- Refactored deploy-preview job into a reusable anchor called deploy-job
- Added a new job called deploy-live that deploys to the live environment after deploying to preview
- Updated the artifact names, paths, and other parameters in deploy-job based on the configuration matrix and secrets
  • Loading branch information
SakuraIsayeki committed Feb 8, 2024
1 parent ee3f0df commit efcdf19
Showing 1 changed file with 39 additions and 36 deletions.
75 changes: 39 additions & 36 deletions .github/workflows/deploy-preview.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
name: Deploy Preview to Server
name: Deploy to Server

on:
push:
branches: [ develop ]
branches:
- main
- develop

permissions:
contents: read
Expand All @@ -24,53 +26,54 @@ jobs:
name: Build & Package API
needs: build-test-solution
uses: Nodsoft/workflows/.github/workflows/package-dotnet.yml@main
strategy: &build-strategy
matrix:
configuration: ['production', 'preview']
with:
dotnet-version: '8.0'
configuration: 'Preview'
configuration: ${{ matrix.configuration }}
project-file: 'WowsKarma.Api/WowsKarma.Api.csproj'
artifact-name: 'wowskarma_api'
artifact-name: 'wowskarma_api_${{ matrix.configuration }}'

build-package-web:
name: Build & Package Web App
needs: build-test-solution
uses: ./.github/workflows/build-package-web.yml
strategy: *build-strategy
with:
build_configuration: 'preview'
build_configuration: ${{ matrix.configuration }}
artifact_name: 'wowskarma_app_${{ matrix.configuration }}'

# Deploy to server
deploy-preview:
name: Deploy Preview to server

deploy-preview: &deploy-job
name: Deploy to Preview
environment:
name: preview
url: https://preview.wows-karma.com/
needs:
- build-package-api
- build-package-web
runs-on: ubuntu-latest
steps:
- name: Download packaged API artifacts
uses: actions/download-artifact@v4
with:
name: wowskarma_api
path: ./api

- name: Download packaged Web App artifacts
uses: actions/download-artifact@v4
with:
name: wowskarma_app
path: ./web

- name: Install SSH Key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.SSH_PRIVATEKEY }}
known_hosts: '*.nodsoft.net'

- name: Add Known Hosts
run: ssh-keyscan -H ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts
- build-package-web
strategy:
matrix:
artifact: [
{ name_pre: 'wowskarma_api', path: './api' },
{ name_pre: 'wowskarma_app', path: './web' }
]
uses: Nodsoft/workflows/.github/workflows/package-dotnet.yml@main
with:
artifact_name: ${{ matrix.artifact.name_pre }}_${{ inputs.configuration }}
artifact_path: ${{ matrix.artifact.path }}
host: ${{ secrets.SSH_HOST }}
user: ${{ secrets.SSH_USER }}
private_key: ${{ secrets.SSH_PRIVATEKEY }}
remote_path: ${{ secrets.SSH_DEPLOYPATH }}
post_deploy_cmd: ${{ secrets.SSH_CMD_RESTART_API }}

- name: Deploy with rsync
run: rsync -rvmzOE . ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:${{ secrets.SSH_DEPLOYPATH }}

- name: Restart API service(s)
run: ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} ${{ vars.SSH_CMD_RESTART_API }}
deploy-live:
<<: *deploy-job
name: Deploy to Live
environment:
name: live
url: https://wows-karma.com/
needs:
- deploy-preview

0 comments on commit efcdf19

Please sign in to comment.