Skip to content

Commit

Permalink
chore: reorganize CI/CD action and workflow files
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanlinat committed Dec 23, 2024
1 parent 1964231 commit bb5b15c
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 62 deletions.
8 changes: 8 additions & 0 deletions .github/actions/_shared/restart-gaming-server/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
runs:
using: composite
steps:
- name: Setup OpenSSH
uses: ./.github/actions/_shared/setup-openssh
- name: Execute the restart command through OpenSSH
run: ssh -i ~/.ssh/${{ env.VPS_GAMESERVER_OPENSSH_ID }} ${{ env.VPS_GAMESERVER_USERNAME }}@${{ env.VPS_HOSTNAME }} -p 22 "${{ env.VPS_GAMESERVER_BINARY }} restart"
shell: bash
10 changes: 10 additions & 0 deletions .github/actions/_shared/setup-openssh/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
runs:
using: composite
steps:
- name: Setup OpenSSH
run: |
mkdir -p ~/.ssh
echo "${{ env.VPS_GAMESERVER_OPENSSH_PRIVATE_KEY }}" > ~/.ssh/${{ env.VPS_GAMESERVER_OPENSSH_ID }}
chmod 600 ~/.ssh/${{ env.VPS_GAMESERVER_OPENSSH_ID }}
ssh-keyscan ${{ env.VPS_HOSTNAME }} >> ~/.ssh/known_hosts
shell: bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
runs:
using: composite
steps:
- name: Setup OpenSSH
uses: ./.github/actions/_shared/setup-openssh
- name: Generate the 'mapcycle.txt' file
run: ls dodserver/serverfiles/dod/maps/*.bsp | awk -F'/' '{ print $(NF) }' | sed 's/\.bsp$//' | shuf > dodserver/serverfiles/dod/mapcycle.txt
shell: bash
- name: "LinuxGSM: Set random default map and max players"
run: |
DEFAULT_MAP=$(shuf -n 1 dodserver/serverfiles/dod/mapcycle.txt)
export VPS_GAMESERVER_CONFIG_DEFAULT_MAP="$DEFAULT_MAP"
export VPS_GAMESERVER_CONFIG_MAX_PLAYERS="${{ env.VPS_GAMESERVER_CONFIG_MAX_PLAYERS }}"
envsubst '$VPS_GAMESERVER_CONFIG_DEFAULT_MAP,$VPS_GAMESERVER_CONFIG_MAX_PLAYERS' < dodserver/lgsm/config-lgsm/dodserver/dodserver.cfg.template > dodserver/lgsm/config-lgsm/dodserver/dodserver.cfg
rm -f dodserver/lgsm/config-lgsm/dodserver/dodserver.cfg.template
shell: bash
- name: "Server configuration: Set hostname, RCON password, and download URL"
run: |
export VPS_GAMESERVER_CONFIG_HOSTNAME="${{ env.VPS_GAMESERVER_CONFIG_HOSTNAME }}"
export VPS_GAMESERVER_CONFIG_RCON_PASSWORD="${{ env.VPS_GAMESERVER_CONFIG_RCON_PASSWORD }}"
export VPS_GAMESERVER_CONFIG_DOWNLOAD_URL="${{ env.VPS_GAMESERVER_CONFIG_DOWNLOAD_URL }}"
envsubst '$VPS_GAMESERVER_CONFIG_HOSTNAME,$VPS_GAMESERVER_CONFIG_RCON_PASSWORD,$VPS_GAMESERVER_CONFIG_DOWNLOAD_URL' < dodserver/serverfiles/dod/dodserver.cfg.template > dodserver/serverfiles/dod/dodserver.cfg
rm -f dodserver/serverfiles/dod/dodserver.cfg.template
shell: bash
- name: "MOTD: Set meta title"
run: |
export VPS_GAMESERVER_CONFIG_HOSTNAME="${{ env.VPS_GAMESERVER_CONFIG_HOSTNAME }}"
envsubst '$VPS_GAMESERVER_CONFIG_HOSTNAME' < dodserver/serverfiles/dod/motd.html.template > dodserver/serverfiles/dod/motd.html
rm -f dodserver/serverfiles/dod/motd.html.template
shell: bash
- name: "AMX Mod X: Set admin and moderator users"
run: |
export VPS_GAMESERVER_CONFIG_AMX_ADMINS="${{ env.VPS_GAMESERVER_CONFIG_AMX_ADMINS }}"
envsubst '$VPS_GAMESERVER_CONFIG_AMX_ADMINS' < dodserver/serverfiles/dod/addons/amxmodx/configs/users.ini.template > dodserver/serverfiles/dod/addons/amxmodx/configs/users.ini
rm -f dodserver/serverfiles/dod/addons/amxmodx/configs/users.ini.template
shell: bash
- name: Set execute permissions for the gaming server files
run: find dodserver/serverfiles/dod -type f -exec chmod 755 {} \;
shell: bash
- name: Synchronize the gaming server files
run: rsync -e "ssh -i ~/.ssh/${{ env.VPS_GAMESERVER_OPENSSH_ID }}" -avvzP --delete --exclude='.*' ${{ env.VPS_GAMESERVER_RSYNC_SOURCE_PATH }} ${{ env.VPS_GAMESERVER_USERNAME }}@${{ env.VPS_HOSTNAME }}:${{ env.VPS_GAMESERVER_RSYNC_DEST_PATH }}
shell: bash
13 changes: 0 additions & 13 deletions .github/actions/restart-gaming-server/action.yml

This file was deleted.

66 changes: 19 additions & 47 deletions .github/workflows/continuous-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,34 @@ name: Continuous Deployment
on:
push:
branches: [main]
env:
VPS_GAMESERVER_BINARY: ${{ secrets.VPS_GAMESERVER_BINARY }}
VPS_GAMESERVER_CONFIG_AMX_ADMINS: ${{ vars.VPS_GAMESERVER_CONFIG_AMX_ADMINS }}
VPS_GAMESERVER_CONFIG_DOWNLOAD_URL: ${{ vars.VPS_GAMESERVER_CONFIG_DOWNLOAD_URL }}
VPS_GAMESERVER_CONFIG_HOSTNAME: ${{ vars.VPS_GAMESERVER_CONFIG_HOSTNAME }}
VPS_GAMESERVER_CONFIG_MAX_PLAYERS: ${{ vars.VPS_GAMESERVER_CONFIG_MAX_PLAYERS }}
VPS_GAMESERVER_CONFIG_RCON_PASSWORD: ${{ secrets.VPS_GAMESERVER_CONFIG_RCON_PASSWORD }}
VPS_GAMESERVER_OPENSSH_ID: ${{ secrets.VPS_GAMESERVER_OPENSSH_ID }}
VPS_GAMESERVER_OPENSSH_PRIVATE_KEY: ${{ secrets.VPS_GAMESERVER_OPENSSH_PRIVATE_KEY }}
VPS_GAMESERVER_RSYNC_DEST_PATH: ${{ secrets.VPS_GAMESERVER_RSYNC_DEST_PATH }}
VPS_GAMESERVER_RSYNC_SOURCE_PATH: ${{ secrets.VPS_GAMESERVER_RSYNC_SOURCE_PATH }}
VPS_GAMESERVER_USERNAME: ${{ secrets.VPS_GAMESERVER_USERNAME }}
VPS_HOSTNAME: ${{ secrets.VPS_HOSTNAME }}
jobs:
sync-gaming-server-files:
deploy-gaming-server-files:
name: Deploy the gaming server files
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup OpenSSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.VPS_GAMESERVER_OPENSSH_PRIVATE_KEY }}" > ~/.ssh/${{ secrets.VPS_GAMESERVER_OPENSSH_ID }}
chmod 600 ~/.ssh/${{ secrets.VPS_GAMESERVER_OPENSSH_ID }}
ssh-keyscan ${{ secrets.VPS_HOSTNAME }} >> ~/.ssh/known_hosts
shell: bash
- name: Generate the 'mapcycle.txt' file
run: ls dodserver/serverfiles/dod/maps/*.bsp | awk -F'/' '{ print $(NF) }' | sed 's/\.bsp$//' | shuf > dodserver/serverfiles/dod/mapcycle.txt
shell: bash
- name: "LinuxGSM: Set random default map and max players"
run: |
DEFAULT_MAP=$(shuf -n 1 dodserver/serverfiles/dod/mapcycle.txt)
export VPS_GAMESERVER_CONFIG_DEFAULT_MAP="$DEFAULT_MAP"
export VPS_GAMESERVER_CONFIG_MAX_PLAYERS="${{ vars.VPS_GAMESERVER_CONFIG_MAX_PLAYERS }}"
envsubst '$VPS_GAMESERVER_CONFIG_DEFAULT_MAP,$VPS_GAMESERVER_CONFIG_MAX_PLAYERS' < dodserver/lgsm/config-lgsm/dodserver/dodserver.cfg.template > dodserver/lgsm/config-lgsm/dodserver/dodserver.cfg
rm -f dodserver/lgsm/config-lgsm/dodserver/dodserver.cfg.template
shell: bash
- name: "Server configuration: Set hostname, RCON password, and download URL"
run: |
export VPS_GAMESERVER_CONFIG_HOSTNAME="${{ vars.VPS_GAMESERVER_CONFIG_HOSTNAME }}"
export VPS_GAMESERVER_CONFIG_RCON_PASSWORD="${{ secrets.VPS_GAMESERVER_CONFIG_RCON_PASSWORD }}"
export VPS_GAMESERVER_CONFIG_DOWNLOAD_URL="${{ vars.VPS_GAMESERVER_CONFIG_DOWNLOAD_URL }}"
envsubst '$VPS_GAMESERVER_CONFIG_HOSTNAME,$VPS_GAMESERVER_CONFIG_RCON_PASSWORD,$VPS_GAMESERVER_CONFIG_DOWNLOAD_URL' < dodserver/serverfiles/dod/dodserver.cfg.template > dodserver/serverfiles/dod/dodserver.cfg
rm -f dodserver/serverfiles/dod/dodserver.cfg.template
shell: bash
- name: "MOTD: Set meta title"
run: |
export VPS_GAMESERVER_CONFIG_HOSTNAME="${{ vars.VPS_GAMESERVER_CONFIG_HOSTNAME }}"
envsubst '$VPS_GAMESERVER_CONFIG_HOSTNAME' < dodserver/serverfiles/dod/motd.html.template > dodserver/serverfiles/dod/motd.html
rm -f dodserver/serverfiles/dod/motd.html.template
shell: bash
- name: "AMX Mod X: Set admin and moderator users"
run: |
export VPS_GAMESERVER_CONFIG_AMX_ADMINS="${{ vars.VPS_GAMESERVER_CONFIG_AMX_ADMINS }}"
envsubst '$VPS_GAMESERVER_CONFIG_AMX_ADMINS' < dodserver/serverfiles/dod/addons/amxmodx/configs/users.ini.template > dodserver/serverfiles/dod/addons/amxmodx/configs/users.ini
rm -f dodserver/serverfiles/dod/addons/amxmodx/configs/users.ini.template
shell: bash
- name: Set execute permissions for the gaming server files
run: find dodserver/serverfiles/dod -type f -exec chmod 755 {} \;
shell: bash
- name: Synchronize the gaming server files
run: rsync -e "ssh -i ~/.ssh/${{ secrets.VPS_GAMESERVER_OPENSSH_ID }}" -avvzP --delete --exclude='.*' ${{ secrets.VPS_GAMESERVER_RSYNC_SOURCE_PATH }} ${{ secrets.VPS_GAMESERVER_USERNAME }}@${{ secrets.VPS_HOSTNAME }}:${{ secrets.VPS_GAMESERVER_RSYNC_DEST_PATH }}
shell: bash
- name: Deploy the gaming server files
uses: ./.github/actions/continuous-deployment/deploy-gaming-server-files
restart-gaming-server:
name: Restart the gaming server
runs-on: ubuntu-latest
needs: [sync-gaming-server-files]
needs: [deploy-gaming-server-files]
steps:
- name: Checkout code
uses: actions/checkout@v4
- uses: ./.github/actions/restart-gaming-server
- name: Restart the gaming server
uses: ./.github/actions/_shared/restart-gaming-server
11 changes: 9 additions & 2 deletions .github/workflows/continuous-scheduling.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@ name: Continuous Scheduling
on:
schedule:
- cron: 0 9 * * 1
env:
VPS_GAMESERVER_BINARY: ${{ secrets.VPS_GAMESERVER_BINARY }}
VPS_GAMESERVER_OPENSSH_ID: ${{ secrets.VPS_GAMESERVER_OPENSSH_ID }}
VPS_GAMESERVER_OPENSSH_PRIVATE_KEY: ${{ secrets.VPS_GAMESERVER_OPENSSH_PRIVATE_KEY }}
VPS_GAMESERVER_USERNAME: ${{ secrets.VPS_GAMESERVER_USERNAME }}
VPS_HOSTNAME: ${{ secrets.VPS_HOSTNAME }}
jobs:
restart-gaming-server:
name: Periodically restart the gaming server
name: Restart the gaming server
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- uses: ./.github/actions/restart-gaming-server
- name: Restart the gaming server
uses: ./.github/actions/restart-gaming-server

0 comments on commit bb5b15c

Please sign in to comment.