From 79391a54bafc90efa557ad724b6e1d1a42209aa4 Mon Sep 17 00:00:00 2001 From: Michael Clapham Date: Sat, 7 Sep 2024 23:23:52 +0100 Subject: [PATCH 1/4] Create deploy.yml --- .github/workflows/deploy.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..e9cae90 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,27 @@ +on: + push: + branches: + - main + - deploy_gha +name: Deploy +jobs: + test: + name: Deploy on merge to main + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2.3.2 + - name: Cache node modules + uses: actions/cache@v1 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- + - uses: actions/setup-node@v2 + with: + node-version: '20' + - run: npm install + - run: npm run build + - run: sudo apt-get install tree + - run: tree build From 1b128007083fcfacfef9708653f93149b07a6eb3 Mon Sep 17 00:00:00 2001 From: Michael Clapham Date: Sat, 7 Sep 2024 23:31:43 +0100 Subject: [PATCH 2/4] Upload website files via SCP --- .github/workflows/deploy.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index e9cae90..c0b464a 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -25,3 +25,15 @@ jobs: - run: npm run build - run: sudo apt-get install tree - run: tree build + - name: Upload site files + uses: appleboy/scp-action@v0.1.7 + with: + host: ${{ secrets.SSH_HOST }} + username: ${{ secrets.SSH_USERNAME }} + password: ${{ secrets.SSH_PASSWORD }} + port: ${{ secrets.SSH_PORT }} + source: "build" + target: /var/www/qrsync + overwrite: true + + From ce12962b18c7473bf7206f0bec6a9e01757ef7d4 Mon Sep 17 00:00:00 2001 From: Michael Clapham Date: Sat, 7 Sep 2024 23:39:09 +0100 Subject: [PATCH 3/4] Upload to tmp folder then copy into web server folder then remove tmp --- .github/workflows/deploy.yml | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index c0b464a..aab022f 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -21,10 +21,14 @@ jobs: - uses: actions/setup-node@v2 with: node-version: '20' + - run: npm install + - run: npm run build + - run: sudo apt-get install tree - run: tree build + - name: Upload site files uses: appleboy/scp-action@v0.1.7 with: @@ -33,7 +37,24 @@ jobs: password: ${{ secrets.SSH_PASSWORD }} port: ${{ secrets.SSH_PORT }} source: "build" - target: /var/www/qrsync + target: /var/www/qrsync/tmp overwrite: true - + + - name: Move site files from tmp folder + uses: appleboy/ssh-action@v1.0.3 + with: + host: ${{ secrets.SSH_HOST }} + username: ${{ secrets.SSH_USERNAME }} + password: ${{ secrets.SSH_PASSWORD }} + port: ${{ secrets.SSH_PORT }} + script: cp "/var/www/qrsync/tmp/*" /var/www/qrsync + + - name: Remove tmp folder + uses: appleboy/ssh-action@v1.0.3 + with: + host: ${{ secrets.SSH_HOST }} + username: ${{ secrets.SSH_USERNAME }} + password: ${{ secrets.SSH_PASSWORD }} + port: ${{ secrets.SSH_PORT }} + script: rm -rf /var/www/qrsync/tmp From 45e73e90752422e469b48f02075e716f4d07bc40 Mon Sep 17 00:00:00 2001 From: Michael Clapham Date: Sat, 7 Sep 2024 23:43:01 +0100 Subject: [PATCH 4/4] Use -a recursive copy --- .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 aab022f..79fbaa5 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -47,7 +47,7 @@ jobs: username: ${{ secrets.SSH_USERNAME }} password: ${{ secrets.SSH_PASSWORD }} port: ${{ secrets.SSH_PORT }} - script: cp "/var/www/qrsync/tmp/*" /var/www/qrsync + script: cp -a /var/www/qrsync/tmp/build/. /var/www/qrsync - name: Remove tmp folder uses: appleboy/ssh-action@v1.0.3