Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
46 changes: 21 additions & 25 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,31 @@ name: Go

on:
push:
branches: [ master ]
branches: [master, v1]
pull_request:
branches: [ master ]
branches: [master, v1]

jobs:

build:
name: Build
name: Build & Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- run: go build ./...
- run: go test -v -race ./...
- run: go vet ./...

- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.13
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Get dependencies
run: |
go get -v -t -d ./...
if [ -f Gopkg.toml ]; then
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
dep ensure
fi

- name: Test
run: |
go get github.com/stretchr/testify/assert
go test -v .
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- uses: golangci/golangci-lint-action@v6
with:
version: latest
72 changes: 72 additions & 0 deletions .github/workflows/sync-upstream.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Sync upstream country data

on:
schedule:
- cron: "0 6 * * 1"
workflow_dispatch:

permissions:
contents: write
pull-requests: write

jobs:
sync:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0

- uses: actions/setup-go@v5
with:
go-version-file: go.mod

- name: Bump countries/countries to latest tag
id: gem
working-directory: upstream/countries
run: |
git fetch --tags
latest=$(git tag --list 'v*' --sort=-v:refname | head -1)
if [ -z "$latest" ]; then echo "no tags found" >&2; exit 1; fi
git checkout "$latest"
echo "version=$latest" >> "$GITHUB_OUTPUT"

- name: Bump mledoze/countries to latest tag
id: mledoze
working-directory: upstream/mledoze-countries
run: |
git fetch --tags
latest=$(git tag --list --sort=-v:refname | head -1)
if [ -z "$latest" ]; then echo "no tags found" >&2; exit 1; fi
git checkout "$latest"
echo "version=$latest" >> "$GITHUB_OUTPUT"

- name: Regenerate data
run: go run ./cmd/sync-data

- name: Run tests
run: go test ./...

- name: Open PR if data changed
uses: peter-evans/create-pull-request@v6
with:
branch: sync/upstream-${{ github.run_id }}
title: "data: sync from countries ${{ steps.gem.outputs.version }} + mledoze ${{ steps.mledoze.outputs.version }}"
commit-message: |
data: sync upstream

countries/countries: ${{ steps.gem.outputs.version }}
mledoze/countries: ${{ steps.mledoze.outputs.version }}
body: |
Automated sync of country and subdivision data.

Sources:
- countries/countries ${{ steps.gem.outputs.version }}
- mledoze/countries ${{ steps.mledoze.outputs.version }}

Tests pass. Review the YAML diff before merging.
labels: data-sync
add-paths: |
data/yaml/**
upstream
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ _projects
_steps
_temp
cover.out
/sync-data
8 changes: 8 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[submodule "upstream/countries"]
path = upstream/countries
url = https://github.com/countries/countries.git
branch = master
[submodule "upstream/mledoze-countries"]
path = upstream/mledoze-countries
url = https://github.com/mledoze/countries.git
branch = master
24 changes: 24 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: "2"

run:
timeout: 3m

linters:
enable:
- errcheck
- govet
- ineffassign
- staticcheck
- unused
- misspell
settings:
staticcheck:
# Quick-fix style suggestions are noise for this codebase; keep
# only correctness/perf checks.
checks:
- "all"
- "-QF*"
exclusions:
paths:
- upstream
- data
86 changes: 86 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Changelog

All notable changes to this project are documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.0] — Unreleased

This is a **breaking** release. The data pipeline has been rebuilt from scratch
and the embedded country/subdivision data is now sourced from upstream
projects that are actively maintained, instead of the previous custom toolchain
that had grown stale.

### Pinning the old release

If you need the v0.1.x behavior and data exactly, pin:

```
go get github.com/pariz/gountries@v0.1.6
```

### Added

- `Country.AltSpellings []string` — short forms and unofficial names (e.g.
`"United States"`, `"USA"`, `"États-Unis"`). These are indexed by
`FindCountryByName`, so common short forms now resolve.
- `cmd/sync-data` — Go program that regenerates `data/yaml/` from vendored
upstream submodules (`upstream/countries`, `upstream/mledoze-countries`).
Run with `go run ./cmd/sync-data`.
- Weekly `sync-upstream` GitHub Action that bumps both upstream submodules,
regenerates data, runs tests, and opens a PR if anything changed.
- `TestDataInvariants` — sanity tests that guard against silent upstream
regressions (mass deletion, schema breakage, canary-lookup failures).

### Changed

- **Data sources.** Country and subdivision data is now derived from
[countries/countries](https://github.com/countries/countries) (MIT, primary)
and [mledoze/countries](https://github.com/mledoze/countries) (ODbL,
supplemental for borders / TLDs / translations).
- **Data shape.** Many countries now have richer translations (Sweden goes
from 7 to 23 languages), more accurate coordinates, more complete
subdivisions (5,059 entries across 200 countries vs. the previous ~195
files with sparser coverage).
- **Embedding mechanism.** Switched from `go-bindata` to the standard library
`//go:embed` (Go 1.16+). The data files are still loaded from
`data/yaml/{countries,subdivisions}/` but you no longer need an external
tool to regenerate the embed.
- **`NewFromPath(path string)`** — still takes a directory path, but reads
through `os.DirFS(path)`. The directory must contain `countries/` and
`subdivisions/` subdirectories (same layout as before).
- **Go version** bumped to 1.21 in `go.mod` (was 1.17).
- **CI workflow** modernized: `actions/setup-go@v5`, `go-version-file: go.mod`,
`go test -race`, `go vet`.

### Removed

- **`bindata.go` and all its exports** — `Asset`, `AssetDir`, `AssetNames`,
`AssetInfo`, `MustAsset`, `RestoreAsset`, `RestoreAssets`, `AssetNameMap`.
If you were importing any of these (none are part of the documented public
API but they were exported), you'll need to read files via your own means.
- The old `gountries-creator` workflow is no longer the data source. The repo
is preserved separately for history but is not used by v1.

### Fixed

- `FindCountryByName` now resolves common short forms and alt-spellings via
the new `AltSpellings` index — e.g. `"United States"` correctly returns the
US even though its canonical `iso_short_name` is `"United States of America"`.
- Czech Republic is now spelled "Czechia" (matching ISO since 2016).
- Bulgaria's currency reflects the EUR transition effective 1 Jan 2026.

### License notes

The Go code remains MIT-licensed. The regenerated YAML data is a derivative
of two upstreams:
- countries/countries — MIT
- mledoze/countries — ODbL

The `data/yaml/` directory should be considered a Derivative Database under
ODbL by virtue of incorporating mledoze fields. See
[upstream/mledoze-countries/LICENSE](upstream/mledoze-countries/LICENSE).
Use of the gountries Go API to query the data does not create a Derivative
Database for your application — only modifying and redistributing the data
itself triggers the ODbL share-alike clause.
Loading
Loading