name: 'Server Install Action' description: 'Clone Nodarx server repository and install Node.js, PHP, and/or nginx based on test requirements' author: 'Nodarx' branding: icon: 'server' color: 'blue' inputs: server-path: description: 'Path where the server will be cloned/installed' required: false default: './server' install-node: description: 'Install Node.js environment' required: false default: 'false' install-php: description: 'Install PHP environment' required: false default: 'false' install-nginx: description: 'Install nginx web server' required: false default: 'false' install-dependencies: description: 'Whether to install dependencies (npm/composer)' required: false default: 'true' node-version: description: 'Node.js version to use (if install-node is true)' required: false default: '20' package-manager: description: 'Package manager for Node.js (npm, yarn, pnpm)' required: false default: 'npm' php-version: description: 'PHP version to use (if install-php is true)' required: false default: '8.2' php-extensions: description: 'Comma-separated list of PHP extensions to install' required: false default: 'mbstring, xml, ctype, json, curl, zip' web-config: description: 'Path to nginx configuration file (optional)' required: false default: '' build-command: description: 'Custom build command to run after install' required: false default: '' env-file: description: 'Path to environment file to copy (.env)' required: false default: '' post-install-script: description: 'Custom script to run after installation' required: false default: '' outputs: install-status: description: 'Status of the installation (success/failure)' value: ${{ steps.install.outputs.status }} install-path: description: 'Path where the server was installed' value: ${{ steps.install.outputs.path }} node-installed: description: 'Whether Node.js was installed' value: ${{ steps.install.outputs.node_installed }} php-installed: description: 'Whether PHP was installed' value: ${{ steps.install.outputs.php_installed }} nginx-installed: description: 'Whether nginx was installed' value: ${{ steps.install.outputs.nginx_installed }} runs: using: 'composite' steps: - name: Validate inputs shell: bash run: | echo "::group::Validating inputs" # Validate at least one component is enabled if [ "${{ inputs.install-node }}" != "true" ] && \ [ "${{ inputs.install-php }}" != "true" ] && \ [ "${{ inputs.install-nginx }}" != "true" ]; then echo "::error::At least one component must be enabled (install-node, install-php, or install-nginx)" exit 1 fi echo "Server path: ${{ inputs.server-path }}" echo "Components to install:" [ "${{ inputs.install-node }}" == "true" ] && echo " ✓ Node.js ${{ inputs.node-version }} (${{ inputs.package-manager }})" [ "${{ inputs.install-php }}" == "true" ] && echo " ✓ PHP ${{ inputs.php-version }}" [ "${{ inputs.install-nginx }}" == "true" ] && echo " ✓ nginx" echo "Install dependencies: ${{ inputs.install-dependencies }}" echo "::endgroup::" - name: Clone server repository shell: bash run: | echo "::group::Cloning Nodarx server repository" if [ -d "${{ inputs.server-path }}" ]; then echo "Directory exists, pulling latest changes..." cd "${{ inputs.server-path }}" git pull --recurse-submodules || echo "::warning::Pull failed, continuing with existing code" else echo "Cloning repository..." git clone --recurse-submodules --depth 1 https://git.ktrix.dev/Nodarx/server "${{ inputs.server-path }}" fi echo "Repository cloned/updated successfully" echo "::endgroup::" - name: Setup Node.js if: inputs.install-node == 'true' uses: actions/setup-node@v4 with: node-version: ${{ inputs.node-version }} - name: Setup pnpm if: inputs.install-node == 'true' && inputs.package-manager == 'pnpm' uses: pnpm/action-setup@v2 with: version: 8 - name: Setup PHP if: inputs.install-php == 'true' uses: shivammathur/setup-php@v2 with: php-version: ${{ inputs.php-version }} extensions: ${{ inputs.php-extensions }} tools: composer:v2 coverage: none - name: Install nginx if: inputs.install-web-server == 'true' shell: bash run: | echo "::group::Installing nginx" sudo apt-get update -qq sudo apt-get install -y nginx echo "nginx installed successfully" nginx -v echo "::endgroup::" - name: Configure nginx if: inputs.install-web-server == 'true' && inputs.nginx-config != '' shell: bash run: | echo "::group::Configuring nginx" if [ -f "${{ inputs.nginx-config }}" ]; then sudo cp "${{ inputs.nginx-config }}" /etc/nginx/sites-available/default sudo nginx -t sudo systemctl reload nginx echo "nginx configured successfully" else echo "::warning::nginx config file not found: ${{ inputs.nginx-config }}" fi echo "::endgroup::" - name: Start nginx if: inputs.install-web-server == 'true' shell: bash run: | echo "::group::Starting nginx" sudo systemctl start nginx sudo systemctl status nginx --no-pager || true echo "nginx started successfully" echo "::endgroup::" - name: Install Node.js dependencies if: inputs.install-node == 'true' && inputs.install-dependencies == 'true' shell: bash run: | echo "::group::Installing Node.js dependencies" cd "${{ inputs.server-path }}" case "${{ inputs.package-manager }}" in npm) npm ci || npm install ;; yarn) yarn install --frozen-lockfile || yarn install ;; pnpm) pnpm install --frozen-lockfile || pnpm install ;; *) echo "::error::Unsupported package manager: ${{ inputs.package-manager }}" exit 1 ;; esac echo "Node.js dependencies installed successfully" echo "::endgroup::" - name: Install PHP dependencies if: inputs.install-php == 'true' && inputs.install-dependencies == 'true' shell: bash run: | echo "::group::Installing PHP dependencies" cd "${{ inputs.server-path }}" if [ -f "composer.json" ]; then composer install --no-dev --optimize-autoloader echo "PHP dependencies installed successfully" else echo "::warning::composer.json not found, skipping PHP dependency installation" fi echo "::endgroup::" - name: Copy environment file if: inputs.env-file != '' shell: bash run: | echo "::group::Setting up environment file" if [ -f "${{ inputs.env-file }}" ]; then cp "${{ inputs.env-file }}" "${{ inputs.server-path }}/.env" echo "Environment file copied successfully" else echo "::warning::Environment file not found: ${{ inputs.env-file }}" fi echo "::endgroup::" - name: Run build command if: inputs.build-command != '' shell: bash run: | echo "::group::Running build command" cd "${{ inputs.server-path }}" ${{ inputs.build-command }} echo "::endgroup::" - name: Run post-install script if: inputs.post-install-script != '' shell: bash run: | echo "::group::Running post-install script" cd "${{ inputs.server-path }}" chmod +x "${{ inputs.post-install-script }}" "${{ inputs.post-install-script }}" echo "::endgroup::" - name: Set outputs id: install shell: bash run: | echo "status=success" >> $GITHUB_OUTPUT echo "path=${{ inputs.server-path }}" >> $GITHUB_OUTPUT echo "node_installed=${{ inputs.install-node }}" >> $GITHUB_OUTPUT echo "php_installed=${{ inputs.install-php }}" >> $GITHUB_OUTPUT echo "nginx_installed=${{ inputs.install-nginx }}" >> $GITHUB_OUTPUT