From bb8e6b7313270365748b763390e479519ba927a4 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Thu, 12 Dec 2024 17:27:25 +0100 Subject: [PATCH] Actions: add single build deploy --- .github/workflows/deploy_single_theme.yml | 57 +++++++++++++++++++++++ scripts/single_build.sh | 51 +++++--------------- 2 files changed, 68 insertions(+), 40 deletions(-) create mode 100644 .github/workflows/deploy_single_theme.yml diff --git a/.github/workflows/deploy_single_theme.yml b/.github/workflows/deploy_single_theme.yml new file mode 100644 index 000000000..18c807ae5 --- /dev/null +++ b/.github/workflows/deploy_single_theme.yml @@ -0,0 +1,57 @@ +name: Deploy develop on dev.mapcomplete.org +on: + push: + branches: + - build/* + +jobs: + deploy_on_hosted: + runs-on: [ hetzner-access ] + steps: + - uses: actions/checkout@v3 + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: "20" + cache: "npm" + cache-dependency-path: package-lock.json + + - name: install deps + run: npm ci + shell: bash + + - name: create generated dir + run: mkdir ./assets/generated + shell: bash + + - name: create dependencies + run: npm run generate:licenses; npm run generate:images; npm run generate:charging-stations; npm run generate:service-worker; npm run download:editor-layer-index + shell: bash + + - name: sync translations + run: npm run generate:translations + shell: bash + + - name: Prepare build + run: | + BRANCH=${{ github.ref_name }} + THEME=${BRANCH:6} + npm run generate:service-worker && ./scripts/single_build.sh $THEME + shell: bash + + - name: Zipping dist file + run: | + BRANCH=${{ github.ref_name }} + THEME=${BRANCH:6} + mv "dist_$THEME" ${{ github.ref_name }} + zip ${{ github.ref_name }}.zip -r ${{ github.ref_name }}/* + + - name: uploading file + run: scp ${{ github.ref_name }}.zip hetzner:/root/staging/ + + - name: unzipping remote file + run: ssh hetzner "cd /root/staging && unzip ${{ github.ref_name }}.zip && rm -rf /root/single_theme_builds/${{ github.ref_name }} && mv /root/staging/${{ github.ref_name }}/ /root/single_theme_builds/ && rm ${{ github.ref_name }}.zip" + + + diff --git a/scripts/single_build.sh b/scripts/single_build.sh index 49677134b..216d95407 100755 --- a/scripts/single_build.sh +++ b/scripts/single_build.sh @@ -1,16 +1,20 @@ +#! /bin/bash + +# Creates the build for just a single theme +export NODE_OPTIONS="--max-old-space-size=12000" THEME=$1 -npm run generate:layouts if [ $# -eq 0 ] then echo "No arguments given. Expected a themename" fi pwd +npm run generate:layouts if [ -f "$THEME.html" ] then echo "$THEME.html found." else - echo "Theme '$THEME' not found. Did you run 'npm run generate:layouts'?" + echo "Theme '$THEME' not found. Did you run 'npm run generate:layouts'? Is the theme name correct?" exit 1 fi @@ -33,14 +37,10 @@ sed -i "s/input,/input: {index:\".\/index.html\", land: \".\/land.html\"}/" vite sed -i "s/\/\/ LAYOUT.ADD_CONFIG/layout.enableMoreQuests = false/" index_"$THEME".ts - - export NODE_OPTIONS=--max-old-space-size=20000 vite build --sourcemap --config vite_single.config.js || { echo 'Vite build failed' ; exit 1; } - - cp -r assets/layers/ dist/assets/layers/ cp -r assets/themes/ dist/assets/themes/ cp -r assets/svg/ dist/assets/svg/ @@ -92,37 +92,8 @@ fi npm run clean echo "BUILD COMPLETED" - -if [ $# -eq 2 ] -then - echo "DEPLOY TO $2" - - if [ -f "$2"/CNAME ] - then - CNAME=$(cat "$2"/CNAME) - echo "Found a CNAME" - fi - echo "Assuming github pages, add \".nojekyll\"" - touch $2/.nojekyll - echo $CNAME > $2/CNAME - rm -r "$2/assets/*" - echo " ! Don't forget to add `https://$CNAME/land.html` to the Redirect URIs on https://www.openstreetmap.org/oauth2/applications/" - cp -r "dist_$THEME/"* "$2"/ - - if [ -d "$2"/.git ] - then - cd $2 - git add * - git commit -m "Add new version of MapComplete with single-page build of $THEME" - git push - cd - - fi - rm -r "dist_$THEME" -else - echo "BUILD COMPLETED" - echo "On what domain will you deploy?" - echo " ! Don't forget to add `https://yourdomain.tld/land.html` to the Redirect URIs on https://www.openstreetmap.org/oauth2/applications/" - echo "Deploying on github pages?" - echo " 1. Don't forget to add a CNAME file (containing your domain name verbatim, without protocol)" - echo " 2 .nojekyll file (which is empty)" -fi +echo "On what domain will you deploy?" +echo " ! Don't forget to add `https://yourdomain.tld/land.html` to the Redirect URIs on https://www.openstreetmap.org/oauth2/applications/" +echo "Deploying on github pages?" +echo " 1. Don't forget to add a CNAME file (containing your domain name verbatim, without protocol)" +echo " 2 .nojekyll file (which is empty)"