Skip to content

Commit fa4d18b

Browse files
ci: add tzdata update workflow
1 parent 2553e1a commit fa4d18b

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: tzdata update
2+
on:
3+
schedule:
4+
- cron: "0 23 * * *"
5+
workflow_dispatch:
6+
7+
permissions:
8+
contents: write
9+
10+
jobs:
11+
update:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Check out repository code
15+
uses: actions/checkout@v4
16+
- name: Set up Go
17+
uses: actions/setup-go@v5
18+
with:
19+
go-version-file: go.mod
20+
- name: Fetch latest tzcode version
21+
run: |
22+
set -euo pipefail
23+
workdir=$(mktemp -d)
24+
wget -O "$workdir/tzcode-latest.tar.gz" https://www.iana.org/time-zones/repository/tzcode-latest.tar.gz
25+
tar -xzf "$workdir/tzcode-latest.tar.gz" -C "$workdir"
26+
27+
version_file=$(find "$workdir" -maxdepth 2 -type f -name version | head -n 1)
28+
if [ -z "$version_file" ]; then
29+
echo "version file not found in tzcode-latest.tar.gz" >&2
30+
exit 1
31+
fi
32+
33+
latest_version=$(tr -d ' \n' < "$version_file")
34+
current_version=$(grep -E 'tzVersion' scripts/tzgen/main.go | sed -E 's/.*"([^"]+)".*/\1/' | head -n 1)
35+
36+
echo "current=$current_version latest=$latest_version"
37+
if [ "$latest_version" = "$current_version" ]; then
38+
echo "tzdata is already up to date"
39+
exit 0
40+
fi
41+
42+
sed -i.bak -E 's/tzVersion = ".*"/tzVersion = "'"$latest_version"'"/' scripts/tzgen/main.go
43+
rm -f scripts/tzgen/main.go.bak
44+
gofmt -w scripts/tzgen/main.go
45+
go run scripts/tzgen/main.go
46+
47+
git config user.name "github-actions[bot]"
48+
git config user.email "github-actions[bot]@users.noreply.github.com"
49+
git add scripts/tzgen/main.go tz
50+
git commit -m "Update tzdata to ${latest_version}"
51+
git push

0 commit comments

Comments
 (0)