Skip to content

Manual Update Server #8

Manual Update Server

Manual Update Server #8

name: Manual Update Server
on:
workflow_dispatch:
inputs:
server:
description: 'Server to set as active'
required: true
type: choice
options:
- 'zimbor.go.ro:8985'
- 'srvalx.duckdns.org:8983'
- 'peviitor.go.ro'
default: 'peviitor.go.ro'
jobs:
manual-update:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install GitHub CLI
run: |
sudo apt-get update
sudo apt-get install gh -y
- name: Update Configuration File Manually
run: |
CONFIG_FILE="v3/config.php"
BACKUP_FILE="$CONFIG_FILE.bak"
manual_server="${{ github.event.inputs.server }}"
cp $CONFIG_FILE $BACKUP_FILE
# Escape single quotes and other special characters in the server name
escaped_manual_server=$(echo "$manual_server" | sed "s/[']/\\\\'/g")
# Comment out all existing server lines
sed -i -e 's/^\s*\$server = /\/\/\$server = /' $CONFIG_FILE
# Uncomment the line for the manual server
sed -i "s/\/\/\$server = '$escaped_manual_server';/\$server = '$escaped_manual_server';/" $CONFIG_FILE
git checkout -b update-server-${{ github.sha }}
git config --global user.name "github-actions"
git config --global user.email "github-actions@github.com"
git add $CONFIG_FILE
git commit -m "Manually updated server to $manual_server"
- name: Fetch and Rebase
run: |
git fetch origin
git rebase origin/master || { echo 'Rebase failed'; exit 1; }
- name: Push changes and create PR
run: |
unset GH_TOKEN
git push origin update-server-${{ github.sha }}
echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token
gh pr create --title "Update server to $manual_server" --body "This PR updates the server configuration." --head update-server-${{ github.sha }} --base master
- name: Approve PR
env:
PAT_TOKEN: ${{ secrets.PAT_TOKEN }}
run: |
echo "${{ secrets.PAT_TOKEN }}" | gh auth login --with-token
PR_NUMBER=$(gh pr list --head update-server-${{ github.sha }} --json number --jq '.[0].number')
gh pr review $PR_NUMBER --approve
- name: Merge PR
run: |
unset GH_TOKEN
echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token
PR_NUMBER=$(gh pr list --head update-server-${{ github.sha }} --json number --jq '.[0].number')
gh pr merge $PR_NUMBER --squash --delete-branch