From 54ac62aac9b71c9d2058f05881ee3e44a558222e Mon Sep 17 00:00:00 2001 From: Leo-Nicolle Date: Thu, 15 Feb 2024 22:04:43 +0100 Subject: [PATCH] Test Deploy (#68) --- .github/workflows/deploy.yml | 66 +++++++++++++++++------------------- .gitignore | 3 +- scripts/postbuild.mjs | 25 +++----------- 3 files changed, 39 insertions(+), 55 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index efc7bcf..ded7662 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,12 +1,12 @@ name: Deploy on: - pull_request: - types: [closed] + push: + branches: + - master jobs: deploy: - if: github.event.pull_request.merged == true || github.ref_name == 'master' runs-on: ubuntu-latest env: TARGET: ${{ secrets.SERVER_USERNAME }}@${{ secrets.SERVER_HOST }} @@ -16,8 +16,6 @@ jobs: steps: - name: Checkout Repository uses: actions/checkout@v2 - with: - ref: "develop" - name: Setup ssh run: | mkdir -p ~/.ssh/ && touch ~/.ssh/known_hosts @@ -30,19 +28,19 @@ jobs: with: node-version: "18" - - name: Determine Deployment Type - if: ${{ success() }} - run: | - echo "DEPLOY_ASSETS=${{ contains(toJson(github.event.pull_request.labels.*.name), 'deploy:assets') }}" >> $GITHUB_ENV - echo "DEPLOY_SERVER=${{ contains(toJson(github.event.pull_request.labels.*.name), 'deploy:server') }}" >> $GITHUB_ENV - echo "DEPLOY_CLIENT=${{ contains(toJson(github.event.pull_request.labels.*.name), 'deploy:client') }}" >> $GITHUB_ENV - echo "PUBLIC=$DIR/public" >> $GITHUB_ENV - echo "SERVER=${{ env.DIR }}/server.js" >> $GITHUB_ENV - echo "ASSETS=${{ env.DIR }}/public/assets" >> $GITHUB_ENV - echo "INDEX_HTML=${{ env.DIR }}/public/index.html" >> $GITHUB_ENV - if [[ $DEPLOY_ASSETS == 'false' && $DEPLOY_SERVER == 'false' && $DEPLOY_CLIENT == 'false' ]]; then - exit 1; - fi + # - name: Determine Deployment Type + # if: ${{ success() }} + # run: | + # echo "DEPLOY_ASSETS=${{ contains(toJson(github.event.pull_request.labels.*.name), 'deploy:assets') }}" >> $GITHUB_ENV + # echo "DEPLOY_SERVER=${{ contains(toJson(github.event.pull_request.labels.*.name), 'deploy:server') }}" >> $GITHUB_ENV + # echo "DEPLOY_CLIENT=${{ contains(toJson(github.event.pull_request.labels.*.name), 'deploy:client') }}" >> $GITHUB_ENV + # echo "PUBLIC=$DIR/public" >> $GITHUB_ENV + # echo "SERVER=${{ env.DIR }}/server.js" >> $GITHUB_ENV + # echo "ASSETS=${{ env.DIR }}/public/assets" >> $GITHUB_ENV + # echo "INDEX_HTML=${{ env.DIR }}/public/index.html" >> $GITHUB_ENV + # if [[ $DEPLOY_ASSETS == 'false' && $DEPLOY_SERVER == 'false' && $DEPLOY_CLIENT == 'false' ]]; then + # exit 1; + # fi - name: Install Dependencies if: ${{ success() }} @@ -55,21 +53,21 @@ jobs: - name: Deploy if: ${{ success() }} run: | - if [ "$DEPLOY_ASSETS" = 'true' ]; then - echo "Deploying JS assets" - ssh -i $KEY $TARGET "rm -rf $ASSETS && mkdir -p $ASSETS" - scp -i $KEY -r dist/public/assets/* "$TARGET:$ASSETS" - scp -i $KEY -r dist/public/index.html "$TARGET:$INDEX_HTML" - fi - if [ "$DEPLOY_CLIENT" = 'true' ]; then - echo "Deploying full client" - ssh -i $KEY $TARGET "rm -rf $PUBLIC && mkdir -p $PUBLIC" - scp -i $KEY -r dist/public/* "$TARGET:$PUBLIC" - ssh -i $KEY $TARGET "cp $DICOS/*.zip $PUBLIC/assets" - fi - if [ "$DEPLOY_SERVER" = 'true' ]; then - echo "Deploying server code" - scp -i $KEY -r dist/server.js "$TARGET:$SERVER" - fi + # if [ "$DEPLOY_ASSETS" = 'true' ]; then + # echo "Deploying JS assets" + # ssh -i $KEY $TARGET "rm -rf $ASSETS && mkdir -p $ASSETS" + # scp -i $KEY -r dist/public/assets/* "$TARGET:$ASSETS" + # scp -i $KEY -r dist/public/index.html "$TARGET:$INDEX_HTML" + # fi + # if [ "$DEPLOY_CLIENT" = 'true' ]; then + echo "Deploying full client" + ssh -i $KEY $TARGET "rm -rf $PUBLIC && mkdir -p $PUBLIC" + scp -i $KEY -r dist/public/* "$TARGET:$PUBLIC" + ssh -i $KEY $TARGET "cp $DICOS/*.zip $PUBLIC/assets" + # fi + # if [ "$DEPLOY_SERVER" = 'true' ]; then + echo "Deploying server code" + scp -i $KEY -r dist/server.js "$TARGET:$SERVER" + # fi - name: Cleanup run: "rm -f $KEY && rm -rf ~/.ssh" diff --git a/.gitignore b/.gitignore index 576c127..fd503ea 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,5 @@ build/ dist/ docs/.vuepress/.cache docs/.vuepress/.temp -scripts/api-key.mjs \ No newline at end of file +scripts/api-key.mjs +scripts/plausible-key \ No newline at end of file diff --git a/scripts/postbuild.mjs b/scripts/postbuild.mjs index bbd4eab..ea924c0 100644 --- a/scripts/postbuild.mjs +++ b/scripts/postbuild.mjs @@ -1,29 +1,14 @@ import rimraf from "rimraf"; -import { mkdir } from 'fs/promises' +import { mkdir } from 'fs/promises'; import fs from "fs-extra"; import path from 'path'; -import { tmpdir } from 'os'; - const outFolder = 'dist/'; -// function buildjs() { -// const outDir = 'dist/'; -// const tmpDir = path.resolve(tmpdir(), `mots-flex-js${Date.now()}`); -// return fs.mkdir(outDir, { recursive: true }) -// .then(() => Promise.all([ -// fs.copy("build/public", path.resolve(tmpDir, "public")), -// fs.copy("build/dico", path.resolve(tmpDir, "dico")), -// fs.copy("build/server.js", path.resolve(tmpDir, "server.js")), -// ])) -// .then(() => wz.mZip.zipFolder(tmpDir, 'dist/mots-flex-js.zip')) -// } - - Promise.resolve() -.then(() => rimraf(outFolder)) -.then(() => mkdir(outFolder)) -.then(() => fs.copy('server/dist', outFolder)) -.then(() => fs.copy('client/dist', path.resolve(outFolder, 'public'))) + .then(() => rimraf(outFolder)) + .then(() => mkdir(outFolder)) + .then(() => fs.copy('server/dist', outFolder)) + .then(() => fs.copy('client/dist', path.resolve(outFolder, 'public')))