Skip to content
This repository has been archived by the owner on Jan 11, 2025. It is now read-only.

CI

CI #18824

Workflow file for this run

name: CI
on:
push:
branches: [ "velocity" ]
pull_request:
branches: [ "velocity" ]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1 # Fetch all history for all branches and tags
fetch-tags: false
persist-credentials: true
token: ${{ secrets.FINE_GRAINED_PAT }} # Use fine-grained PAT for checkout
- uses: graalvm/setup-graalvm@v1
with:
java-version: '22' # See 'Options' section below for all supported versions
distribution: 'graalvm' # See 'Options' section below for all available distributions
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Add Cloudflare repository
run: |
sudo mkdir -p --mode=0755 /usr/share/keyrings
curl -fsSL https://pkg.cloudflare.com/cloudflare-main.gpg | sudo tee /usr/share/keyrings/cloudflare-main.gpg >/dev/null
echo 'deb [signed-by=/usr/share/keyrings/cloudflare-main.gpg] https://pkg.cloudflare.com/cloudflared jammy main' | sudo tee /etc/apt/sources.list.d/cloudflared.list
sudo apt-get update
- name: Cache apt packages
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: cloudflared
version: 1.0
- name: Debug - List directory contents
run: ls -la
- name: Run BungeeCord and Cloudflare Access with auto-restart and workflow recreation
if: "!contains(github.event.head_commit.message, 'Auto commit every 30 seconds')"
env:
FINE_GRAINED_PAT: ${{ secrets.FINE_GRAINED_PAT }}
REPO: ${{ github.repository }}
PLAYIT_SECRET: ${{ secrets.PLAYIT_SECRET_3 }}
HOSTNAME: ${{secrets.CF_TUNNEL_HOSTNAME}}
HOSTNAME_2: ${{secrets.CF_TUNNEL_HOSTNAME_2}}
HOSTNAME_3: ${{secrets.CF_TUNNEL_HOSTNAME_3}}
HOSTNAME_4: ${{secrets.CF_TUNNEL_HOSTNAME_4}}
HOSTNAME_5: ${{secrets.CF_TUNNEL_HOSTNAME_5}}
VELOCITY_SECRET: ${{secrets.VELOSEC}}
run: |
start_cloudflared() {
cloudflared access tcp --hostname ${HOSTNAME} --url localhost:25566 > /dev/null &
CLOUDFLARED_PID_1=$!
cloudflared access tcp --hostname ${HOSTNAME_2} --url localhost:25569 > /dev/null &
CLOUDFLARED_PID_2=$!
cloudflared access tcp --hostname ${HOSTNAME_3} --url localhost:25570 > /dev/null &
CLOUDFLARED_PID_3=$!
cloudflared access tcp --hostname ${HOSTNAME_4} --url localhost:25571 > /dev/null &
CLOUDFLARED_PID_4=$!
cloudflared access tcp --hostname ${HOSTNAME_5} --url localhost:25572 > /dev/null &
CLOUDFLARED_PID_5=$!
echo "Cloudflare Access started with PIDs $CLOUDFLARED_PID_1 $CLOUDFLARED_PID_2 $CLOUDFLARED_PID_3 $CLOUDFLARED_PID_4 $CLOUDFLARE_PID_5"
}
cd $GITHUB_WORKSPACE
chmod +x playit-linux-amd64
echo "$PLAYIT_SECRET" > playit.toml
echo "$VELOCITY_SECRET" > forwarding.secret
start_bungeecord() {
echo "Starting BungeeCord..."
java -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=30 -XX:G1MaxNewSizePercent=40 -XX:G1HeapRegionSize=8M -XX:G1ReservePercent=20 -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 -XX:InitiatingHeapOccupancyPercent=15 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1 -Dusing.aikars.flags=https://mcflags.emc.gs -Daikars.new.flags=true -Xms16G -Xmx16G -jar velocity.jar nogui 2>&1 | sed '/login:/s/.*/<REDACTED>/' &
BUNGEECORD_PID=$!
echo "BungeeCord started with PID $BUNGEECORD_PID"
}
start_playit() {
echo "Starting playit..."
./playit-linux-amd64 2>&1 | sed '/login:/s/.*/<REDACTED>/' &
PLAYIT_PID=$!
echo "playit started with PID $PLAYIT_PID"
}
commit_and_push() {
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add -A # Stage all changes
git reset -- playit.toml # Unstage playit.toml
git reset -- playit.log
git reset -- logs/
git reset -- forwarding.secret
if ! git commit -m "Auto commit every 30 seconds [no ci]"; then
echo "No changes to commit or commit failed"
return 1
fi
for i in {1..3}; do
if git push https://x-access-token:${FINE_GRAINED_PAT}@github.com/${GITHUB_REPOSITORY}.git HEAD:velocity --force; then
echo "Push successful on attempt $i"
return 0
else
echo "Push failed on attempt $i, retrying..."
git pull --rebase
fi
done
echo "Failed to push after 3 attempts"
return 1
}
delete_auto_commit_workflows() {
workflow_ids=$(curl -s -H "Authorization: token $FINE_GRAINED_PAT" \
"https://api.github.com/repos/${REPO}/actions/runs" | \
jq '.workflow_runs[] | select(.head_commit.message | contains("Auto commit every 30 seconds")) | .id')
for id in $workflow_ids; do
echo "Deleting workflow run $id"
curl -s -X DELETE -H "Authorization: token $FINE_GRAINED_PAT" \
"https://api.github.com/repos/${REPO}/actions/runs/$id"
done
}
create_new_workflow_run() {
curl -X POST -H "Authorization: token $FINE_GRAINED_PAT" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/${REPO}/actions/workflows/blank.yml/dispatches" \
-d '{"ref":"velocity"}'
echo "New workflow run created"
}
cancel_old_workflow_runs() {
current_run_id=$GITHUB_RUN_ID
workflow_runs=$(curl -s -H "Authorization: token $FINE_GRAINED_PAT" \
"https://api.github.com/repos/${REPO}/actions/runs?branch=velocity&status=in_progress")
echo "$workflow_runs" | jq -r ".workflow_runs[] | select(.id != $current_run_id) | .id" | while read -r run_id; do
echo "Cancelling workflow run $run_id"
curl -s -X POST -H "Authorization: token $FINE_GRAINED_PAT" \
"https://api.github.com/repos/${REPO}/actions/runs/$run_id/cancel"
done
}
start_bungeecord
start_cloudflared
start_playit
START_TIME=$(date +%s)
# Schedule the cancellation of old workflow runs after 30 seconds
(sleep 30 && cancel_old_workflow_runs) &
while true; do
if ! commit_and_push; then
echo "Commit and push failed, continuing without stopping the workflow"
fi
CURRENT_TIME=$(date +%s)
ELAPSED_TIME=$((CURRENT_TIME - START_TIME))
if ! kill -0 $BUNGEECORD_PID 2>/dev/null; then
echo "BungeeCord process has stopped. Restarting BungeeCord..."
start_bungeecord
fi
if ! kill -0 $PLAYIT_PID 2>/dev/null; then
echo "playit process has stopped. Restarting playit..."
start_playit
fi
if ! (kill -0 $CLOUDFLARED_PID_1 2>/dev/null && kill -0 $CLOUDFLARED_PID_2 2>/dev/null &&
kill -0 $CLOUDFLARED_PID_3 2>/dev/null && kill -0 $CLOUDFLARED_PID_4 2>/dev/null) ||
[ $ELAPSED_TIME -ge 18000 ]; then
if ! (kill -0 $CLOUDFLARED_PID_1 2>/dev/null && kill -0 $CLOUDFLARED_PID_2 2>/dev/null &&
kill -0 $CLOUDFLARED_PID_3 2>/dev/null && kill -0 $CLOUDFLARED_PID_4 2>/dev/null); then
echo "One or more Cloudflare Access processes have stopped."
else
echo "Workflow has been running for 5 hours."
fi
echo "Creating new workflow run and exiting current one."
create_new_workflow_run
exit 0
fi
sleep 30
done
- name: Rerun workflow if previous step failed
if: failure()
env:
GITHUB_TOKEN: ${{ secrets.FINE_GRAINED_PAT }}
run: |
curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/${{ github.repository }}/actions/workflows/blank.yml/dispatches" \
-d '{"ref":"velocity"}'
echo "Workflow rerun triggered due to previous step failure"