rea-ci-tests-audit
MOmorluto/rea485k7,690 new stars in the last 7 days
Sync this Go port with a new upstream google/libphonenumber release — regenerate the embedded metadata and reconcile the ported Java logic. Use when the user says "sync with upstream", "do an upstream sync", "reconcile against libphonenumber", "pull the latest libphonenumber", bump to a new libphonenumber version, or invokes /sync-upstream. SYNC.md holds the state (baseline version + deliberate divergences); this skill is the procedure.
This package is a Go port of google/libphonenumber, tracking its Java reference implementation. A sync has two phases — run them in order:
data/ blobs from a new upstream
release. Fully automated by cmd/buildmetadata.State lives in SYNC.md: the upstream version the port is synced against
and the deliberate divergences (what we intentionally do not port). Read it first. The
generated metadata/version.go (metadata.Version) records the same version — never hand-edit
that.
Run everything from the repo root (/Users/rowan/nyaruka/phonenumbers).
This skill never releases — no tag, no push, no CHANGELOG.md. Releases are cut
separately after reviewing the sync.
go run ./cmd/buildmetadata # latest upstream release
# go run ./cmd/buildmetadata v9.0.32 # or pin a specific tag
This resolves the target tag, wipes and re-clones upstream into _build/ (a shallow
--depth=1 checkout at the target tag — gitignored), rebuilds every embedded blob
(data/, metadata/data/, carrier/data/, geocoding/data/, timezone/data/), and
rewrites the generated metadata/version.go with the tag it built from.
Then:
go test ./...
Review the diff — include untracked files (git status not just git diff), since a new
upstream locale or prefix file produces a new blob. The only files that may change or appear
are the embedded blobs (data/, metadata/data/, carrier/data/, geocoding/data/,
timezone/data/) and the generated metadata/version.go:
Goal: apply any upstream Java logic changes between the old baseline (SYNC.md) and the
target to each Go port. The target is the tag Phase 1 built (from metadata/version.go).
If the baseline already equals the target, there is nothing to reconcile — skip to Finalize.
Phase 1 leaves _build/ as a shallow clone at the target tag. Fetch the baseline tag
into it so you can diff tree-to-tree (no merge base needed — git diff A B compares trees):
BASE=v9.0.31 # from SYNC.md "Synced against"
git -C _build fetch --depth=1 origin tag "$BASE"
The per-file headers are the source of truth for the Go→Java mapping — every reconcilable
file carries a // Port of <upstream/path>. header. Enumerate them:
grep -rn "Port of" --include='*.go' . | grep -v _test.go | grep -v _build/
For each upstream path P, diff it across the window and reconcile anything non-trivial:
git -C _build diff "$BASE" "$TARGET" -- "$P"
The mapping (kept current; if files move, the headers win and this table is refreshed):
| Go | upstream Java path |
|---|---|
phonenumberutil.go, enums.go | java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java |
asyoutypeformatter.go | java/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java |
shortnumberinfo.go | java/libphonenumber/src/com/google/i18n/phonenumbers/ShortNumberInfo.java |
phonenumbermatcher.go | java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberMatcher.java |
phonenumbermatch.go | java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberMatch.java |
errors.go | java/libphonenumber/src/com/google/i18n/phonenumbers/NumberParseException.java |
internal/regexcache/ | java/libphonenumber/src/com/google/i18n/phonenumbers/internal/RegexCache.java |
internal/regexbasedmatcher/ | java/libphonenumber/src/com/google/i18n/phonenumbers/internal/RegexBasedMatcher.java, .../internal/MatcherApi.java |
metadata/source.go, alternateformats.go | java/libphonenumber/src/com/google/i18n/phonenumbers/metadata/source/*, .../MetadataLoader.java |
carrier/ | java/carrier/src/com/google/i18n/phonenumbers/PhoneNumberToCarrierMapper.java |
geocoding/ | java/geocoder/src/com/google/i18n/phonenumbers/geocoding/PhoneNumberOfflineGeocoder.java |
timezone/ | java/geocoder/src/com/google/i18n/phonenumbers/PhoneNumberToTimeZonesMapper.java |
internal/prefixmapper/ | java/internal/prefixmapper/src/com/google/i18n/phonenumbers/prefixmapper/* |
internal/metadatabuilder/ | tools/java/common/src/com/google/i18n/phonenumbers/BuildMetadataFromXml.java |
internal/serialize and internal/stringbuilder are Go-specific scaffolding (gzip/binary
decode; a java.lang.StringBuilder stand-in) with no upstream logic to reconcile — skip them.
The corresponding upstream tests move in lockstep. The Go tests mirror the Java test
classes (e.g. PhoneNumberUtilTest → phonenumberutil_test.go and friends); diff those too
and port new cases:
git -C _build diff "$BASE" "$TARGET" -- "$(echo "$P" | sed 's#/src/#/test/#')"
For each non-empty diff, translate the relevant change into the Go port. While doing so:
metadata/source.go, internal/regexcache, internal/regexbasedmatcher,
internal/prefixmapper); that's expected.// Port of … file, keep constructs close
to the Java so the next diff lines up, even when a linter (gopls modernize, staticcheck)
suggests a more idiomatic Go form — e.g. don't rewrite an index for loop as for i := range n,
or a manual scan as slices.Contains. Let those modernizations ride in with upstream when the
Java itself changes. Non-ported code (cmd/, CI, build glue, and Go-specific scaffolding like
internal/serialize / internal/stringbuilder) has no Java counterpart to track, so make it
fully idiomatic.public in Java is exported in Go; one that is
private/package-private/@VisibleForTesting stays unexported (lower-case camelCase). Constants
especially: REGION_CODE_FOR_NON_GEO_ENTITY is the only public static final upstream, so it
is the lone exported constant — every other ported regex/char-class/length-limit/mapping is
unexported. The deliberate exceptions are the Go-idiomatic Err* vars (standing in for Java's
checked exceptions) and the public enum types. Don't export a new internal just because it's a
package-level const/var.Parse/ParseToNumber,
IsNumberMatch/IsNumberMatchWithNumbers/IsNumberMatchWithOneNumber,
GetExampleNumberForType/GetExampleNumberForTypeInRegion,
IsPossibleNumber/IsPossibleNumberFromRegion, IsNumberGeographical/IsNumberGeographicalForType.
Porting an overload that already exists upstream is faithful porting, not the "don't add API"
case above — fill the gap rather than skipping it. Which overload keeps the bare name (and the
exact suffix) is a judgment call; flag new public names in the PR.metadata/version.go, *.pb.go) or the data/ blobs —
those come from Phase 1 / protoc.Then make it green:
go test ./...
Update SYNC.md (state only):
Synced against version to the target tag.Then, with go test ./... green, commit the changes. Stage the data directories with
git add (not just modified files — new upstream locales produce new blobs):
git add data/ metadata/data/ carrier/data/ geocoding/data/ timezone/data/ metadata/version.go SYNC.md
Then stage any reconciled Go source files.
Commit structure:
Updated metadata to <tag>, e.g. Updated metadata to v9.0.43.Updated metadata to <tag>), then
a second commit with the reconciled Go files and SYNC.md describing what was reconciled.Stop there. Do not push, tag, or touch CHANGELOG.md — those belong to the release
process. Finish by reporting what was synced and that the changes are committed on local main.
Leave public-facing text (commit messages, comments) describing the software in general terms.
MOmorluto/rea485k7,690 new stars in the last 7 days
MOmorluto/rea485k7,690 new stars in the last 7 days
MAmattpocock/skills336k4,217 new stars in the last 7 days
MAmattpocock/skills336k4,217 new stars in the last 7 days
MAmattpocock/skills336k4,217 new stars in the last 7 days
Block dangerous git commands like push and reset --hard before they execute.
MAmattpocock/skills336k4,217 new stars in the last 7 days