Skip to content

Build Latest TZDB #1102

Build Latest TZDB

Build Latest TZDB #1102

name: Build Latest TZDB
on:
workflow_dispatch:
push:
branches:
- main
schedule:
- cron: '0 0 * * *'
jobs:
check:
name: Check if newer version available
runs-on: ubuntu-latest
outputs:
build_required: ${{steps.build_required.outputs.required}}
latest_iana_version: ${{steps.versions.outputs.latest_iana_version}}
last_processed_version: ${{steps.versions.outputs.last_processed_version}}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Fetch latest version file from IANA
run: wget https://data.iana.org/time-zones/tzdb/version
- name: Determine versions
id: versions
run: |
LATEST_IANA_VERSION=`cat version | sed 's/ *//g'`
echo "latest_iana_version=$LATEST_IANA_VERSION" >> $GITHUB_OUTPUT
touch last_processed_version
LAST_PROCESSED_VERSION=`cat last_processed_version | sed 's/ *//g'`
echo "last_processed_version=$LAST_PROCESSED_VERSION" >> $GITHUB_OUTPUT
- run: echo Latest IANA version [${{steps.versions.outputs.latest_iana_version}}] and Last processed version [${{steps.versions.outputs.last_processed_version}}] and Trigger [${{github.event_name}}]
- name: Check if a build is required
id: build_required
run: |
if [ "${{steps.versions.outputs.latest_iana_version}}" != "${{steps.versions.outputs.last_processed_version}}" ] || [ "${{github.event_name}}" != "schedule" ]; then
echo "required=true" >> $GITHUB_OUTPUT
else
echo "required=false" >> $GITHUB_OUTPUT
fi
- name: Record last run timestamp
run: echo $(date) > last_run_timestamp
- name: Commit last run timestamp
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Update last run timestamp
file_pattern: last_run_timestamp
skip_dirty_check: false
build:
name: Build
runs-on: ubuntu-latest
needs: check
if: needs.check.outputs.build_required == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Git pull
run: git pull
- name: Check installed TZDB version
run: java test/GetTzdbVersion.java
- name: Fetch TZDB code and data from IANA
run: |
mkdir -p temp
cd temp
wget https://data.iana.org/time-zones/releases/tzcode${{needs.check.outputs.latest_iana_version}}.tar.gz
wget https://data.iana.org/time-zones/releases/tzdata${{needs.check.outputs.latest_iana_version}}.tar.gz
tar xzfv tzcode${{needs.check.outputs.latest_iana_version}}.tar.gz
tar xzfv tzdata${{needs.check.outputs.latest_iana_version}}.tar.gz
make rearguard_tarballs
cp "tzdata${{needs.check.outputs.latest_iana_version}}-rearguard.tar.gz" ..
- name: Backup existing TZDB file permissions
id: perms
run: |
TZDB_PERMS=`stat -c "%a" $JAVA_HOME/lib/tzdb.dat`
echo "tzdb_perms=$TZDB_PERMS" >> $GITHUB_OUTPUT
- name: Run ziupdater and install new TZDB
run: sudo java -jar ziupdater/ziupdater.jar -l file://`pwd`/tzdata${{needs.check.outputs.latest_iana_version}}-rearguard.tar.gz
- name: Restore TZDB file permissions
run: sudo chmod ${{steps.perms.outputs.tzdb_perms}} $JAVA_HOME/lib/tzdb.dat
- name: Recheck installed TZDB version
run: java test/GetTzdbVersion.java
- name: Runs tests
run: java test/CheckTimeZoneInformation.java
- name: Prep files for commit
run: |
mkdir -p releases/${{needs.check.outputs.latest_iana_version}}
mkdir -p releases/latest
echo ${{needs.check.outputs.latest_iana_version}} > last_processed_version
cp temp/tzdata${{needs.check.outputs.latest_iana_version}}-rearguard.tar.gz releases/${{needs.check.outputs.latest_iana_version}}
cp $JAVA_HOME/lib/tzdb.dat releases/${{needs.check.outputs.latest_iana_version}}/tzdb${{needs.check.outputs.latest_iana_version}}.dat
cp temp/tzdata${{needs.check.outputs.latest_iana_version}}-rearguard.tar.gz releases/latest/tzdata-rearguard.tar.gz
cp $JAVA_HOME/lib/tzdb.dat releases/latest/tzdb.dat
- name: Commit files if needed
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Build TZDB ${{needs.check.outputs.latest_iana_version}}
file_pattern: last_processed_version releases/*
skip_fetch: false
skip_checkout: true
skip_dirty_check: false
- name: Release
uses: softprops/action-gh-release@v1
with:
body: Release TZDB ${{needs.check.outputs.latest_iana_version}}
files: |
releases/${{needs.check.outputs.latest_iana_version}}/*
name: Release TZDB ${{needs.check.outputs.latest_iana_version}}
tag_name: TZDB-${{needs.check.outputs.latest_iana_version}}