-
Notifications
You must be signed in to change notification settings - Fork 0
124 lines (112 loc) · 4.51 KB
/
Copy pathplatformio.yml
File metadata and controls
124 lines (112 loc) · 4.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
name: Sync platformio
on:
workflow_dispatch: {}
permissions:
contents: write
concurrency:
group: sync-platformio
cancel-in-progress: false
jobs:
sync:
runs-on: ubuntu-latest
steps:
- name: Checkout main (tools live here)
uses: actions/checkout@v4
with: { fetch-depth: 0 }
- uses: astral-sh/setup-uv@v3
- name: Configure git identity
run: |
git config user.name "fbuild-bot[sync]"
git config user.email "fbuild-bot+sync@users.noreply.github.com"
- name: Worktree the platformio branch
run: |
set -euo pipefail
if git ls-remote --heads origin platformio | grep -q .; then
git fetch origin platformio:platformio
git worktree add .data platformio
else
git worktree add --detach .data
(cd .data && git checkout --orphan platformio && git rm -rf . 2>/dev/null || true)
fi
mkdir -p .data/data
- name: Dump upstream JSON to /tmp/pio-dump
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
mkdir -p /tmp/pio-dump
uv run --no-project --script builders/platformio.py --out /tmp/pio-dump
- name: Copy-merge (NEVER replace existing JSON; log conflicts)
id: merge
run: |
# Walk /tmp/pio-dump; for each file, if .data/data/<relpath> exists,
# SKIP and append to the conflicts log. Otherwise copy it.
mkdir -p /tmp
LOG=/tmp/conflicts.log
: > "$LOG"
uv run --no-project --script - <<'PY' "$LOG" "/tmp/pio-dump" "$(pwd)/.data/data"
# /// script
# requires-python = ">=3.10"
# ///
import shutil, sys, pathlib
log_path = pathlib.Path(sys.argv[1])
src = pathlib.Path(sys.argv[2])
dst = pathlib.Path(sys.argv[3])
copied = skipped = 0
with log_path.open("a", encoding="utf-8") as logf:
for p in src.rglob("*"):
if not p.is_file(): continue
rel = p.relative_to(src)
target = dst / rel
if target.exists():
logf.write(f"SKIP existing: {rel}\n")
skipped += 1
continue
target.parent.mkdir(parents=True, exist_ok=True)
shutil.copy2(p, target)
copied += 1
print(f"copied={copied} skipped={skipped} log={log_path}", file=sys.stderr)
PY
echo "log_path=$LOG" >> "$GITHUB_OUTPUT"
- name: Show conflict log in workflow output
if: always()
run: |
echo "=== conflict log (skipped pre-existing files) ==="
cat /tmp/conflicts.log || echo "(no log)"
echo "=== end of conflict log ==="
- name: Upload conflict log as artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: platformio-conflicts-log
path: /tmp/conflicts.log
if-no-files-found: ignore
- name: Force-push as a fresh orphan commit
working-directory: .data
# Each sync replaces the platformio branch with a SINGLE orphan
# commit whose tree contains the cumulative (skip-on-exists)
# working state. No history retained — GH UI no longer reports
# "N commits behind main" growing over time. Cumulative data is
# preserved because the copy-merge step above kept any existing
# files from the prior tip.
run: |
set -euo pipefail
git add -A
TREE=$(git write-tree)
# If the new tree matches the current remote tip's tree, exit silently.
REMOTE_TREE=""
if git ls-remote --exit-code --heads origin platformio >/dev/null 2>&1; then
REMOTE_TREE=$(git rev-parse "origin/platformio^{tree}" 2>/dev/null || true)
fi
if [ -n "$REMOTE_TREE" ] && [ "$TREE" = "$REMOTE_TREE" ]; then
echo "tree unchanged ($TREE); skipping push"
exit 0
fi
ts="$(date -u +%Y-%m-%d)"
NEW=$(git commit-tree "$TREE" -m "sync(platformio): ${ts}" \
-m "from builders/platformio.py via workflow_dispatch")
echo "new orphan: $NEW (tree $TREE)"
if git ls-remote --exit-code --heads origin platformio >/dev/null 2>&1; then
git push --force origin "$NEW:refs/heads/platformio"
else
git push origin "$NEW:refs/heads/platformio"
fi