|
| 1 | +name: Validate Workspace Configuration |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main ] |
| 6 | + pull_request: |
| 7 | + branches: [ main ] |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +jobs: |
| 11 | + validate-repositories-consistency: |
| 12 | + name: Validate Repositories Consistency |
| 13 | + runs-on: ubuntu-latest |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Checkout code |
| 17 | + uses: actions/checkout@v4 |
| 18 | + |
| 19 | + - name: Extract repositories from init.sh |
| 20 | + id: extract-repos |
| 21 | + run: | |
| 22 | + # Extract repository names from the repositories array in init.sh |
| 23 | + # The array format is: "url" "name" pairs, we need the names (odd indices) |
| 24 | + REPOS=$(grep -A 20 'declare -a repositories=(' init.sh | \ |
| 25 | + grep -E '^\s*"[^"]*"\s*"[^"]*"' | \ |
| 26 | + sed -E 's/.*"[^"]*"\s*"([^"]*)".*/\1/' | \ |
| 27 | + sort) |
| 28 | + |
| 29 | + echo "repositories<<EOF" >> $GITHUB_OUTPUT |
| 30 | + echo "$REPOS" >> $GITHUB_OUTPUT |
| 31 | + echo "EOF" >> $GITHUB_OUTPUT |
| 32 | + |
| 33 | + echo "Found repositories:" |
| 34 | + echo "$REPOS" |
| 35 | + |
| 36 | + - name: Extract folders from workspace file |
| 37 | + id: extract-folders |
| 38 | + run: | |
| 39 | + # Extract folder paths from the workspace file and convert to just the folder names |
| 40 | + FOLDERS=$(grep -E '^\s*"path":\s*"apps/[^"]*"' opencollective-workspace.code-workspace | \ |
| 41 | + sed -E 's/.*"path":\s*"apps\/([^"]*)".*/\1/' | \ |
| 42 | + sort) |
| 43 | + |
| 44 | + echo "folders<<EOF" >> $GITHUB_OUTPUT |
| 45 | + echo "$FOLDERS" >> $GITHUB_OUTPUT |
| 46 | + echo "EOF" >> $GITHUB_OUTPUT |
| 47 | + |
| 48 | + echo "Found folders:" |
| 49 | + echo "$FOLDERS" |
| 50 | + |
| 51 | + - name: Compare repositories and folders |
| 52 | + run: | |
| 53 | + # Create temporary files for comparison |
| 54 | + echo "${{ steps.extract-repos.outputs.repositories }}" > /tmp/repos.txt |
| 55 | + echo "${{ steps.extract-folders.outputs.folders }}" > /tmp/folders.txt |
| 56 | + |
| 57 | + echo "=== Repositories from init.sh ===" |
| 58 | + cat /tmp/repos.txt |
| 59 | + |
| 60 | + echo "" |
| 61 | + echo "=== Folders from workspace ===" |
| 62 | + cat /tmp/folders.txt |
| 63 | + |
| 64 | + echo "" |
| 65 | + echo "=== Checking for missing repositories in workspace ===" |
| 66 | + MISSING_IN_WORKSPACE=$(comm -23 /tmp/repos.txt /tmp/folders.txt) |
| 67 | + if [ -n "$MISSING_IN_WORKSPACE" ]; then |
| 68 | + echo "❌ Repositories missing from workspace:" |
| 69 | + echo "$MISSING_IN_WORKSPACE" |
| 70 | + exit 1 |
| 71 | + else |
| 72 | + echo "✅ All repositories from init.sh are present in workspace" |
| 73 | + fi |
| 74 | + |
| 75 | + echo "" |
| 76 | + echo "=== Checking for extra folders in workspace ===" |
| 77 | + EXTRA_IN_WORKSPACE=$(comm -13 /tmp/repos.txt /tmp/folders.txt) |
| 78 | + if [ -n "$EXTRA_IN_WORKSPACE" ]; then |
| 79 | + echo "⚠️ Extra folders in workspace (not in init.sh):" |
| 80 | + echo "$EXTRA_IN_WORKSPACE" |
| 81 | + echo "This might be intentional, but please verify." |
| 82 | + else |
| 83 | + echo "✅ No extra folders found in workspace" |
| 84 | + fi |
| 85 | + |
| 86 | + echo "" |
| 87 | + echo "=== Summary ===" |
| 88 | + echo "✅ Repository consistency check passed!" |
| 89 | +
|
| 90 | + test-init-script: |
| 91 | + name: Test Init Script |
| 92 | + runs-on: ubuntu-latest |
| 93 | + |
| 94 | + steps: |
| 95 | + - name: Checkout code |
| 96 | + uses: actions/checkout@v4 |
| 97 | + |
| 98 | + - name: Test init.sh script |
| 99 | + run: ./init.sh --shallow |
| 100 | + |
| 101 | + - name: Verify apps directory structure |
| 102 | + run: | |
| 103 | + echo "=== Apps directory contents ===" |
| 104 | + ls -la apps/ |
| 105 | + |
| 106 | + echo "" |
| 107 | + echo "=== Expected repositories ===" |
| 108 | + # List the expected repository names from init.sh |
| 109 | + grep -A 20 'declare -a repositories=(' init.sh | \ |
| 110 | + grep -E '^\s*"[^"]*"\s*"[^"]*"' | \ |
| 111 | + sed -E 's/.*"[^"]*"\s*"([^"]*)".*/\1/' | \ |
| 112 | + while read repo; do |
| 113 | + if [ -d "apps/$repo" ]; then |
| 114 | + echo "✅ apps/$repo exists" |
| 115 | + else |
| 116 | + echo "❌ apps/$repo missing" |
| 117 | + exit 1 |
| 118 | + fi |
| 119 | + done |
| 120 | + |
| 121 | + echo "" |
| 122 | + echo "✅ All expected repositories were created!" |
0 commit comments