Update EU VAT Rates #63
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Update EU VAT Rates | |
| on: | |
| schedule: | |
| - 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 & 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: | | |
| if [ "${{ github.event.inputs.force_publish }}" = "true" ]; then | |
| echo "rates_changed=true" >> "$GITHUB_OUTPUT" | |
| echo "Force publish requested." | |
| else | |
| CURRENT=$(python3 -c "import json,sys; print(json.dumps(json.load(open(sys.argv[1]))['rates'],sort_keys=True))" 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 [ "$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 | |
| fi | |
| - name: Update bundled data | |
| if: steps.diff.outputs.rates_changed == 'true' | |
| run: cp /tmp/latest.json data/eu-vat-rates-data.json | |
| - name: Commit, tag and push | |
| if: steps.diff.outputs.rates_changed == 'true' && github.event.inputs.dry_run != 'true' | |
| run: | | |
| DATE=$(date -u +%Y-%m-%d) | |
| YEAR=$(date -u +%Y) | |
| MONTH=$(date -u +%-m) | |
| DAY=$(date -u +%-d) | |
| VERSION="${YEAR}.${MONTH}.${DAY}" | |
| # Check remote tags to avoid push rejection (shallow clone has no local tags) | |
| while git ls-remote --tags origin "refs/tags/v${VERSION}" | grep -q .; do | |
| DAY=$((DAY + 1)) | |
| VERSION="${YEAR}.${MONTH}.${DAY}" | |
| done | |
| git config user.name "vatnode-bot" | |
| git config user.email "bot@vatnode.dev" | |
| git add data/eu-vat-rates-data.json | |
| git diff --staged --quiet || git commit -m "chore: update VAT rates ${DATE} (v${VERSION})" | |
| git tag "v${VERSION}" | |
| git push && git push --tags |