Deploy ConnectX #34
This file contains hidden or 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: Deploy ConnectX | |
| on: | |
| workflow_run: | |
| workflows: [ "CodeQL Advanced" ] | |
| types: | |
| - completed | |
| workflow_dispatch: | |
| jobs: | |
| publish: | |
| if: github.event.workflow_run.conclusion == 'success' | |
| strategy: | |
| matrix: | |
| configuration: [Relay, Server] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Install .NET Core | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: 9.0.x | |
| - name: Init git submodule | |
| run: | | |
| git submodule init | |
| git submodule update | |
| - name: Restore the application | |
| run: dotnet restore | |
| - name: Build the application | |
| run: | | |
| cd ./ConnectX.${{ matrix.configuration }} | |
| dotnet publish -f net9.0 -c Release -r linux-x64 /p:PublishSingleFile=true | |
| - name: Upload build artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ matrix.configuration }}-Release-linux-x64 | |
| path: ./ConnectX.${{ matrix.configuration }}/bin/Release/net9.0/linux-x64/publish/ | |
| deploy-server: | |
| needs: publish | |
| strategy: | |
| matrix: | |
| server: [hangzhou, ningbo] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Download artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: Server-Release-linux-x64 | |
| path: ./deploy-package | |
| - name: Remove excluded files | |
| run: | | |
| find ./deploy-package -name "appsettings*.json" -delete | |
| - name: Stop remote service | |
| uses: appleboy/ssh-action@v1 | |
| with: | |
| host: ${{ secrets[format('Server_{0}_SSH_HOST', matrix.server)] }} | |
| username: ${{ secrets[format('Server_{0}_SSH_USERNAME', matrix.server)] }} | |
| password: ${{ secrets[format('Server_{0}_SSH_KEY', matrix.server)] }} | |
| script: sudo supervisorctl stop connectx-Server-service | |
| - name: Deploy via SFTP | |
| uses: wlixcc/SFTP-Deploy-Action@v1.2.5 | |
| with: | |
| server: ${{ secrets[format('Server_{0}_SSH_HOST', matrix.server)] }} | |
| username: ${{ secrets[format('Server_{0}_SSH_USERNAME', matrix.server)] }} | |
| password: ${{ secrets[format('Server_{0}_SSH_KEY', matrix.server)] }} | |
| local_path: './deploy-package/*' | |
| remote_path: '/www/connectx/Server' | |
| - name: Start remote service | |
| uses: appleboy/ssh-action@v1 | |
| with: | |
| host: ${{ secrets[format('Server_{0}_SSH_HOST', matrix.server)] }} | |
| username: ${{ secrets[format('Server_{0}_SSH_USERNAME', matrix.server)] }} | |
| password: ${{ secrets[format('Server_{0}_SSH_KEY', matrix.server)] }} | |
| script: sudo supervisorctl start connectx-Server-service | |
| deploy-relay: | |
| needs: deploy-server | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| server: [hangzhou, ningbo, shiyan] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Download artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: Relay-Release-linux-x64 | |
| path: ./deploy-package | |
| - name: Remove excluded files | |
| run: | | |
| find ./deploy-package -name "appsettings*.json" -delete | |
| - name: Stop remote service | |
| uses: appleboy/ssh-action@v1 | |
| with: | |
| host: ${{ secrets[format('Relay_{0}_SSH_HOST', matrix.server)] }} | |
| username: ${{ secrets[format('Relay_{0}_SSH_USERNAME', matrix.server)] }} | |
| password: ${{ secrets[format('Relay_{0}_SSH_KEY', matrix.server)] }} | |
| script: sudo supervisorctl stop connectx-Relay-service | |
| - name: Deploy via SFTP | |
| uses: wlixcc/SFTP-Deploy-Action@v1.2.5 | |
| with: | |
| server: ${{ secrets[format('Relay_{0}_SSH_HOST', matrix.server)] }} | |
| username: ${{ secrets[format('Relay_{0}_SSH_USERNAME', matrix.server)] }} | |
| password: ${{ secrets[format('Relay_{0}_SSH_KEY', matrix.server)] }} | |
| local_path: './deploy-package/*' | |
| remote_path: '/www/connectx/Relay' | |
| - name: Start remote service | |
| uses: appleboy/ssh-action@v1 | |
| with: | |
| host: ${{ secrets[format('Relay_{0}_SSH_HOST', matrix.server)] }} | |
| username: ${{ secrets[format('Relay_{0}_SSH_USERNAME', matrix.server)] }} | |
| password: ${{ secrets[format('Relay_{0}_SSH_KEY', matrix.server)] }} | |
| script: sudo supervisorctl start connectx-Relay-service |