From 501c51b865b92196ef347f61d2d2ef7b44739ceb Mon Sep 17 00:00:00 2001 From: Octol1ttle Date: Mon, 14 Aug 2023 18:24:20 +0500 Subject: [PATCH] Add automatic deployment (#90) This PR closes #87. This PR splits the workflow into 2 files: `build-pr.yml` and `build-push.yml`. The former runs InspectCode to make sure issues don't get through, while the latter builds and uploads Boyfriend and publishes it to a remote production server via SSH. --------- Signed-off-by: Octol1ttle --- .editorconfig | 4 +++ .github/workflows/build-pr.yml | 31 ++++++++++++++++ .github/workflows/build-push.yml | 61 ++++++++++++++++++++++++++++++++ .github/workflows/resharper.yml | 36 ------------------- 4 files changed, 96 insertions(+), 36 deletions(-) create mode 100644 .github/workflows/build-pr.yml create mode 100644 .github/workflows/build-push.yml delete mode 100644 .github/workflows/resharper.yml diff --git a/.editorconfig b/.editorconfig index 7548c96..4982036 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1760,3 +1760,7 @@ resharper_zero_index_from_end_highlighting = warning indent_style = space indent_size = 4 tab_width = 4 + +[*.yml] +indent_style = space +indent_size = 2 diff --git a/.github/workflows/build-pr.yml b/.github/workflows/build-pr.yml new file mode 100644 index 0000000..dc91660 --- /dev/null +++ b/.github/workflows/build-pr.yml @@ -0,0 +1,31 @@ +name: "ReSharper" +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +on: + pull_request: + branches: [ "master" ] + merge_group: + types: [ checks_requested ] + +jobs: + inspect-code: + name: Inspect code + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: ReSharper CLI InspectCode + uses: muno92/resharper_inspectcode@1.8.0 + with: + solutionPath: ./Boyfriend.sln + ignoreIssueType: InvertIf, ConvertIfStatementToSwitchStatement + extensions: ReSharperPlugin.CognitiveComplexity + solutionWideAnalysis: true diff --git a/.github/workflows/build-push.yml b/.github/workflows/build-push.yml new file mode 100644 index 0000000..731201d --- /dev/null +++ b/.github/workflows/build-push.yml @@ -0,0 +1,61 @@ +name: "Publish and deploy" +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +on: + push: + branches: [ "master" ] + +jobs: + upload-solution: + name: Upload Boyfriend to production + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + environment: production + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Publish solution + run: dotnet publish -c Release -r linux-x64 --no-self-contained -p:PublishReadyToRun=true + + - name: Setup SSH key + run: | + install -m 600 -D /dev/null ~/.ssh/id_rsa + echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa + ssh-keyscan -H $SSH_HOST > ~/.ssh/known_hosts + shell: bash + env: + SSH_PRIVATE_KEY: ${{secrets.SSH_PRIVATE_KEY}} + SSH_HOST: ${{secrets.SSH_HOST}} + + - name: Quit currently running instance + continue-on-error: true + run: | + ssh $SSH_USER@$SSH_HOST pkill --signal SIGQUIT Boyfriend + shell: bash + env: + SSH_USER: ${{secrets.SSH_USER}} + SSH_HOST: ${{secrets.SSH_HOST}} + + - name: Upload published solution + run: | + scp -r bin/Release/net7.0/linux-x64/publish/* $SSH_USER@$SSH_HOST:$UPLOAD_DESTINATION + shell: bash + env: + SSH_USER: ${{secrets.SSH_USER}} + SSH_HOST: ${{secrets.SSH_HOST}} + UPLOAD_DESTINATION: ${{secrets.UPLOAD_DESTINATION}} + + - name: Start uploaded solution + run: | + ssh $SSH_USER@$SSH_HOST $COMMAND + shell: bash + env: + SSH_USER: ${{secrets.SSH_USER}} + SSH_HOST: ${{secrets.SSH_HOST}} + COMMAND: ${{secrets.COMMAND}} diff --git a/.github/workflows/resharper.yml b/.github/workflows/resharper.yml deleted file mode 100644 index 860dd94..0000000 --- a/.github/workflows/resharper.yml +++ /dev/null @@ -1,36 +0,0 @@ -name: "ReSharper" -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -on: - push: - branches: [ "*" ] - pull_request: - branches: [ "master" ] - merge_group: - types: [checks_requested] - -jobs: - inspect-code: - name: Inspect code - runs-on: ubuntu-latest - permissions: - actions: read - contents: read - security-events: write - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Restore dependencies and tools - run: dotnet restore - - - name: ReSharper CLI InspectCode - uses: muno92/resharper_inspectcode@1.8.0 - with: - solutionPath: ./Boyfriend.sln - ignoreIssueType: InvertIf, ConvertIfStatementToSwitchStatement - extensions: ReSharperPlugin.CognitiveComplexity - solutionWideAnalysis: true