|
| 1 | + |
| 2 | +name: ∆ src-data |
| 3 | +description: Sync JSON and @context changes from src-data to production, applying relevant updates. |
| 4 | +permissions: |
| 5 | + contents: write |
| 6 | + pages: write |
| 7 | + actions: write |
| 8 | + id-token: write |
| 9 | +on: |
| 10 | + push: |
| 11 | + branches: |
| 12 | + - "src-data" |
| 13 | + # Temporarily remove path restrictions to test if that's the issue |
| 14 | + paths: |
| 15 | + - '**/*.json' |
| 16 | + - '**/_context' |
| 17 | + workflow_dispatch: |
| 18 | + inputs: |
| 19 | + debug: |
| 20 | + description: 'Enable debug output' |
| 21 | + required: false |
| 22 | + default: 'false' |
| 23 | + type: boolean |
| 24 | +jobs: |
| 25 | + sync: |
| 26 | + runs-on: ubuntu-latest |
| 27 | + steps: |
| 28 | + - name: Debug trigger information |
| 29 | + run: | |
| 30 | + echo "🔍 Workflow triggered!" |
| 31 | + echo "Event: ${{ github.event_name }}" |
| 32 | + echo "Ref: ${{ github.ref }}" |
| 33 | + echo "Branch: ${{ github.ref_name }}" |
| 34 | + echo "Repository: ${{ github.repository }}" |
| 35 | + echo "Commit SHA: ${{ github.sha }}" |
| 36 | + echo "Actor: ${{ github.actor }}" |
| 37 | + |
| 38 | + if [[ "${{ github.event_name }}" == "push" ]]; then |
| 39 | + echo "=== Push event details ===" |
| 40 | + echo "Before: ${{ github.event.before }}" |
| 41 | + echo "After: ${{ github.event.after }}" |
| 42 | + echo "Forced: ${{ github.event.forced }}" |
| 43 | + echo "Compare URL: ${{ github.event.compare }}" |
| 44 | + fi |
| 45 | + |
| 46 | + - name: Checkout production branch |
| 47 | + uses: actions/checkout@v4 |
| 48 | + with: |
| 49 | + ref: production |
| 50 | + fetch-depth: 0 |
| 51 | + persist-credentials: true |
| 52 | + - name: Clean production except docs and summaries |
| 53 | + run: | |
| 54 | + echo "=== Before cleaning ===" |
| 55 | + ls -la || true |
| 56 | + |
| 57 | + # Enable extended globbing |
| 58 | + shopt -s extglob dotglob |
| 59 | + |
| 60 | + # Show what will be removed |
| 61 | + echo ">>> Files that will be removed (everything except docs, summaries, .git, .github):" |
| 62 | + ls -A | awk '{ |
| 63 | + if ($0 != "docs" && $0 != "summaries" && $0 != ".git" && $0 != ".github") print $0 |
| 64 | + }' || true |
| 65 | + |
| 66 | + # Remove files (but keep docs, summaries, .git, .github) |
| 67 | + rm -rf -- !(docs|summaries|.git|.github) || true |
| 68 | + |
| 69 | + echo "=== After cleaning ===" |
| 70 | + ls -la || true |
| 71 | + - name: Restore path from src-data branch |
| 72 | + uses: WCRP-CMIP/CMIPLD/actions/fetch_branch_path@main |
| 73 | + with: |
| 74 | + branch: "src-data" |
| 75 | + path: . |
| 76 | + remove: false |
| 77 | + - name: Verify restore operation and analyze differences |
| 78 | + run: | |
| 79 | + echo "=== Files after restore ===" |
| 80 | + ls -la || true |
| 81 | + |
| 82 | + echo "=== Git status after restore ===" |
| 83 | + git status --porcelain || true |
| 84 | + |
| 85 | + echo "=== Comparing with src-data branch ===" |
| 86 | + git fetch origin src-data |
| 87 | + |
| 88 | + echo "=== Files different between current state and src-data ===" |
| 89 | + git diff --name-only HEAD origin/src-data || true |
| 90 | + |
| 91 | + echo "=== Detailed diff summary ===" |
| 92 | + git diff --stat HEAD origin/src-data || true |
| 93 | + |
| 94 | + echo "=== Check if working directory has uncommitted changes ===" |
| 95 | + git status --untracked-files=all || true |
| 96 | + |
| 97 | + echo "=== Force add all files including untracked ===" |
| 98 | + git add -A |
| 99 | + echo "=== Check staged changes ===" |
| 100 | + git diff --cached --name-status || true |
| 101 | + - name: Debug — show git status and changed files |
| 102 | + run: | |
| 103 | + git config --global --add safe.directory "$GITHUB_WORKSPACE" || true |
| 104 | + echo "=== git status (porcelain) ===" |
| 105 | + git status --porcelain --untracked-files=all || true |
| 106 | + echo "=== changed files ===" |
| 107 | + git --no-pager diff --name-only || true |
| 108 | + echo "=== ls workspace ===" |
| 109 | + ls -la || true |
| 110 | + - name: Check for changes |
| 111 | + id: check_changes |
| 112 | + run: | |
| 113 | + # Set git config for the runner |
| 114 | + git config user.name "cmip-ipo" |
| 115 | + git config user.email "[email protected]" |
| 116 | + |
| 117 | + # Ensure we're comparing against the right state |
| 118 | + echo "=== Current branch and HEAD ===" |
| 119 | + git branch -v |
| 120 | + git log --oneline -1 |
| 121 | + |
| 122 | + # Check what files exist and their status |
| 123 | + echo "=== All files in workspace ===" |
| 124 | + find . -type f -not -path './.git/*' | sort || true |
| 125 | + |
| 126 | + # Reset any previous staging |
| 127 | + git reset HEAD -- . || true |
| 128 | + |
| 129 | + # Add all files to staging (including untracked) |
| 130 | + git add -A |
| 131 | + |
| 132 | + # Show what's staged |
| 133 | + echo "=== Staged changes ===" |
| 134 | + git diff --cached --name-status || true |
| 135 | + |
| 136 | + # Also check for any differences against origin/src-data |
| 137 | + echo "=== Differences against src-data branch ===" |
| 138 | + git fetch origin src-data || true |
| 139 | + git diff --name-only HEAD origin/src-data || true |
| 140 | + |
| 141 | + # Check if there are any staged changes |
| 142 | + if git diff --cached --quiet; then |
| 143 | + echo "no_changes=true" >> $GITHUB_OUTPUT |
| 144 | + echo "✅ No staged changes detected" |
| 145 | + |
| 146 | + # But let's also check if there are differences against src-data |
| 147 | + if git diff --quiet HEAD origin/src-data; then |
| 148 | + echo "✅ Production and src-data are identical - this is expected" |
| 149 | + else |
| 150 | + echo "⚠️ Files differ from src-data but not staged - potential issue with custom action" |
| 151 | + # Force stage the differences |
| 152 | + git checkout origin/src-data -- . || true |
| 153 | + git add -A |
| 154 | + if ! git diff --cached --quiet; then |
| 155 | + echo "🔄 Forced staging worked - changes now detected" |
| 156 | + echo "no_changes=false" >> $GITHUB_OUTPUT |
| 157 | + fi |
| 158 | + fi |
| 159 | + else |
| 160 | + echo "no_changes=false" >> $GITHUB_OUTPUT |
| 161 | + echo "🔄 Changes detected — will commit." |
| 162 | + echo "=== Summary of changes ===" |
| 163 | + git diff --cached --stat || true |
| 164 | + fi |
| 165 | + - name: Commit and Push Changes |
| 166 | + if: steps.check_changes.outputs.no_changes == 'false' |
| 167 | + uses: EndBug/add-and-commit@v9 |
| 168 | + with: |
| 169 | + add: '.' |
| 170 | + author_name: 'cmip-ipo' |
| 171 | + |
| 172 | + message: 'Clean file upload from src-data' |
| 173 | + branch: production |
| 174 | + push: true |
| 175 | + |
| 176 | + graph: |
| 177 | + uses: WCRP-CMIP/CMIPLD/.github/workflows/graph.yml@main |
| 178 | + needs: sync |
| 179 | + with: |
| 180 | + updated: false |
| 181 | + |
| 182 | + |
| 183 | + publish-pages: |
| 184 | + if: always() # Run even if graph job fails |
| 185 | + needs: |
| 186 | + - graph |
| 187 | + uses: WCRP-CMIP/CMIPLD/.github/workflows/pages.yml@main |
| 188 | + with: |
| 189 | + branch: production |
| 190 | + force: true |
| 191 | + secrets: |
| 192 | + token: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments