Skip to content

Update EU VAT Rates #54

Update EU VAT Rates

Update EU VAT Rates #54

Workflow file for this run

name: Update EU VAT Rates
on:
schedule:
# Run 1 hour after the data repo updates (which runs at 07:00 UTC)
- cron: '0 8 * * *'
workflow_dispatch:
inputs:
dry_run:
description: 'Dry run (show diff without publishing)'
type: boolean
default: false
force_publish:
description: 'Force publish even if rates unchanged (for initial release)'
type: boolean
default: false
jobs:
update:
name: Fetch, bump & publish
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v5
- name: Download latest VAT rates
run: |
curl -sf https://raw.githubusercontent.com/vatnode/eu-vat-rates-data/main/data/eu-vat-rates-data.json \
-o /tmp/latest.json
- name: Check for rate changes
id: diff
run: |
CURRENT=$(python3 -c "import json,sys; print(json.dumps(json.load(open(sys.argv[1]))['rates'],sort_keys=True))" src/eu_vat_rates_data/eu_vat_rates_data.json)
LATEST=$(python3 -c "import json,sys; print(json.dumps(json.load(open(sys.argv[1]))['rates'],sort_keys=True))" /tmp/latest.json)
if [ "${{ github.event.inputs.force_publish }}" = "true" ]; then
echo "rates_changed=true" >> "$GITHUB_OUTPUT"
echo "Force publish requested."
elif [ "$CURRENT" = "$LATEST" ]; then
echo "rates_changed=false" >> "$GITHUB_OUTPUT"
echo "No rate changes."
else
echo "rates_changed=true" >> "$GITHUB_OUTPUT"
echo "Rate changes detected."
fi
- name: Update bundled data
if: steps.diff.outputs.rates_changed == 'true'
run: cp /tmp/latest.json src/eu_vat_rates_data/eu_vat_rates_data.json
- name: Set up Python
if: steps.diff.outputs.rates_changed == 'true' && github.event.inputs.dry_run != 'true'
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install build tools
if: steps.diff.outputs.rates_changed == 'true' && github.event.inputs.dry_run != 'true'
run: pip install hatch
- name: Bump version and build
if: steps.diff.outputs.rates_changed == 'true' && github.event.inputs.dry_run != 'true'
run: |
YEAR=$(date -u +%Y)
MONTH=$(date -u +%-m)
DAY=$(date -u +%-d)
VERSION="${YEAR}.${MONTH}.${DAY}"
# If this version already exists on PyPI, increment the day until we find a free slot
while curl -sf "https://pypi.org/pypi/eu-vat-rates-data/${VERSION}/json" -o /dev/null; do
DAY=$((DAY + 1))
VERSION="${YEAR}.${MONTH}.${DAY}"
done
echo "Publishing version: $VERSION"
sed -i "s/^version = .*/version = \"$VERSION\"/" pyproject.toml
hatch build
- name: Publish to PyPI
if: steps.diff.outputs.rates_changed == 'true' && github.event.inputs.dry_run != 'true'
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_TOKEN }}
- name: Commit and push
if: steps.diff.outputs.rates_changed == 'true' && github.event.inputs.dry_run != 'true'
run: |
DATE=$(date -u +%Y-%m-%d)
VERSION=$(python3 -c "import tomllib; print(tomllib.load(open('pyproject.toml','rb'))['project']['version'])")
git config user.name "vatnode-bot"
git config user.email "bot@vatnode.dev"
git add src/eu_vat_rates_data/eu_vat_rates_data.json pyproject.toml
git diff --staged --quiet || git commit -m "chore: update VAT rates ${DATE} (v${VERSION})"
git push