Skip to content

Merge pull request #7 from feat/kyau-95b4-phpdoc #6

Merge pull request #7 from feat/kyau-95b4-phpdoc

Merge pull request #7 from feat/kyau-95b4-phpdoc #6

Workflow file for this run

# $KYAULabs: deploy.yml,v 1.1.2 2024/07/31 00:24:43 -0700 kyau Exp $
name: "Hexforged CI 🌌"
on:
push:
branches: ["main", "develop"]
workflow_dispatch:
jobs:
deploy:
name: Deploy 🚀
runs-on: ubuntu-latest
steps:
# https://github.com/marketplace/actions/checkout
- name: Checkout `hexforged/web` 💾
uses: actions/checkout@v4
with:
fetch-depth: 0
path: "root"
sparse-checkout: |
aurora
error
hexforged_com
submodules: true
# https://github.com/marketplace/actions/checkout
- name: Checkout `hexforged/media` 💾
uses: actions/checkout@v4
with:
repository: "hexforged/media"
fetch-depth: 0
path: "media"
sparse-checkout: |
fonts
images
token: ${{ secrets.TOKEN_MEDIA }}
# copy the media repository
- name: Copy Media 🔗
run: |
mkdir -vp root/hexforged_com/cdn/css root/hexforged_com/cdn/fonts root/hexforged_com/cdn/images
cp -r media/fonts/* root/hexforged_com/cdn/fonts/
cp -r media/images/* root/hexforged_com/cdn/images/
cd root/hexforged_com/www
ln -s ../cdn/images/[email protected] favicon.png
ln -s ../cdn/images/[email protected] og-image.png
# https://github.com/marketplace/actions/sass-build
- name: Compile Sass 👷
uses: gha-utilities/[email protected]
with:
source: root/hexforged_com/cdn/sass/hexforged.sass
destination: root/hexforged_com/cdn/css/hexforged.css
# https://github.com/marketplace/actions/release-downloader
- name: Download jQuery Release 💾
uses: robinraju/[email protected]
with:
repository: "tdewolff/minify"
latest: true
fileName: "minify_linux_amd64.tar.gz"
out-file-path: "/tmp/downloads"
extract: true
- name: Minify CSS/JS 📦️
run: |
chmod a+x /tmp/downloads/minify
for file in root/hexforged_com/cdn/css/*.css; do
if [ -f "$file" ]; then
/tmp/downloads/minify $file -o ${file%.css}.min.css
rm $file
fi
done
for file in root/hexforged_com/cdn/javascript/*.js; do
if [ -f "$file" ]; then
/tmp/downloads/minify $file -o ${file%.js}.min.js
rm $file
fi
done
# https://github.com/marketplace/actions/release-downloader
- name: Download jQuery Release 💾
uses: robinraju/[email protected]
with:
repository: "jquery/jquery"
latest: true
tarBall: true
zipBall: false
out-file-path: "/tmp/downloads"
extract: true
# https://github.com/marketplace/actions/release-downloader
- name: Download Font Awesome Release 💾
uses: robinraju/[email protected]
with:
repository: "FortAwesome/Font-Awesome"
latest: true
fileName: "fontawesome-free-*-web.zip"
out-file-path: "/tmp/downloads"
extract: true
- name: Copy jQuery & FontAwesome 🔗
run: |
cp /tmp/downloads/fontawesome-free-*-web/css/all.min.css root/hexforged_com/cdn/css/
cp /tmp/downloads/fontawesome-free-*-web/css/fontawesome.min.css root/hexforged_com/cdn/css/
cp /tmp/downloads/fontawesome-free-*-web/webfonts/* root/hexforged_com/cdn/fonts/
sed -i 's|\.\./webfonts/|\.\./fonts/|g' root/hexforged_com/cdn/css/all.min.css
cp /tmp/downloads/jquery-jquery-*/dist/jquery.min.js root/hexforged_com/cdn/javascript/
cp /tmp/downloads/jquery-jquery-*/dist/jquery.min.map root/hexforged_com/cdn/javascript/
curl -L https://github.com/blobject/agave/releases/latest/download/Agave-Regular.ttf --output root/hexforged_com/cdn/fonts/Agave-Regular.ttf
curl -L https://github.com/blobject/agave/releases/latest/download/Agave-Bold.ttf --output root/hexforged_com/cdn/fonts/Agave-Bold.ttf
# subresource integrity
- name: Subresource Integrity 🔒️
id: subresource
run: |
for file in root/hexforged_com/cdn/css/*.min.css; do
if [ -f "$file" ]; then
shasum -b -a 512 ${file} | awk '{ print $1 }' | xxd -r -p | base64 | tr -d '\n' > ${file}.sha512
fi
done
for file in root/hexforged_com/cdn/javascript/*.min.js; do
if [ -f "$file" ]; then
shasum -b -a 512 ${file} | awk '{ print $1 }' | xxd -r -p | base64 | tr -d '\n' > ${file}.sha512
fi
done
# create dotenv
- name: Create DotENV 🔐
id: dotenv
run: |
echo -e "<?php\n" > root/.env
echo -e "define(\"GOOGLE_PUBLIC\", \"${{ secrets.GOOGLE_PUBLIC }}\");" >> root/.env
echo -e "define(\"GOOGLE_SECRET\", \"${{ secrets.GOOGLE_SECRET }}\");" >> root/.env
echo -e "define(\"SQL_USER\", \"${{ secrets.SQL_USER }}\");" >> root/.env
echo -e "define(\"SQL_PASSWD\", \"${{ secrets.SQL_PASSWD }}\");" >> root/.env
echo -e "define(\"PASSWD_PEPPER\", \"${{ secrets.PASSWD_PEPPER }}\");" >> root/.env
echo -e "define(\"SESSION_NAME\", \"${{ secrets.SESSION_NAME }}\");" >> root/.env
echo -e "define(\"SESSION_KEY\", \"${{ secrets.SESSION_KEY }}\");" >> root/.env
- name: Detect Production Environment 🎬
if: github.ref == 'refs/heads/main'
run: |
echo -e "define(\"CDN_HOST\", \"cdn.hexforged.com\");" >> root/.env
echo -e "define(\"ENVIRONMENT\", \"production\");" >> root/.env
- name: Detect Development Environment ⚗️
if: github.ref == 'refs/heads/develop'
run: |
echo -e "define(\"CDN_HOST\", \"cdn.dev.hexforged.com\");" >> root/.env
echo -e "define(\"ENVIRONMENT\", \"development\");" >> root/.env
# repo cleanup
- name: Cleanup Directory 🗑️
run: |
rm -rf root/.gitignore root/.gitleaksignore root/.gitmodules root/aurora/.gitignore
rm -rf root/*.md root/*.toml root/commitlint.config.js
rm -rf root/aurora/*.md root/aurora/*.toml root/aurora/commitlint.config.js
rm -rf root/aurora/settings.example.php root/aurora/.github
# https://github.com/marketplace/actions/rsync-deployments-action
- name: Rsync to Production 🚀
if: github.ref == 'refs/heads/main'
uses: burnett01/[email protected]
with:
path: root/
switches: -lrtvz --delete-excluded --exclude=".git" --exclude="aurora/.git" --specials
remote_path: ${{ secrets.TARGET }}
remote_host: ${{ secrets.SSH_HOST }}
remote_user: ${{ secrets.SSH_USER }}
remote_key: ${{ secrets.SSH_KEY }}
remote_key_pass: ${{ secrets.SSH_PASSWD }}
remote_port: ${{ secrets.SSH_PORT }}
# https://github.com/marketplace/actions/rsync-deployments-action
- name: Rsync to Development 🚀
if: github.ref == 'refs/heads/develop'
uses: burnett01/[email protected]
with:
path: root/
switches: -lrtvz --delete-excluded --exclude=".git" --exclude="aurora/.git" --specials
remote_path: ${{ secrets.TARGET }}
remote_host: ${{ secrets.SSH_HOST_DEV }}
remote_user: ${{ secrets.SSH_USER }}
remote_key: ${{ secrets.SSH_KEY }}
remote_key_pass: ${{ secrets.SSH_PASSWD }}
remote_port: ${{ secrets.SSH_PORT }}
# https://github.com/marketplace/actions/ssh-remote-commands
- name: Confirm Permissions 🔑
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST_DEV }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_KEY }}
passphrase: ${{ secrets.SSH_PASSWD }}
port: ${{ secrets.SSH_PORT }}
script: |
find ${{ secrets.TARGET }} -type d -exec chmod 2770 {} \;
find ${{ secrets.TARGET }} -type f -exec chmod 660 {} \;
# https://github.com/marketplace/actions/ssh-remote-commands
- name: Reset the Development Database 🗃️
if: github.ref == 'refs/heads/develop'
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST_DEV }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_KEY }}
passphrase: ${{ secrets.SSH_PASSWD }}
port: ${{ secrets.SSH_PORT }}
script: |
mariadb -u ${{ secrets.SQL_USER }} -e 'DROP DATABASE hexforged'
mariadb -u ${{ secrets.SQL_USER }} < ${{ secrets.TARGET }}/hexforged_com/backend/hexforged.sql