|
| 1 | +# $KYAULabs: deploy.yml,v 1.1.0 2024/07/22 01:12:20 -0700 kyau Exp $ |
| 2 | + |
| 3 | +name: "🌌 Hexforged CI" |
| 4 | + |
| 5 | +on: |
| 6 | + push: |
| 7 | + branches: ["main", "develop"] |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +jobs: |
| 11 | + deploy: |
| 12 | + name: Deploy 🚀 |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + # https://github.com/marketplace/actions/checkout |
| 16 | + - name: Checkout 💾 |
| 17 | + uses: actions/checkout@v4 |
| 18 | + with: |
| 19 | + fetch-depth: 0 |
| 20 | + submodules: true |
| 21 | + |
| 22 | + # create CSS directory |
| 23 | + - name: Create CSS Directory 🚧 |
| 24 | + run: mkdir -vp hexforged_com/cdn/css |
| 25 | + |
| 26 | + # https://github.com/marketplace/actions/sass-build |
| 27 | + - name: Compile Sass 👷 |
| 28 | + uses: gha-utilities/[email protected] |
| 29 | + with: |
| 30 | + source: hexforged_com/cdn/sass/hexforged.sass |
| 31 | + destination: hexforged_com/cdn/css/hexforged.css |
| 32 | + |
| 33 | + # https://github.com/marketplace/actions/release-downloader |
| 34 | + - name: Download jQuery Release 💾 |
| 35 | + |
| 36 | + with: |
| 37 | + repository: "tdewolff/minify" |
| 38 | + latest: true |
| 39 | + fileName: "minify_linux_amd64.tar.gz" |
| 40 | + out-file-path: "/tmp/downloads" |
| 41 | + extract: true |
| 42 | + |
| 43 | + - name: Minify CSS/JS 📦️ |
| 44 | + run: | |
| 45 | + chmod a+x /tmp/downloads/minify |
| 46 | + for file in hexforged_com/cdn/css/*.css; do |
| 47 | + if [ -f "$file" ]; then |
| 48 | + /tmp/downloads/minify $file -o ${file%.css}.min.css |
| 49 | + rm $file |
| 50 | + fi |
| 51 | + done |
| 52 | + for file in hexforged_com/cdn/javascript/*.js; do |
| 53 | + if [ -f "$file" ]; then |
| 54 | + /tmp/downloads/minify $file -o ${file%.js}.min.js |
| 55 | + rm $file |
| 56 | + fi |
| 57 | + done |
| 58 | +
|
| 59 | + # https://github.com/marketplace/actions/release-downloader |
| 60 | + - name: Download jQuery Release 💾 |
| 61 | + |
| 62 | + with: |
| 63 | + repository: "jquery/jquery" |
| 64 | + latest: true |
| 65 | + tarBall: true |
| 66 | + zipBall: false |
| 67 | + out-file-path: "/tmp/downloads" |
| 68 | + extract: true |
| 69 | + |
| 70 | + # https://github.com/marketplace/actions/release-downloader |
| 71 | + - name: Download Font Awesome Release 💾 |
| 72 | + |
| 73 | + with: |
| 74 | + repository: "FortAwesome/Font-Awesome" |
| 75 | + latest: true |
| 76 | + fileName: "fontawesome-free-*-web.zip" |
| 77 | + out-file-path: "/tmp/downloads" |
| 78 | + extract: true |
| 79 | + |
| 80 | + - name: Copy jQuery & FontAwesome 🔗 |
| 81 | + run: | |
| 82 | + cp /tmp/downloads/fontawesome-free-*-web/css/all.min.css hexforged_com/cdn/css/ |
| 83 | + cp /tmp/downloads/fontawesome-free-*-web/css/fontawesome.min.css hexforged_com/cdn/css/ |
| 84 | + sed -i 's|\.\./webfonts/|\.\./fonts/|g' hexforged_com/cdn/css/all.min.css |
| 85 | + cp /tmp/downloads/jquery-jquery-*/dist/jquery.min.js hexforged_com/cdn/javascript/ |
| 86 | + cp /tmp/downloads/jquery-jquery-*/dist/jquery.min.map hexforged_com/cdn/javascript/ |
| 87 | +
|
| 88 | + # subresource integrity |
| 89 | + - name: Subresource Integrity 🔒️ |
| 90 | + id: subresource |
| 91 | + run: | |
| 92 | + for file in hexforged_com/cdn/css/*.min.css; do |
| 93 | + if [ -f "$file" ]; then |
| 94 | + shasum -b -a 512 ${file} | awk '{ print $1 }' | xxd -r -p | base64 | tr -d '\n' > ${file}.sha512 |
| 95 | + fi |
| 96 | + done |
| 97 | + for file in hexforged_com/cdn/javascript/*.min.js; do |
| 98 | + if [ -f "$file" ]; then |
| 99 | + shasum -b -a 512 ${file} | awk '{ print $1 }' | xxd -r -p | base64 | tr -d '\n' > ${file}.sha512 |
| 100 | + fi |
| 101 | + done |
| 102 | +
|
| 103 | + # create dotenv |
| 104 | + - name: Create DotENV 🔐 |
| 105 | + id: dotenv |
| 106 | + run: | |
| 107 | + echo -e "<?php\n" > .env |
| 108 | + echo -e "define(\"GOOGLE_PUBLIC\", \"${{ secrets.GOOGLE_PUBLIC }}\");" >> .env |
| 109 | + echo -e "define(\"GOOGLE_SECRET\", \"${{ secrets.GOOGLE_SECRET }}\");" >> .env |
| 110 | + echo -e "define(\"SQL_USER\", \"${{ secrets.SQL_USER }}\");" >> .env |
| 111 | + echo -e "define(\"SQL_PASSWD\", \"${{ secrets.SQL_PASSWD }}\");" >> .env |
| 112 | + - name: Detect Production Environment 🎬 |
| 113 | + if: github.ref == 'refs/heads/main' |
| 114 | + run: | |
| 115 | + echo -e "define(\"CDN_HOST\", \"cdn.hexforged.com\");" >> .env |
| 116 | + echo -e "define(\"ENVIRONMENT\", \"production\");" >> .env |
| 117 | + - name: Detect Development Environment ⚗️ |
| 118 | + if: github.ref == 'refs/heads/develop' |
| 119 | + run: | |
| 120 | + echo -e "define(\"CDN_HOST\", \"cdn.dev.hexforged.com\");" >> .env |
| 121 | + echo -e "define(\"ENVIRONMENT\", \"development\");" >> .env |
| 122 | +
|
| 123 | + # https://github.com/marketplace/actions/rsync-deployments-action |
| 124 | + - name: Rsync to Production 🚀 |
| 125 | + if: github.ref == 'refs/heads/main' |
| 126 | + |
| 127 | + with: |
| 128 | + switches: -avzr --exclude=".git" --exclude="aurora/.git" |
| 129 | + remote_path: ${{ secrets.TARGET }} |
| 130 | + remote_host: ${{ secrets.SSH_HOST }} |
| 131 | + remote_user: ${{ secrets.SSH_USER }} |
| 132 | + remote_key: ${{ secrets.SSH_KEY }} |
| 133 | + remote_key_pass: ${{ secrets.SSH_PASSWD }} |
| 134 | + remote_port: ${{ secrets.SSH_PORT }} |
| 135 | + |
| 136 | + # https://github.com/marketplace/actions/rsync-deployments-action |
| 137 | + - name: Rsync to Development 🚀 |
| 138 | + if: github.ref == 'refs/heads/develop' |
| 139 | + |
| 140 | + with: |
| 141 | + switches: -avzr --exclude=".git" --exclude="aurora/.git" |
| 142 | + remote_path: ${{ secrets.TARGET }} |
| 143 | + remote_host: ${{ secrets.SSH_HOST_DEV }} |
| 144 | + remote_user: ${{ secrets.SSH_USER }} |
| 145 | + remote_key: ${{ secrets.SSH_KEY }} |
| 146 | + remote_key_pass: ${{ secrets.SSH_PASSWD }} |
| 147 | + remote_port: ${{ secrets.SSH_PORT }} |
| 148 | + |
| 149 | + # https://github.com/marketplace/actions/ssh-remote-commands |
| 150 | + - name: Confirm Permissions 🔑 |
| 151 | + |
| 152 | + with: |
| 153 | + host: ${{ secrets.SSH_HOST_DEV }} |
| 154 | + username: ${{ secrets.SSH_USER }} |
| 155 | + key: ${{ secrets.SSH_KEY }} |
| 156 | + passphrase: ${{ secrets.SSH_PASSWD }} |
| 157 | + port: ${{ secrets.SSH_PORT }} |
| 158 | + script: | |
| 159 | + find ${{ secrets.TARGET }} -type d -exec chmod 2770 {} \; |
| 160 | + find ${{ secrets.TARGET }} -type f -exec chmod 660 {} \; |
| 161 | +
|
| 162 | + # https://github.com/marketplace/actions/ssh-remote-commands |
| 163 | + - name: Reset the Development Database 🗃️ |
| 164 | + if: github.ref == 'refs/heads/develop' |
| 165 | + |
| 166 | + with: |
| 167 | + host: ${{ secrets.SSH_HOST_DEV }} |
| 168 | + username: ${{ secrets.SSH_USER }} |
| 169 | + key: ${{ secrets.SSH_KEY }} |
| 170 | + passphrase: ${{ secrets.SSH_PASSWD }} |
| 171 | + port: ${{ secrets.SSH_PORT }} |
| 172 | + script: | |
| 173 | + mariadb -u ${{ secrets.SQL_USER }} -e 'DROP DATABASE hexforged' |
| 174 | + mariadb -u ${{ secrets.SQL_USER }} < ${{ secrets.TARGET }}/hexforged_com/backend/hexforged.sql |
0 commit comments