Refresh dataset #1
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: Refresh dataset | |
| # Regenerates lib/sepomex_db.csv from the latest official SEPOMEX export and | |
| # opens a PR when the data changes. | |
| # | |
| # The scheduled run is self-contained: `rake data:refresh` downloads the export | |
| # straight from Correos de México (the CodigoPostal_Exportar.aspx WebForms | |
| # postback, handled by FetchSepomexExport) and regenerates the CSV — no mirror | |
| # URL to provision. Pass a `xml_url` on manual dispatch to import a specific, | |
| # already-hosted `CPdescarga.xml` instead (e.g. to reproduce a past export). | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| xml_url: | |
| description: Optional URL to a specific SEPOMEX CPdescarga.xml (skips the live download) | |
| required: false | |
| schedule: | |
| - cron: "0 6 1 * *" # 06:00 UTC on the 1st of each month | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| concurrency: | |
| group: data-refresh | |
| cancel-in-progress: false | |
| jobs: | |
| refresh: | |
| name: Refresh dataset | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v7 | |
| - name: Set up Ruby | |
| uses: ruby/setup-ruby@v1 | |
| with: | |
| bundler-cache: true | |
| - name: Regenerate lib/sepomex_db.csv from the latest export | |
| if: github.event.inputs.xml_url == '' | |
| run: bundle exec rake data:refresh | |
| - name: Regenerate lib/sepomex_db.csv from a provided URL | |
| if: github.event.inputs.xml_url != '' | |
| run: | | |
| curl -fSL "${{ github.event.inputs.xml_url }}" -o "${RUNNER_TEMP}/CPdescarga.xml" | |
| bundle exec rake "data:import_xml[${RUNNER_TEMP}/CPdescarga.xml]" | |
| - name: Open a PR if the dataset changed | |
| uses: peter-evans/create-pull-request@v8 | |
| with: | |
| branch: chore/refresh-dataset | |
| add-paths: lib/sepomex_db.csv | |
| commit-message: Refresh lib/sepomex_db.csv from the latest SEPOMEX export | |
| title: Refresh postal-code dataset | |
| labels: data | |
| body: | | |
| Automated refresh of `lib/sepomex_db.csv` from the latest official | |
| SEPOMEX export (`rake data:refresh`). | |
| After merging, the next release image bakes in the new data; to update | |
| a running/local database, run `bin/rails db:reset && rake data:loadev`. |