From 6e4a99eba3d4e19bddba44337680617a4a191007 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20DURR?= Date: Fri, 26 Aug 2022 13:20:57 +0200 Subject: [PATCH 1/8] Added sample deploy action --- .github/workflows/deploy.yml | 34 ++++++++++++++++++++------------- .github/workflows/unittests.bak | 7 ++++++- .github/workflows/unittests.yml | 7 ++++++- 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 8bc0cbdd..91e2203f 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,21 +1,29 @@ name: Deploy to production on: - workflow_run: - workflows: [Unit Testing] - types: [completed] - branches: - - master + push: + branches: [ actions ] + workflow_dispatch: jobs: - on-success: + deploy: runs-on: ubuntu-latest - if: ${{ github.event.workflow_run.conclusion == 'success' }} + steps: - - run: echo 'The triggering workflow passed' + - name: SSH Remote Commands + uses: appleboy/ssh-action@v0.1.5 + with: + # Proxy + proxy_host : ${{secrets.PROXY_HOST}} + proxy_port : ${{secrets.PROXY_PORT}} + proxy_username : ${{secrets.PROXY_USERNAME}} + proxy_passphrase: ${{secrets.PROXY_PASSPHRASE}} + proxy_key: ${{secrets.PROXY_KEY}} + + # Serveur web + host: ${{secrets.HOST}} + port : ${{secrets.PORT}} + username : ${{secrets.USERNAME}} + key: ${{secrets.KEY}} - on-failure: - runs-on: ubuntu-latest - if: ${{ github.event.workflow_run.conclusion == 'failure' }} - steps: - - run: echo 'The triggering workflow failed' \ No newline at end of file + script: whoami \ No newline at end of file diff --git a/.github/workflows/unittests.bak b/.github/workflows/unittests.bak index 733fe07b..98c57daf 100644 --- a/.github/workflows/unittests.bak +++ b/.github/workflows/unittests.bak @@ -1,6 +1,11 @@ name: Unit Testing -on: [push] +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + jobs: unittests: runs-on: ubuntu-latest diff --git a/.github/workflows/unittests.yml b/.github/workflows/unittests.yml index 8b5964d1..f1a6aa13 100644 --- a/.github/workflows/unittests.yml +++ b/.github/workflows/unittests.yml @@ -1,6 +1,11 @@ name: Unit Testing -on: [push] +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + jobs: unittests: runs-on: ubuntu-latest From 8a923761a5da8c96b6f2f45d22b68170a817da42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20DURR?= Date: Fri, 26 Aug 2022 13:26:41 +0200 Subject: [PATCH 2/8] Specified environment --- .github/workflows/deploy.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 91e2203f..21c30202 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -6,9 +6,10 @@ on: workflow_dispatch: jobs: - deploy: + deployment: runs-on: ubuntu-latest - + environment: production + steps: - name: SSH Remote Commands uses: appleboy/ssh-action@v0.1.5 From 83a384145ba02fe638eaf18728056ec39bfb179e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20DURR?= Date: Fri, 26 Aug 2022 13:43:13 +0200 Subject: [PATCH 3/8] Fixed spelling --- .github/workflows/deploy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 21c30202..780a6953 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -17,14 +17,14 @@ jobs: # Proxy proxy_host : ${{secrets.PROXY_HOST}} proxy_port : ${{secrets.PROXY_PORT}} - proxy_username : ${{secrets.PROXY_USERNAME}} + proxy_username : ${{secrets.PROXY_USER}} proxy_passphrase: ${{secrets.PROXY_PASSPHRASE}} proxy_key: ${{secrets.PROXY_KEY}} # Serveur web host: ${{secrets.HOST}} port : ${{secrets.PORT}} - username : ${{secrets.USERNAME}} + username : ${{secrets.USER}} key: ${{secrets.KEY}} script: whoami \ No newline at end of file From 13f0bfe546f05dfb540ea528d0f448f8f5e258a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20DURR?= Date: Fri, 26 Aug 2022 13:48:40 +0200 Subject: [PATCH 4/8] Enabled debug --- .github/workflows/deploy.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 780a6953..b03ba60b 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -27,4 +27,6 @@ jobs: username : ${{secrets.USER}} key: ${{secrets.KEY}} + debug: true + script: whoami \ No newline at end of file From ab43d7d2df22448f9bd4df26541a3badaa44e60f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20DURR?= Date: Fri, 26 Aug 2022 13:53:17 +0200 Subject: [PATCH 5/8] Testing things --- .github/workflows/deploy.yml | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index b03ba60b..d59f4c5b 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -15,17 +15,18 @@ jobs: uses: appleboy/ssh-action@v0.1.5 with: # Proxy - proxy_host : ${{secrets.PROXY_HOST}} - proxy_port : ${{secrets.PROXY_PORT}} - proxy_username : ${{secrets.PROXY_USER}} - proxy_passphrase: ${{secrets.PROXY_PASSPHRASE}} - proxy_key: ${{secrets.PROXY_KEY}} + # proxy_host : ${{secrets.PROXY_HOST}} + # proxy_port : ${{secrets.PROXY_PORT}} + # proxy_username : ${{secrets.PROXY_USER}} + # proxy_passphrase: ${{secrets.PROXY_PASSPHRASE}} + # proxy_key: ${{secrets.PROXY_KEY}} # Serveur web - host: ${{secrets.HOST}} - port : ${{secrets.PORT}} - username : ${{secrets.USER}} - key: ${{secrets.KEY}} + host: ${{secrets.PROXY_HOST}} + port : ${{secrets.PROXY_PORT}} + username : ${{secrets.PROXY_USER}} + key: ${{secrets.PROXY_KEY}} + passphrase: ${{secrets.PROXY_PASSPHRASE}} debug: true From 55e0eecc0b399c6dadea4827692484f6b10c3d44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20DURR?= Date: Fri, 26 Aug 2022 13:58:45 +0200 Subject: [PATCH 6/8] SSH Connection now works --- .github/workflows/deploy.yml | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index d59f4c5b..40539ed2 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -15,19 +15,18 @@ jobs: uses: appleboy/ssh-action@v0.1.5 with: # Proxy - # proxy_host : ${{secrets.PROXY_HOST}} - # proxy_port : ${{secrets.PROXY_PORT}} - # proxy_username : ${{secrets.PROXY_USER}} - # proxy_passphrase: ${{secrets.PROXY_PASSPHRASE}} - # proxy_key: ${{secrets.PROXY_KEY}} + proxy_host : ${{secrets.PROXY_HOST}} + proxy_port : ${{secrets.PROXY_PORT}} + proxy_username : ${{secrets.PROXY_USER}} + proxy_passphrase: ${{secrets.PROXY_PASSPHRASE}} + proxy_key: ${{secrets.PROXY_KEY}} # Serveur web - host: ${{secrets.PROXY_HOST}} - port : ${{secrets.PROXY_PORT}} - username : ${{secrets.PROXY_USER}} - key: ${{secrets.PROXY_KEY}} - passphrase: ${{secrets.PROXY_PASSPHRASE}} + host: ${{secrets.HOST}} + port : ${{secrets.PORT}} + username : ${{secrets.USER}} + key: ${{secrets.KEY}} - debug: true - - script: whoami \ No newline at end of file + script: | + whoami + ls -al \ No newline at end of file From 8646b2c8f7656edf69332d8a3b66fc801cd56c45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20DURR?= Date: Fri, 26 Aug 2022 14:10:37 +0200 Subject: [PATCH 7/8] Rollback to previous version (see: https://github.com/appleboy/ssh-action/issues/174) --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 40539ed2..58cafe7c 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -12,7 +12,7 @@ jobs: steps: - name: SSH Remote Commands - uses: appleboy/ssh-action@v0.1.5 + uses: appleboy/ssh-action@dce9d565de8d876c11d93fa4fe677c0285a66d78 with: # Proxy proxy_host : ${{secrets.PROXY_HOST}} From 596126f4f466fcb05b710e98fd0936a2a6bbc182 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20DURR?= Date: Fri, 26 Aug 2022 14:39:10 +0200 Subject: [PATCH 8/8] Actions seem to be operationnal --- .github/workflows/deploy.yml | 20 ++++++++-- .github/workflows/unittests.bak | 68 --------------------------------- .github/workflows/unittests.yml | 53 +++++++++++++++++++++++-- 3 files changed, 67 insertions(+), 74 deletions(-) delete mode 100644 .github/workflows/unittests.bak diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 58cafe7c..98862db5 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,14 +1,16 @@ name: Deploy to production +concurrency: production on: push: - branches: [ actions ] + branches: [master] workflow_dispatch: jobs: deployment: runs-on: ubuntu-latest environment: production + timeout-minutes: 30 steps: - name: SSH Remote Commands @@ -27,6 +29,18 @@ jobs: username : ${{secrets.USER}} key: ${{secrets.KEY}} + # See https://github.com/ae-utbm/sith3/wiki/GitHub-Actions#deployment-action script: | - whoami - ls -al \ No newline at end of file + BASE_DIR="$(dirname "$(realpath "$0")")" + export PATH="$HOME/.poetry/bin:$PATH" + pushd $BASE_DIR + + VERSION_LAST=$(git rev-parse HEAD) + git pull + poetry update + poetry run ./manage.py migrate + echo "yes" | poetry run ./manage.py collectstatic + poetry run ./manage.py compilestatic + poetry run ./manage.py compilemessages + + sudo systemctl restart uwsgi \ No newline at end of file diff --git a/.github/workflows/unittests.bak b/.github/workflows/unittests.bak deleted file mode 100644 index 98c57daf..00000000 --- a/.github/workflows/unittests.bak +++ /dev/null @@ -1,68 +0,0 @@ -name: Unit Testing - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -jobs: - unittests: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - - name: Set up python - uses: actions/setup-python@v4 - with: - python-version: '3.8' - - - name: Install dependencies - run: | - sudo apt-get update - sudo apt-get install gettext libxapian-dev libgraphviz-dev - - - name: Install poetry - run: | - python -m pip install --upgrade pip - python -m pip install poetry - - - name: Checking pyproject.toml syntax - run: poetry check - - - name: Install project - run: poetry install -E testing - - - name: Setup xapian index - run: | - mkdir -p /dev/shm/search_indexes - ln -s /dev/shm/search_indexes sith/search_indexes - - - name: Setup project - run: poetry run ./manage.py compilemessages - - - name: Launch tests and generate coverage report - run: | - poetry run coverage run ./manage.py test - poetry run coverage report - - lint: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - name: Set up python - uses: actions/setup-python@v4 - with: - python-version: '3.8' - - - name: Install black - run: | - python -m pip install --upgrade pip - python -m pip install black==22.6.0 - - - name: Check linting - run: black --check . - - diff --git a/.github/workflows/unittests.yml b/.github/workflows/unittests.yml index f1a6aa13..9356882a 100644 --- a/.github/workflows/unittests.yml +++ b/.github/workflows/unittests.yml @@ -5,18 +5,65 @@ on: branches: [ master ] pull_request: branches: [ master ] - + jobs: unittests: runs-on: ubuntu-latest + timeout-minutes: 30 steps: - - run: echo 'Dry test' + - uses: actions/checkout@v3 + + - name: Set up python + uses: actions/setup-python@v4 + with: + python-version: '3.8' + + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install gettext libxapian-dev libgraphviz-dev + + - name: Install poetry + run: | + python -m pip install --upgrade pip + python -m pip install poetry + + - name: Checking pyproject.toml syntax + run: poetry check + + - name: Install project + run: poetry install -E testing + + - name: Setup xapian index + run: | + mkdir -p /dev/shm/search_indexes + ln -s /dev/shm/search_indexes sith/search_indexes + + - name: Setup project + run: poetry run ./manage.py compilemessages + + - name: Launch tests and generate coverage report + run: | + poetry run coverage run ./manage.py test + poetry run coverage report lint: runs-on: ubuntu-latest steps: - - run: echo 'Dry lint' + - uses: actions/checkout@v3 + - name: Set up python + uses: actions/setup-python@v4 + with: + python-version: '3.8' + + - name: Install black + run: | + python -m pip install --upgrade pip + python -m pip install black==22.6.0 + + - name: Check linting + run: black --check .