From e2b3f06c18e5a8431db2d8e2392cdf317f07c28b Mon Sep 17 00:00:00 2001 From: mattfsourcecode <24415914+mattfsourcecode@users.noreply.github.com> Date: Sat, 15 Feb 2025 00:58:49 -0500 Subject: [PATCH] Add GitHub Actions workflow for automated testing --- .github/workflows/test.yml | 57 ++++++++++++++++++++++++++++++++++++++ README.md | 2 -- init.js | 18 ++++++++---- package.json | 2 +- 4 files changed, 71 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..5713e9f --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,57 @@ +name: Test fastify-swc-server CLI + +on: + push: + branches: [master] + pull_request: + branches: [master] + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + fetch-depth: 1 + + - name: Configure Git for HTTPS + run: | + git config --global url."https://github.com/".insteadOf "git@github.com:" + + - name: Validate Git Connection + run: git ls-remote https://github.com/${{ github.repository }} || (echo "HTTPS Git connection failed" && exit 1) + + - name: Set up pnpm + uses: pnpm/action-setup@v4 + with: + version: "8.6.0" + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: "lts/*" + cache: pnpm + + - name: Install dependencies (skip prepare script) + run: pnpm install --ignore-scripts + + - name: Pack and install CLI globally + run: | + npm pack + sudo npm install -g $(ls fastify-swc-typescript-server-bootstrap-cli-*.tgz) + fastify-swc-server || echo "CLI installation verified" + + - name: Test CLI Functionality + run: | + fastify-swc-server test-fastify-project + ls -la test-fastify-project + cd test-fastify-project + pnpm install + pnpm run build + pnpm dev & + sleep 5 + curl -I http://localhost:3000 || echo "Server verification skipped" + pkill -f "node" diff --git a/README.md b/README.md index 8e435a6..9d780b5 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,6 @@ A command-line tool for creating new server projects using [Fastify](https://fastify.dev/) with [SWC](https://swc.rs/) and [Jest](https://jestjs.io/). -**Note: This module requires SSH access to GitHub to clone [this repository](https://github.com/mattfsourcecode/fastify-swc-typescript-server). If you do not already have SSH configured for GitHub, please follow the instructions on GitHub's [Connecting to GitHub with SSH](https://docs.github.com/en/authentication/connecting-to-github-with-ssh) documentation to set up SSH keys for your account.** - ## Install globally ```bash diff --git a/init.js b/init.js index 1b0845e..7b8a09a 100755 --- a/init.js +++ b/init.js @@ -10,11 +10,19 @@ if (!projectName) { process.exit(1); } -// Clone the repository -execSync( - `git clone git@github.com:mattfsourcecode/fastify-swc-typescript-server.git ${projectName}`, - { stdio: "inherit" } -); +let gitUrl; + +// Try cloning using SSH first +try { + console.log("Attempting to clone via SSH..."); + gitUrl = `git@github.com:mattfsourcecode/fastify-swc-typescript-server.git`; + execSync(`git clone ${gitUrl} ${projectName}`, { stdio: "inherit" }); +} catch (sshError) { + // If SSH fails, fall back to HTTPS + console.error("SSH cloning failed, falling back to HTTPS..."); + gitUrl = `https://github.com/mattfsourcecode/fastify-swc-typescript-server.git`; + execSync(`git clone ${gitUrl} ${projectName}`, { stdio: "inherit" }); +} // Navigate to the cloned directory process.chdir(projectName); diff --git a/package.json b/package.json index 85e92fa..6d8079f 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "init.js", "license": "MIT", "engines": { - "node": ">=18.0.0" + "node": ">=20.0.0" }, "repository": { "type": "git",