From 93d354eb33456ace96134a12e01b143487b58446 Mon Sep 17 00:00:00 2001 From: Nicolas Picon Date: Tue, 27 Aug 2024 23:21:11 +0200 Subject: [PATCH] fix/restart-server (#104) (hopefully) --- .github/workflows/deploy-on-tag.yml | 7 +++---- .github/workflows/restart-server.yml | 9 ++++----- act/n2rss_dev.variables | 2 +- test_cd.sh | 7 ++++++- test_restart_server.sh | 25 +++++++++++++++++++++++++ 5 files changed, 39 insertions(+), 11 deletions(-) create mode 100755 test_restart_server.sh diff --git a/.github/workflows/deploy-on-tag.yml b/.github/workflows/deploy-on-tag.yml index d7ecaf0..7ef3255 100644 --- a/.github/workflows/deploy-on-tag.yml +++ b/.github/workflows/deploy-on-tag.yml @@ -38,6 +38,7 @@ jobs: server-dir: ${{ vars.FTP_DIR }} local-dir: ./deploy/ create-github-release: + if: ${{ !env.ACT }} needs: deploy runs-on: ubuntu-latest permissions: @@ -71,7 +72,5 @@ jobs: runs-on: ubuntu-latest steps: - name: Trigger Restart Server workflow - uses: peter-evans/repository-dispatch@v3 - with: - token: ${{ secrets.GITHUB_TOKEN }} - event-type: trigger-restart-server + uses: ./.github/workflows/restart-server.yml + secrets: inherit diff --git a/.github/workflows/restart-server.yml b/.github/workflows/restart-server.yml index f6dcefe..96a85cc 100644 --- a/.github/workflows/restart-server.yml +++ b/.github/workflows/restart-server.yml @@ -2,8 +2,7 @@ name: Restart Server on: workflow_dispatch: # Allows manual triggering - repository_dispatch: - types: [ trigger-restart-server ] + workflow_call: # Allows calling from another workflow jobs: restart-server: @@ -18,12 +17,12 @@ jobs: { "X-Secret-Key": "${{ secrets.SERVER_MAINTENANCE_SECRET_KEY }}" } - preventFailureOnNoResponse: true - - name: Wait for 1 minutes + - name: Wait until the server has stopped run: | - sleep 60 + sleep 15 - name: Restart Server uses: fjogeleit/http-request-action@v1 with: url: ${{ vars.SERVER_ENDPOINT }} method: GET + preventFailureOnNoResponse: true diff --git a/act/n2rss_dev.variables b/act/n2rss_dev.variables index cae2ac3..7a9d460 100644 --- a/act/n2rss_dev.variables +++ b/act/n2rss_dev.variables @@ -1,2 +1,2 @@ FTP_DIR=/n2rss/ -SERVER_ENDPOINT=http://localhost:8080 +SERVER_ENDPOINT=http://host.docker.internal:8080 diff --git a/test_cd.sh b/test_cd.sh index c3686ee..d3fe941 100755 --- a/test_cd.sh +++ b/test_cd.sh @@ -16,8 +16,13 @@ # DEALINGS IN THE SOFTWARE. # -act push -s GITHUB_TOKEN="$(gh auth token)" \ +echo "{ \"ref\": \"refs/tags/1.0.0\" }" > act_cd_event.json + +act push -e act_cd_event.json \ + -s GITHUB_TOKEN="$(gh auth token)" \ --container-architecture linux/amd64 \ --artifact-server-path ./act/artifacts \ --var-file ./act/n2rss_dev.variables \ --secret-file ./act/n2rss_dev.secrets + +rm act_cd_event.json diff --git a/test_restart_server.sh b/test_restart_server.sh new file mode 100755 index 0000000..7e83792 --- /dev/null +++ b/test_restart_server.sh @@ -0,0 +1,25 @@ +# +# Copyright (c) 2024 Nicolas PICON +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +# documentation files (the "Software"), to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, +# and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all copies or substantial portions +# of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +# TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +# CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + +act workflow_dispatch \ + -W .github/workflows/restart-server.yml \ + -s GITHUB_TOKEN="$(gh auth token)" \ + --container-architecture linux/amd64 \ + --artifact-server-path ./act/artifacts \ + --var-file ./act/n2rss_dev.variables \ + --secret-file ./act/n2rss_dev.secrets