Skip to content

Add GitHub Actions workflow for automated testing (#15) #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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 "[email protected]:"

- 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"
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 13 additions & 5 deletions init.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,19 @@ if (!projectName) {
process.exit(1);
}

// Clone the repository
execSync(
`git clone [email protected]: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 = `[email protected]: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);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "init.js",
"license": "MIT",
"engines": {
"node": ">=18.0.0"
"node": ">=20.0.0"
},
"repository": {
"type": "git",
Expand Down
Loading