server prod no longer min #4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: dev | |
on: | |
push: | |
branches: | |
- dev | |
jobs: | |
# JOB to run change detection | |
detectChanges: | |
runs-on: ubuntu-latest | |
timeout-minutes: 5 | |
outputs: | |
CD: ${{ steps.filter.outputs.CD }} | |
images: ${{ steps.filter.outputs.images }} | |
imagesFiles: ${{ steps.filter.outputs.images_files }} | |
server: ${{ steps.filter.outputs.server }} | |
replServer: ${{ steps.filter.outputs.replServer }} | |
app: ${{ steps.filter.outputs.app }} | |
serviceWorker: ${{ steps.filter.outputs.serviceWorker }} | |
dependencies: ${{ steps.filter.outputs.dependencies }} | |
public: ${{ steps.filter.outputs.public }} | |
deployOption: ${{ steps.filter.outputs.deployOption }} | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: dorny/paths-filter@v2 | |
id: filter | |
with: | |
base: dev | |
list-files: 'csv' | |
filters: | | |
CD: | |
- '.github/workflows/CD_dev.yml' | |
images: | |
- added|modified: 'app/res/img/**' | |
server: | |
- 'server/**' | |
replServer: | |
- 'replServer/**' | |
app: | |
- 'app/**' | |
serviceWorker: | |
- 'serviceWorker/**' | |
dependencies: | |
- 'package.json' | |
public: | |
- 'public/**' | |
deployOption: | |
- '.deploy' | |
buildApp: | |
runs-on: ubuntu-latest | |
needs: [detectChanges] | |
timeout-minutes: 15 | |
steps: | |
- name: "checkout" | |
if: ${{ (needs.detectChanges.outputs.app == 'true') || (needs.detectChanges.outputs.dependencies == 'true') || (needs.detectChanges.outputs.CD == 'true') }} | |
uses: actions/checkout@master | |
- name: Setting up node | |
if: ${{ (needs.detectChanges.outputs.app == 'true') || (needs.detectChanges.outputs.dependencies == 'true') || (needs.detectChanges.outputs.CD == 'true') }} | |
uses: actions/setup-node@master | |
with: | |
node-version: '20.x' | |
- name: Setting up bun | |
if: ${{ (needs.detectChanges.outputs.app == 'true') || (needs.detectChanges.outputs.dependencies == 'true') || (needs.detectChanges.outputs.CD == 'true') }} | |
uses: oven-sh/setup-bun@v1 | |
- name: Installing runner dependencies | |
if: ${{ (needs.detectChanges.outputs.app == 'true') || (needs.detectChanges.outputs.dependencies == 'true') || (needs.detectChanges.outputs.CD == 'true') }} | |
run: npx -y pnpm i | |
# - name: set environment variables | |
# uses: allenevans/[email protected] | |
# with: | |
# GOOGLE_MAPS_API_KEY: '${{ secrets.MAPS_API_KEY }}' | |
- name: "Building app" | |
if: ${{ (needs.detectChanges.outputs.app == 'true') || (needs.detectChanges.outputs.dependencies == 'true') || (needs.detectChanges.outputs.CD == 'true') }} | |
run: npm run buildProdApp --if-present | |
- name: "Uploading files to remote" | |
if: ${{ (needs.detectChanges.outputs.app == 'true') || (needs.detectChanges.outputs.dependencies == 'true') || (needs.detectChanges.outputs.CD == 'true') }} | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USERNAME }} | |
key: ${{ secrets.KEY }} | |
passphrase: ${{ secrets.PASSPHRASE }} | |
source: "public/dist" | |
target: /var/www/html/lbAnmeldung/dev/_${{github.sha}} | |
overwrite: true | |
buildServer: | |
runs-on: ubuntu-latest | |
needs: [detectChanges] | |
timeout-minutes: 15 | |
steps: | |
- name: "checkout" | |
if: ${{ needs.detectChanges.outputs.server == 'true' || needs.detectChanges.outputs.dependencies == 'true' || (needs.detectChanges.outputs.CD == 'true') }} | |
uses: actions/checkout@master | |
- name: Setting up node | |
if: ${{ needs.detectChanges.outputs.server == 'true' || needs.detectChanges.outputs.dependencies == 'true' || (needs.detectChanges.outputs.CD == 'true') }} | |
uses: actions/setup-node@master | |
with: | |
node-version: '20.x' | |
- name: Installing runner dependencies | |
if: ${{ needs.detectChanges.outputs.server == 'true' || needs.detectChanges.outputs.dependencies == 'true' || (needs.detectChanges.outputs.CD == 'true') }} | |
run: npx -y pnpm i | |
# - name: set environment variables | |
# uses: allenevans/[email protected] | |
# with: | |
# GOOGLE_MAPS_API_KEY: '${{ secrets.MAPS_API_KEY }}' | |
- name: set env vars | |
uses: SpicyPizza/[email protected] | |
with: | |
envkey_PUSHSAFER_KEY: '${{ secrets.PUSHSAFER_KEY }}' | |
envkey_TGM_USERNAME: '${{ secrets.TGM_USERNAME }}' | |
envkey_TGM_PASSWORD: '${{ secrets.TGM_PASSWORD }}' | |
- name: "Building server" | |
if: ${{ needs.detectChanges.outputs.server == 'true' || needs.detectChanges.outputs.dependencies == 'true' || (needs.detectChanges.outputs.CD == 'true') }} | |
run: npm run buildProdServer --if-present | |
- name: "Uploading files to remote" | |
if: ${{ needs.detectChanges.outputs.server == 'true' || needs.detectChanges.outputs.dependencies == 'true' || (needs.detectChanges.outputs.CD == 'true') }} | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USERNAME }} | |
key: ${{ secrets.KEY }} | |
passphrase: ${{ secrets.PASSPHRASE }} | |
source: "server" | |
target: /var/www/html/lbAnmeldung/dev/_${{github.sha}} | |
overwrite: true | |
buildReplServer: | |
runs-on: ubuntu-latest | |
needs: [detectChanges] | |
timeout-minutes: 15 | |
steps: | |
- name: "checkout" | |
if: ${{ needs.detectChanges.outputs.replServer == 'true' || needs.detectChanges.outputs.dependencies == 'true' || (needs.detectChanges.outputs.CD == 'true') }} | |
uses: actions/checkout@master | |
- name: Setting up node | |
if: ${{ needs.detectChanges.outputs.replServer == 'true' || needs.detectChanges.outputs.dependencies == 'true' || (needs.detectChanges.outputs.CD == 'true') }} | |
uses: actions/setup-node@master | |
with: | |
node-version: '20.x' | |
- name: Installing runner dependencies | |
if: ${{ needs.detectChanges.outputs.replServer == 'true' || needs.detectChanges.outputs.dependencies == 'true' || (needs.detectChanges.outputs.CD == 'true') }} | |
run: npx -y pnpm i | |
# - name: set environment variables | |
# uses: allenevans/[email protected] | |
# with: | |
# GOOGLE_MAPS_API_KEY: '${{ secrets.MAPS_API_KEY }}' | |
- name: "Building repl server" | |
if: ${{ needs.detectChanges.outputs.replServer == 'true' || needs.detectChanges.outputs.dependencies == 'true' || (needs.detectChanges.outputs.CD == 'true') }} | |
run: npm run buildProdReplServer --if-present | |
- name: "Uploading files to remote" | |
if: ${{ needs.detectChanges.outputs.replServer == 'true' || needs.detectChanges.outputs.dependencies == 'true' || (needs.detectChanges.outputs.CD == 'true') }} | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USERNAME }} | |
key: ${{ secrets.KEY }} | |
passphrase: ${{ secrets.PASSPHRASE }} | |
source: "replServer" | |
target: /var/www/html/lbAnmeldung/dev/_${{github.sha}} | |
overwrite: true | |
buildServiceWorker: | |
runs-on: ubuntu-latest | |
needs: [detectChanges] | |
timeout-minutes: 15 | |
steps: | |
- name: "checkout" | |
if: ${{ needs.detectChanges.outputs.serviceWorker == 'true' || needs.detectChanges.outputs.dependencies == 'true' || (needs.detectChanges.outputs.CD == 'true') }} | |
uses: actions/checkout@master | |
- name: Setting up node | |
if: ${{ needs.detectChanges.outputs.serviceWorker == 'true' || needs.detectChanges.outputs.dependencies == 'true' || (needs.detectChanges.outputs.CD == 'true') }} | |
uses: actions/setup-node@master | |
with: | |
node-version: '20.x' | |
- name: Installing runner dependencies | |
if: ${{ needs.detectChanges.outputs.serviceWorker == 'true' || needs.detectChanges.outputs.dependencies == 'true' || (needs.detectChanges.outputs.CD == 'true') }} | |
run: npx -y pnpm i | |
# - name: set environment variables | |
# uses: allenevans/[email protected] | |
# with: | |
# GOOGLE_MAPS_API_KEY: '${{ secrets.MAPS_API_KEY }}' | |
- name: "Building service worker" | |
if: ${{ needs.detectChanges.outputs.serviceWorker == 'true' || (needs.detectChanges.outputs.CD == 'true') }} | |
run: npm run buildProdSw --if-present | |
- name: "Uploading files to remote" | |
if: ${{ needs.detectChanges.outputs.serviceWorker == 'true' || (needs.detectChanges.outputs.CD == 'true') }} | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USERNAME }} | |
key: ${{ secrets.KEY }} | |
# todo service worker dist | |
passphrase: ${{ secrets.PASSPHRASE }} | |
source: "public/sw.js" | |
target: /var/www/html/lbAnmeldung/dev/_${{github.sha}} | |
overwrite: true | |
compressImages: | |
runs-on: ubuntu-latest | |
needs: [detectChanges] | |
timeout-minutes: 100 | |
steps: | |
- name: "checkout" | |
if: ${{ needs.detectChanges.outputs.images == 'true' || (needs.detectChanges.outputs.CD == 'true') }} | |
uses: actions/checkout@master | |
with: | |
lfs: "true" | |
- name: Setting up node | |
if: ${{ needs.detectChanges.outputs.images == 'true' || (needs.detectChanges.outputs.CD == 'true') }} | |
uses: actions/setup-node@master | |
with: | |
node-version: '20.x' | |
- name: Installing runner dependencies | |
if: ${{ needs.detectChanges.outputs.images == 'true' || (needs.detectChanges.outputs.CD == 'true') }} | |
run: npm i image-web -g | |
- name: Setting environment variables | |
if: ${{ needs.detectChanges.outputs.images == 'true' || (needs.detectChanges.outputs.CD == 'true') }} | |
uses: allenevans/[email protected] | |
with: | |
UV_THREADPOOL_SIZE: '1' # otherwise may take up too much memory and cause action to be canceled. | |
- name: Debug log | |
run: "echo eval `node -e \"let a = JSON.parse(fs.readFileSync('package.json').toString()).scripts.compressImages.split(' '); let i = a.indexOf('image-web'); assert(i !== -1); assert(a[0] === 'image-web' || (a[0] === 'npx' && (a[1] === 'image-web' || ((a[1] === '--yes' || a[1] === '-y') && a[2] === 'image-web')))); let inp = require('process').argv[1]; if (inp !== undefined && inp !== '') a[i + 1] = inp; console.log(a.join(' ') + (a.includes('--legacyLogs') ? '' : ' --legacyLogs'));\" \"${{ needs.detectChanges.outputs.imagesFiles }}\"`" | |
- name: "Compressing images" | |
if: ${{ needs.detectChanges.outputs.images == 'true' || (needs.detectChanges.outputs.CD == 'true') }} | |
# replace the input of the compressImage command (hopefully using image-web) with the image diffs of this commit. Also add legacyLogs option | |
run: "eval `node -e \"let a = JSON.parse(fs.readFileSync('package.json').toString()).scripts.compressImages.split(' '); let i = a.indexOf('image-web'); assert(i !== -1); assert(a[0] === 'image-web' || (a[0] === 'npx' && (a[1] === 'image-web' || ((a[1] === '--yes' || a[1] === '-y') && a[2] === 'image-web')))); let inp = require('process').argv[1]; if (inp !== undefined && inp !== '') a[i + 1] = inp; console.log(a.join(' ') + (a.includes('--legacyLogs') ? '' : ' --legacyLogs'));\" \"${{ needs.detectChanges.outputs.imagesFiles }}\"`" | |
- name: "Uploading files to remote" | |
if: ${{ needs.detectChanges.outputs.images == 'true' || (needs.detectChanges.outputs.CD == 'true') }} | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USERNAME }} | |
key: ${{ secrets.KEY }} | |
passphrase: ${{ secrets.PASSPHRASE }} | |
source: "public/res/img/dist" | |
target: /var/www/html/lbAnmeldung/dev/_${{github.sha}} | |
overwrite: true | |
uploadPublicAssets: | |
runs-on: ubuntu-latest | |
needs: [detectChanges] | |
timeout-minutes: 15 | |
steps: | |
- name: "checkout" | |
if: ${{ needs.detectChanges.outputs.public == 'true' || (needs.detectChanges.outputs.CD == 'true') }} | |
uses: actions/checkout@master | |
- name: Upload public files | |
if: ${{ needs.detectChanges.outputs.public == 'true' || (needs.detectChanges.outputs.CD == 'true') }} | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USERNAME }} | |
key: ${{ secrets.KEY }} | |
passphrase: ${{ secrets.PASSPHRASE }} | |
source: "public" | |
target: /var/www/html/lbAnmeldung/dev/_${{github.sha}} | |
overwrite: true | |
dependencies: | |
runs-on: ubuntu-latest | |
needs: [detectChanges] | |
timeout-minutes: 15 | |
steps: | |
- name: "checkout" | |
if: ${{ needs.detectChanges.outputs.dependencies == 'true' || (needs.detectChanges.outputs.CD == 'true') }} | |
uses: actions/checkout@master | |
- name: Upload dependency declaration | |
if: ${{ needs.detectChanges.outputs.dependencies == 'true' || (needs.detectChanges.outputs.CD == 'true') }} | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USERNAME }} | |
key: ${{ secrets.KEY }} | |
passphrase: ${{ secrets.PASSPHRASE }} | |
source: "package.json" | |
target: /var/www/html/lbAnmeldung/dev | |
overwrite: true | |
- name: Installing dependencies on remote | |
if: ${{ needs.detectChanges.outputs.dependencies == 'true' || (needs.detectChanges.outputs.CD == 'true') }} | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USERNAME }} | |
key: ${{ secrets.KEY }} | |
passphrase: ${{ secrets.PASSPHRASE }} | |
script: | | |
cd /var/www/html/lbAnmeldung/dev | |
source ~/.nvm/nvm.sh | |
nvm use default | |
npx -y pnpm update | |
deploy: | |
runs-on: ubuntu-latest | |
needs: [detectChanges, buildApp, buildServer, buildReplServer, buildServiceWorker, compressImages, uploadPublicAssets, dependencies] | |
if: always() | |
timeout-minutes: 15 | |
steps: | |
- name: "checkout" | |
if: ${{ needs.detectChanges.outputs.deployOption == 'true' }} | |
uses: actions/checkout@master | |
- name: Upload deploy option files | |
if: ${{ needs.detectChanges.outputs.deployOption == 'true' }} | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USERNAME }} | |
key: ${{ secrets.KEY }} | |
passphrase: ${{ secrets.PASSPHRASE }} | |
source: ".deploy" | |
target: /var/www/html/lbAnmeldung/dev | |
overwrite: true | |
- name: Moving files from temp storage | |
if: ${{ (needs.detectChanges.outputs.dependencies == 'true') || (needs.detectChanges.outputs.images == 'true') || (needs.detectChanges.outputs.server == 'true') || (needs.detectChanges.outputs.replServer == 'true') || (needs.detectChanges.outputs.app == 'true') || (needs.detectChanges.outputs.serviceWorker == 'true') || (needs.detectChanges.outputs.public == 'true') || (needs.detectChanges.outputs.CD == 'true') }} | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USERNAME }} | |
key: ${{ secrets.KEY }} | |
passphrase: ${{ secrets.PASSPHRASE }} | |
# https://unix.stackexchange.com/a/182155/431792 | |
script: | | |
cp -rlf /var/www/html/lbAnmeldung/dev/_${{github.sha}}/* /var/www/html/lbAnmeldung/dev | |
rm -r /var/www/html/lbAnmeldung/dev/_${{github.sha}} | |
- name: Restarting server | |
if: ${{ (needs.detectChanges.outputs.deployOption == 'true') || (needs.detectChanges.outputs.server == 'true') || (needs.detectChanges.outputs.replServer == 'true') || (needs.detectChanges.outputs.dependencies == 'true') || (needs.detectChanges.outputs.CD == 'true') }} | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USERNAME }} | |
key: ${{ secrets.KEY }} | |
passphrase: ${{ secrets.PASSPHRASE }} | |
script: | | |
cd /var/www/html/lbAnmeldung/dev | |
source ~/.nvm/nvm.sh | |
nvm use default | |
npx wait-on ecosystem.config.js | |
node pm2Reload.js |