diff --git a/.github/workflows/tzdata-update.yml b/.github/workflows/tzdata-update.yml new file mode 100644 index 0000000..996319a --- /dev/null +++ b/.github/workflows/tzdata-update.yml @@ -0,0 +1,51 @@ +name: tzdata update +on: + schedule: + - cron: "0 23 * * *" + workflow_dispatch: + +permissions: + contents: write + +jobs: + update: + runs-on: ubuntu-latest + steps: + - name: Check out repository code + uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + - name: Fetch latest tzcode version + run: | + set -euo pipefail + workdir=$(mktemp -d) + wget -O "$workdir/tzcode-latest.tar.gz" https://www.iana.org/time-zones/repository/tzcode-latest.tar.gz + tar -xzf "$workdir/tzcode-latest.tar.gz" -C "$workdir" + + version_file=$(find "$workdir" -maxdepth 2 -type f -name version | head -n 1) + if [ -z "$version_file" ]; then + echo "version file not found in tzcode-latest.tar.gz" >&2 + exit 1 + fi + + latest_version=$(tr -d ' \n' < "$version_file") + current_version=$(grep -E 'tzVersion' scripts/tzgen/main.go | sed -E 's/.*"([^"]+)".*/\1/' | head -n 1) + + echo "current=$current_version latest=$latest_version" + if [ "$latest_version" = "$current_version" ]; then + echo "tzdata is already up to date" + exit 0 + fi + + sed -i.bak -E 's/tzVersion = ".*"/tzVersion = "'"$latest_version"'"/' scripts/tzgen/main.go + rm -f scripts/tzgen/main.go.bak + gofmt -w scripts/tzgen/main.go + go run scripts/tzgen/main.go + + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git add scripts/tzgen/main.go tz + git commit -m "Update tzdata to ${latest_version}" + git push diff --git a/scripts/tzgen/main.go b/scripts/tzgen/main.go index 51b2ba5..a3737e8 100644 --- a/scripts/tzgen/main.go +++ b/scripts/tzgen/main.go @@ -16,7 +16,10 @@ import ( "strings" ) -const tzdataURL = "https://data.iana.org/time-zones/releases/tzdata2025b.tar.gz" +const ( + tzVersion = "2025c" + tzdataURL = "https://data.iana.org/time-zones/releases/tzdata" + tzVersion + ".tar.gz" +) func main() { if err := run(context.Background()); err != nil {