|
| 1 | +name: Test Bootstrapper Script Generator |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + pull_request_target: |
| 8 | + branches: |
| 9 | + - master |
| 10 | + |
| 11 | +jobs: |
| 12 | + test: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + |
| 15 | + steps: |
| 16 | + - uses: actions/checkout@v3 |
| 17 | + |
| 18 | + - name: Set up Node.js 20 |
| 19 | + uses: actions/setup-node@v3 |
| 20 | + with: |
| 21 | + node-version: 20 |
| 22 | + |
| 23 | + - name: Install pnpm |
| 24 | + uses: pnpm/action-setup@v2 |
| 25 | + with: |
| 26 | + version: latest |
| 27 | + |
| 28 | + - name: Install dependencies |
| 29 | + run: pnpm install |
| 30 | + |
| 31 | + - name: Build project |
| 32 | + run: pnpm build |
| 33 | + |
| 34 | + - name: Create test directories |
| 35 | + run: | |
| 36 | + mkdir test-dir |
| 37 | + mkdir -p test-source test-output scripts |
| 38 | + cat > test-source/package.json << 'EOL' |
| 39 | + { |
| 40 | + "name": "test-app", |
| 41 | + "version": "1.0.0", |
| 42 | + "description": "Test app for bootstrapper", |
| 43 | + "main": "index.js", |
| 44 | + "scripts": { |
| 45 | + "test": "echo \"Error: no test specified\" && exit 1" |
| 46 | + } |
| 47 | + } |
| 48 | + EOL |
| 49 | + mkdir test-source/src |
| 50 | + echo 'console.log("Hello World");' > test-source/src/index.js |
| 51 | + echo 'body { margin: 0; }' > test-source/src/styles.css |
| 52 | +
|
| 53 | + - name: Pack and install globally |
| 54 | + run: | |
| 55 | + npm pack |
| 56 | + sudo npm install -g $(ls bootstrapper-script-generator-*.tgz) |
| 57 | +
|
| 58 | + - name: Generate and run bootstrap script |
| 59 | + run: | |
| 60 | + # Generate bootstrap script in scripts directory |
| 61 | + npx make-bootstrapper-script scripts/bootstrap.sh test-source |
| 62 | + chmod +x scripts/bootstrap.sh |
| 63 | +
|
| 64 | + # Execute bootstrap script in test-output directory |
| 65 | + cd test-output |
| 66 | + ../scripts/bootstrap.sh |
| 67 | + cd .. |
| 68 | +
|
| 69 | + - name: Install dos2unix |
| 70 | + run: sudo apt-get update && sudo apt-get install -y dos2unix |
| 71 | + |
| 72 | + - name: Remove trailing blank lines |
| 73 | + run: | |
| 74 | + find test-source test-output -type f -exec sed -i ':a;/^\n*$/{$d;N;};/\n$/ba' {} + |
| 75 | +
|
| 76 | + - name: Compare directories |
| 77 | + run: | |
| 78 | + echo -e "\n=== Directory Comparison ===" |
| 79 | + diff_output=$(diff -r --ignore-all-space --strip-trailing-cr test-source test-output || true) |
| 80 | + if [ -n "$diff_output" ]; then |
| 81 | + echo "Directory comparison failed. Differences found:" |
| 82 | + echo "$diff_output" |
| 83 | + exit 1 |
| 84 | + else |
| 85 | + echo "Directories are identical!" |
| 86 | + fi |
| 87 | +
|
| 88 | + - name: Debug differences |
| 89 | + run: | |
| 90 | + diff -rq test-source test-output | awk '{print $2}' | while read file; do |
| 91 | + echo "=== Debugging $file ===" |
| 92 | + echo "Hex dump of test-source/$file:" |
| 93 | + xxd "test-source/${file#test-source/}" || echo "File not found in test-source: $file" |
| 94 | + echo "Hex dump of test-output/$file:" |
| 95 | + xxd "test-output/${file#test-output/}" || echo "File not found in test-output: $file" |
| 96 | + done |
0 commit comments