modifed action #53
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Run create-plugma on multiple OS | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
branches: [main] | |
workflow_dispatch: # Allows manual triggering | |
jobs: | |
test-cli: | |
strategy: | |
matrix: | |
os: [ubuntu-latest, windows-latest] # Test on Ubuntu and Windows | |
runs-on: ${{ matrix.os }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '18' | |
- name: Install create-plugma locally | |
run: | | |
npm install create-plugma@latest | |
- name: Install execa | |
run: npm install execa | |
- name: Write simulate-cli.js | |
run: | | |
echo "const { spawn } = require('child_process');" > simulate-cli.js | |
echo "(async () => {" >> simulate-cli.js | |
echo " try {" >> simulate-cli.js | |
echo " const cli = spawn('npx', ['create-plugma@latest'], { stdio: ['pipe', 'pipe', 'pipe'], shell: true });" >> simulate-cli.js | |
echo " const promptResponses = [" >> simulate-cli.js | |
echo " { prompt: 'Select a framework:', response: '\\n' }," >> simulate-cli.js | |
echo " { prompt: 'Select a variant:', response: '\\n' }," >> simulate-cli.js | |
echo " { prompt: 'Project name:', response: 'TestProject\\n' }," >> simulate-cli.js | |
echo " { prompt: 'Next:', response: '\\n' }," >> simulate-cli.js | |
echo " ];" >> simulate-cli.js | |
echo " let currentPrompt = 0;" >> simulate-cli.js | |
echo " cli.stdout.on('data', function (data) {" >> simulate-cli.js | |
echo " const output = data.toString();" >> simulate-cli.js | |
echo " console.log('STDOUT: ' + output);" >> simulate-cli.js | |
echo " if (currentPrompt < promptResponses.length) {" >> simulate-cli.js | |
echo " const { prompt, response } = promptResponses[currentPrompt];" >> simulate-cli.js | |
echo " if (output.includes(prompt)) {" >> simulate-cli.js | |
echo " console.log('Sending response: ' + response.trim() || '<Enter>');" >> simulate-cli.js | |
echo " cli.stdin.write(response);" >> simulate-cli.js | |
echo " currentPrompt++;" >> simulate-cli.js | |
echo " }" >> simulate-cli.js | |
echo " } else {" >> simulate-cli.js | |
echo " console.log('Unrecognized output: ' + output);" >> simulate-cli.js | |
echo " }" >> simulate-cli.js | |
echo " });" >> simulate-cli.js | |
echo " cli.stderr.on('data', function (data) { console.error('STDERR: ' + data.toString()); });" >> simulate-cli.js | |
echo " cli.on('close', function (code) {" >> simulate-cli.js | |
echo " console.log('CLI process exited with code: ' + code);" >> simulate-cli.js | |
echo " if (code !== 0) { process.exit(1); }" >> simulate-cli.js | |
echo " });" >> simulate-cli.js | |
echo " cli.on('error', function (error) {" >> simulate-cli.js | |
echo " console.error('Error spawning the process: ' + error);" >> simulate-cli.js | |
echo " process.exit(1);" >> simulate-cli.js | |
echo " });" >> simulate-cli.js | |
echo " } catch (error) {" >> simulate-cli.js | |
echo " console.error('Error running create-plugma CLI: ' + error);" >> simulate-cli.js | |
echo " process.exit(1);" >> simulate-cli.js | |
echo " }" >> simulate-cli.js | |
echo "})();" >> simulate-cli.js | |
- name: Run simulate-cli.js | |
run: node simulate-cli.js | |
- name: Verify TestProject directory | |
run: | | |
if [ -d "TestProject" ]; then | |
echo "TestProject directory exists."; | |
else | |
echo "TestProject directory not found."; | |
exit 1; | |
fi | |
- name: Display package.json contents | |
run: | | |
echo "Contents of package.json:" | |
cat package.json || echo "Failed to read package.json" | |
working-directory: TestProject | |
- name: Install project dependencies | |
run: | | |
npm install | |
working-directory: TestProject | |
- name: Build the project | |
run: | | |
npm run build | |
working-directory: TestProject | |
- name: Verify Build | |
run: | | |
test -f dist/main.js && echo "Build succeeded" || (echo "Build failed" && exit 1) | |
working-directory: TestProject |