From 0a759ed4e52a718ba99868e99e30cfc276f9a465 Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Wed, 12 Jun 2024 19:52:00 +0100 Subject: [PATCH] Add workflows --- .forgejo/workflows/production.yml | 73 ---------------------------- .forgejo/workflows/stage.yml | 73 ---------------------------- .forgejo/workflows/test.yml | 25 ---------- .github/workflows/prod.yml | 79 +++++++++++++++++++++++++++++++ .github/workflows/stage.yml | 78 ++++++++++++++++++++++++++++++ .github/workflows/test.yml | 27 +++++++++++ 6 files changed, 184 insertions(+), 171 deletions(-) delete mode 100644 .forgejo/workflows/production.yml delete mode 100644 .forgejo/workflows/stage.yml delete mode 100644 .forgejo/workflows/test.yml create mode 100644 .github/workflows/prod.yml create mode 100644 .github/workflows/stage.yml create mode 100644 .github/workflows/test.yml diff --git a/.forgejo/workflows/production.yml b/.forgejo/workflows/production.yml deleted file mode 100644 index 19ce662..0000000 --- a/.forgejo/workflows/production.yml +++ /dev/null @@ -1,73 +0,0 @@ -name: Deploy To Production - -on: - push: - branches: - - main - -jobs: - build: - environment: prod - - runs-on: node - - steps: - - uses: actions/checkout@v4 - - name: Use Node.js - uses: actions/setup-node@v4 - with: - node-version: 18.x - - run: yarn install --frozen-lockfile - - run: yarn build - - run: yarn test - - run: yarn lint - - - name: "Copy files over to location" - run: cp -r . ${{ secrets.PROD_REPO_PATH }} - - deploy: - environment: prod - needs: build - runs-on: node - steps: - - uses: https://github.com/appleboy/ssh-action@v1.0.0 - env: - DB_NAME: ${{ secrets.PROD_DB_NAME }} - DB_AUTH_USER: ${{ secrets.PROD_DB_AUTH_USER }} - DB_AUTH_PASS: ${{ secrets.PROD_DB_AUTH_PASS }} - DB_HOST: ${{ secrets.PROD_DB_HOST }} - DB_PORT: ${{ secrets.PROD_DB_PORT }} - DB_ROOT_HOST: ${{ secrets.PROD_DB_ROOT_HOST }} - DB_SYNC: ${{ secrets.PROD_DB_SYNC }} - DB_LOGGING: ${{ secrets.PROD_DB_LOGGING }} - DB_DATA_LOCATION: ${{ secrets.PROD_DB_DATA_LOCATION }} - SERVER_PATH: ${{ secrets.PROD_SSH_SERVER_PATH }} - BOT_TOKEN: ${{ secrets.PROD_BOT_TOKEN }} - BOT_VER: ${{ vars.PROD_BOT_VER }} - BOT_AUTHOR: ${{ vars.PROD_BOT_AUTHOR }} - BOT_OWNERID: ${{ vars.PROD_BOT_OWNERID }} - BOT_CLIENTID: ${{ vars.PROD_BOT_CLIENTID }} - BOT_ENV: ${{ vars.PROD_BOT_ENV }} - BOT_ADMINS: ${{ vars.PROD_BOT_ADMINS }} - ABOUT_FUNDING: ${{ vars.PROD_ABOUT_FUNDING }} - ABOUT_REPO: ${{ vars.PROD_ABOUT_REPO }} - DATA_DIR: ${{ secrets.PROD_DATA_DIR }} - GDRIVESYNC_AUTO: ${{ vars.PROD_GDRIVESYNC_AUTO }} - EXPRESS_PORT: ${{ secrets.PROD_EXPRESS_PORT }} - BOT_LOGLEVEL: ${{ vars.PROD_BOT_LOGLEVEL }} - with: - host: ${{ secrets.PROD_SSH_HOST }} - username: ${{ secrets.PROD_SSH_USER }} - key: ${{ secrets.PROD_SSH_KEY }} - port: ${{ secrets.PROD_SSH_PORT }} - envs: DB_NAME,DB_AUTH_USER,DB_AUTH_PASS,DB_HOST,DB_PORT,DB_ROOT_HOST,DB_SYNC,DB_LOGGING,DB_DATA_LOCATION,BOT_TOKEN,BOT_VER,BOT_AUTHOR,BOT_OWNERID,BOT_CLIENTID,ABOUT_FUNDING,ABOUT_REPO,BOT_ENV,BOT_ADMINS,DATA_DIR,GDRIVESYNC_AUTO,SERVER_PATH,EXPRESS_PORT,BOT_LOGLEVEL - script: | - source .sshrc \ - && cd /home/vylpes/apps/card-drop/card-drop_prod \ - && docker compose down \ - && (pm2 stop card-drop_prod || true) \ - && (pm2 delete card-drop_prod || true) \ - && docker compose up -d \ - && sleep 10 \ - && yarn run db:up \ - && pm2 start --name card-drop_prod dist/bot.js \ No newline at end of file diff --git a/.forgejo/workflows/stage.yml b/.forgejo/workflows/stage.yml deleted file mode 100644 index 37ff5ea..0000000 --- a/.forgejo/workflows/stage.yml +++ /dev/null @@ -1,73 +0,0 @@ -name: Deploy To Stage - -on: - push: - branches: - - develop - -jobs: - build: - environment: stage - - runs-on: node - - steps: - - uses: actions/checkout@v4 - - name: Use Node.js - uses: actions/setup-node@v4 - with: - node-version: 18.x - - run: yarn install --frozen-lockfile - - run: yarn build - - run: yarn test - - run: yarn lint - - - name: "Copy files over to location" - run: cp -r . ${{ secrets.STAGE_REPO_PATH }} - - deploy: - environment: prod - needs: build - runs-on: node - steps: - - uses: https://github.com/appleboy/ssh-action@v1.0.0 - env: - DB_NAME: ${{ secrets.STAGE_DB_NAME }} - DB_AUTH_USER: ${{ secrets.STAGE_DB_AUTH_USER }} - DB_AUTH_PASS: ${{ secrets.STAGE_DB_AUTH_PASS }} - DB_HOST: ${{ secrets.STAGE_DB_HOST }} - DB_PORT: ${{ secrets.STAGE_DB_PORT }} - DB_ROOT_HOST: ${{ secrets.STAGE_DB_ROOT_HOST }} - DB_SYNC: ${{ secrets.STAGE_DB_SYNC }} - DB_LOGGING: ${{ secrets.STAGE_DB_LOGGING }} - DB_DATA_LOCATION: ${{ secrets.STAGE_DB_DATA_LOCATION }} - SERVER_PATH: ${{ secrets.STAGE_SSH_SERVER_PATH }} - BOT_TOKEN: ${{ secrets.STAGE_BOT_TOKEN }} - BOT_VER: ${{ vars.STAGE_BOT_VER }} - BOT_AUTHOR: ${{ vars.STAGE_BOT_AUTHOR }} - BOT_OWNERID: ${{ vars.STAGE_BOT_OWNERID }} - BOT_CLIENTID: ${{ vars.STAGE_BOT_CLIENTID }} - BOT_ENV: ${{ vars.STAGE_BOT_ENV }} - BOT_ADMINS: ${{ vars.STAGE_BOT_ADMINS }} - ABOUT_FUNDING: ${{ vars.STAGE_ABOUT_FUNDING }} - ABOUT_REPO: ${{ vars.STAGE_ABOUT_REPO }} - DATA_DIR: ${{ secrets.STAGE_DATA_DIR }} - GDRIVESYNC_AUTO: ${{ vars.STAGE_GDRIVESYNC_AUTO }} - EXPRESS_PORT: ${{ secrets.STAGE_EXPRESS_PORT }} - BOT_LOGLEVEL: ${{ vars.STAGE_BOT_LOGLEVEL }} - with: - host: ${{ secrets.STAGE_SSH_HOST }} - username: ${{ secrets.STAGE_SSH_USER }} - key: ${{ secrets.STAGE_SSH_KEY }} - port: ${{ secrets.STAGE_SSH_PORT }} - envs: DB_NAME,DB_AUTH_USER,DB_AUTH_PASS,DB_HOST,DB_PORT,DB_ROOT_HOST,DB_SYNC,DB_LOGGING,DB_DATA_LOCATION,BOT_TOKEN,BOT_VER,BOT_AUTHOR,BOT_OWNERID,BOT_CLIENTID,ABOUT_FUNDING,ABOUT_REPO,BOT_ENV,BOT_ADMINS,DATA_DIR,GDRIVESYNC_AUTO,SERVER_PATH,EXPRESS_PORT,BOT_LOGLEVEL - script: | - source .sshrc \ - && cd /home/vylpes/apps/card-drop/card-drop_stage \ - && docker compose down \ - && (pm2 stop card-drop_stage || true) \ - && (pm2 delete card-drop_stage || true) \ - && docker compose up -d \ - && sleep 10 \ - && yarn run db:up \ - && pm2 start --name card-drop_stage dist/bot.js \ No newline at end of file diff --git a/.forgejo/workflows/test.yml b/.forgejo/workflows/test.yml deleted file mode 100644 index b2de547..0000000 --- a/.forgejo/workflows/test.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: Test - -on: - push: - branches: - - feature/* - - hotfix/* - - renovate/* - -jobs: - build: - environment: stage - - runs-on: node - - steps: - - uses: actions/checkout@v4 - - name: Use Node.js - uses: actions/setup-node@v4 - with: - node-version: 18.x - - run: yarn install --frozen-lockfile - - run: yarn build - - run: yarn test - - run: yarn lint \ No newline at end of file diff --git a/.github/workflows/prod.yml b/.github/workflows/prod.yml new file mode 100644 index 0000000..b83d066 --- /dev/null +++ b/.github/workflows/prod.yml @@ -0,0 +1,79 @@ +name: Deploy To Prod + +on: + workflow_dispatch: + push: + branches: + - main + + +jobs: + build: + environment: prod + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Use Node.js + uses: actions/setup-node@v1 + with: + node-version: 18.x + - run: yarn install --frozen-lockfile + - run: yarn build + - run: yarn test + + - name: RSync to Prod Server + uses: D3rHase/rsync-deploy-action@v0.2 + with: + HOST: ${{ secrets.SSH_HOST }} + PORT: ${{ secrets.SSH_PORT }} + USER: ${{ secrets.SSH_USER }} + PRIVATE_SSH_KEY: ${{ secrets.SSH_KEY }} + REPOSITORY_PATH: ${{ secrets.SSH_REPO_PATH }} + SERVER_PATH: ${{ secrets.SSH_SERVER_PATH }} + + deploy: + environment: prod + needs: build + runs-on: ubuntu-latest + steps: + - uses: appleboy/ssh-action@v1.0.0 + env: + DB_NAME: ${{ secrets.DB_NAME }} + DB_AUTH_USER: ${{ secrets.DB_AUTH_USER }} + DB_AUTH_PASS: ${{ secrets.DB_AUTH_PASS }} + DB_HOST: ${{ secrets.DB_HOST }} + DB_PORT: ${{ secrets.DB_PORT }} + DB_ROOT_HOST: ${{ secrets.DB_ROOT_HOST }} + DB_SYNC: ${{ secrets.DB_SYNC }} + DB_LOGGING: ${{ secrets.DB_LOGGING }} + DB_DATA_LOCATION: ${{ secrets.DB_DATA_LOCATION }} + DB_CARD_FILE: ${{ secrets.DB_CARD_FILE }} + BOT_TOKEN: ${{ secrets.BOT_TOKEN }} + BOT_VER: ${{ vars.BOT_VER }} + BOT_AUTHOR: ${{ vars.BOT_AUTHOR }} + BOT_OWNERID: ${{ vars.BOT_OWNERID }} + BOT_CLIENTID: ${{ vars.BOT_CLIENTID }} + ABOUT_FUNDING: ${{ vars.ABOUT_FUNDING }} + ABOUT_REPO: ${{ vars.ABOUT_REPO }} + DATA_DIR: ${{ secrets.DATA_DIR }} + EXPRESS_PORT: ${{ secrets.EXPRESS_PORT }} + GDRIVESYNC_AUTO: ${{ vars.GDRIVESYNC_AUTO }} + BOT_ADMINS: ${{ vars.BOT_ADMINS }} + BOT_ENV: ${{ vars.BOT_ENV }} + with: + host: ${{ secrets.SSH_HOST }} + username: ${{ secrets.SSH_USER }} + key: ${{ secrets.SSH_KEY }} + port: ${{ secrets.SSH_PORT }} + envs: DB_NAME,DB_AUTH_USER,DB_AUTH_PASS,DB_HOST,DB_PORT,DB_ROOT_HOST,DB_CARD_FILE,DB_SYNC,DB_LOGGING,DB_DATA_LOCATION,BOT_TOKEN,BOT_VER,BOT_AUTHOR,BOT_OWNERID,BOT_CLIENTID,ABOUT_FUNDING,ABOUT_REPO,DATA_DIR,EXPRESS_PORT,GDRIVESYNC_AUTO,BOT_ADMINS,BOT_ENV + script: | + cd ${{ secrets.SSH_SERVER_PATH }} \ + && docker compose down \ + && (pm2 stop carddrop_prod || true) \ + && (pm2 delete carddrop_prod || true) \ + && docker compose up -d \ + && sleep 10 \ + && yarn run db:up \ + && pm2 start --name carddrop_prod dist/bot.js \ No newline at end of file diff --git a/.github/workflows/stage.yml b/.github/workflows/stage.yml new file mode 100644 index 0000000..90d51ad --- /dev/null +++ b/.github/workflows/stage.yml @@ -0,0 +1,78 @@ +name: Deploy To Stage + +on: + workflow_dispatch: + push: + branches: + - develop + +jobs: + build: + environment: stage + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Use Node.js + uses: actions/setup-node@v3 + with: + node-version: 18.x + - run: yarn install --frozen-lockfile + - run: yarn build + - run: yarn test + + - name: RSync to Stage Server + uses: D3rHase/rsync-deploy-action@v0.2 + with: + HOST: ${{ secrets.SSH_HOST }} + PORT: ${{ secrets.SSH_PORT }} + USER: ${{ secrets.SSH_USER }} + PRIVATE_SSH_KEY: ${{ secrets.SSH_KEY }} + REPOSITORY_PATH: ${{ secrets.SSH_REPO_PATH }} + SERVER_PATH: ${{ secrets.SSH_SERVER_PATH }} + + deploy: + environment: stage + needs: build + runs-on: ubuntu-latest + steps: + - uses: appleboy/ssh-action@v1.0.0 + env: + DB_NAME: ${{ secrets.DB_NAME }} + DB_AUTH_USER: ${{ secrets.DB_AUTH_USER }} + DB_AUTH_PASS: ${{ secrets.DB_AUTH_PASS }} + DB_HOST: ${{ secrets.DB_HOST }} + DB_PORT: ${{ secrets.DB_PORT }} + DB_ROOT_HOST: ${{ secrets.DB_ROOT_HOST }} + DB_SYNC: ${{ secrets.DB_SYNC }} + DB_LOGGING: ${{ secrets.DB_LOGGING }} + DB_DATA_LOCATION: ${{ secrets.DB_DATA_LOCATION }} + DB_CARD_FILE: ${{ secrets.DB_CARD_FILE }} + BOT_TOKEN: ${{ secrets.BOT_TOKEN }} + BOT_VER: ${{ vars.BOT_VER }} + BOT_AUTHOR: ${{ vars.BOT_AUTHOR }} + BOT_OWNERID: ${{ vars.BOT_OWNERID }} + BOT_CLIENTID: ${{ vars.BOT_CLIENTID }} + ABOUT_FUNDING: ${{ vars.ABOUT_FUNDING }} + ABOUT_REPO: ${{ vars.ABOUT_REPO }} + DATA_DIR: ${{ secrets.DATA_DIR }} + EXPRESS_PORT: ${{ secrets.EXPRESS_PORT }} + GDRIVESYNC_AUTO: ${{ vars.GDRIVESYNC_AUTO }} + BOT_ADMINS: ${{ vars.BOT_ADMINS }} + BOT_ENV: ${{ vars.BOT_ENV }} + with: + host: ${{ secrets.SSH_HOST }} + username: ${{ secrets.SSH_USER }} + key: ${{ secrets.SSH_KEY }} + port: ${{ secrets.SSH_PORT }} + envs: DB_NAME,DB_AUTH_USER,DB_AUTH_PASS,DB_HOST,DB_PORT,DB_ROOT_HOST,DB_CARD_FILE,DB_SYNC,DB_LOGGING,DB_DATA_LOCATION,BOT_TOKEN,BOT_VER,BOT_AUTHOR,BOT_OWNERID,BOT_CLIENTID,ABOUT_FUNDING,ABOUT_REPO,DATA_DIR,EXPRESS_PORT,GDRIVESYNC_AUTO,BOT_ADMINS,BOT_ENV + script: | + cd ${{ secrets.SSH_SERVER_PATH }} \ + && docker compose down \ + && (pm2 stop carddrop_stage || true) \ + && (pm2 delete carddrop_stage || true) \ + && docker compose up -d \ + && sleep 10 \ + && yarn run db:up \ + && pm2 start --name carddrop_stage dist/bot.js \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..b656d5b --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,27 @@ +name: Test + +on: + push: + branches: + - feature/* + - hotfix/* + - renovate/* + +jobs: + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [18.x, 20.x] + + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - run: yarn install --frozen-lockfile + - run: yarn build + - run: yarn test \ No newline at end of file