|
| 1 | +name: dump-develop |
| 2 | + |
| 3 | +# Keeps site/public/v1 in sync with data/ AFTER a data change lands on develop, |
| 4 | +# so data PRs no longer carry a dump commit (the ~33 min step that every rebase |
| 5 | +# invalidated). Runs the TechEngine dump from the pinned submodule, restricted |
| 6 | +# to the collections the pushed data can affect (app.dump --changed-since), and |
| 7 | +# commits the result back to develop. The commit touches only site/public, which |
| 8 | +# this workflow's own path filter ignores, so it cannot loop. |
| 9 | +on: |
| 10 | + push: |
| 11 | + branches: [develop] |
| 12 | + paths: |
| 13 | + - "data/**" |
| 14 | + workflow_dispatch: |
| 15 | + inputs: |
| 16 | + full: |
| 17 | + description: "Regenerate every collection" |
| 18 | + type: boolean |
| 19 | + default: false |
| 20 | + |
| 21 | +permissions: |
| 22 | + contents: write |
| 23 | + |
| 24 | +concurrency: |
| 25 | + group: dump-develop |
| 26 | + cancel-in-progress: false |
| 27 | + |
| 28 | +jobs: |
| 29 | + dump: |
| 30 | + if: github.repository == 'GetTechAPI/TechAPI' |
| 31 | + runs-on: ubuntu-latest |
| 32 | + timeout-minutes: 120 |
| 33 | + env: |
| 34 | + BEFORE: ${{ github.event.before }} |
| 35 | + FULL: ${{ inputs.full }} |
| 36 | + steps: |
| 37 | + - uses: actions/checkout@v4 |
| 38 | + with: |
| 39 | + # created_at/updated_at come from each record's git history. |
| 40 | + fetch-depth: 0 |
| 41 | + |
| 42 | + - uses: actions/setup-python@v5 |
| 43 | + with: |
| 44 | + python-version: "3.12" |
| 45 | + |
| 46 | + # NOT --recursive: TechEngine carries TechAPI back as a submodule. |
| 47 | + - name: Init TechEngine submodule |
| 48 | + run: git submodule update --init TechEngine |
| 49 | + |
| 50 | + - name: Install TechEngine |
| 51 | + working-directory: TechEngine |
| 52 | + run: pip install -e . |
| 53 | + |
| 54 | + - name: Generate dump |
| 55 | + working-directory: TechEngine |
| 56 | + env: |
| 57 | + TECHAPI_DATA_DIR: ${{ github.workspace }}/data |
| 58 | + run: | |
| 59 | + OUT="${GITHUB_WORKSPACE}/site/public" |
| 60 | + # An older pinned engine has no --changed-since: fall back to a full dump. |
| 61 | + python -m app.dump --help | grep -q -- --changed-since || FULL=true |
| 62 | + if [ "$FULL" = "true" ] || [ -z "$BEFORE" ] || [ "$BEFORE" = "0000000000000000000000000000000000000000" ]; then |
| 63 | + python -m app.validate |
| 64 | + python -m app.dump --output "$OUT" |
| 65 | + else |
| 66 | + python -m app.dump --changed-since "$BEFORE" --output "$OUT" |
| 67 | + fi |
| 68 | +
|
| 69 | + - name: Commit and push if changed |
| 70 | + run: | |
| 71 | + git add site/public |
| 72 | + if git diff --cached --quiet; then |
| 73 | + echo "dump already up to date"; exit 0 |
| 74 | + fi |
| 75 | + git config user.name "github-actions[bot]" |
| 76 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 77 | + git commit -m "chore(dump): refresh public dump for ${GITHUB_SHA::7}" |
| 78 | + # Other merges may have landed while this ran. |
| 79 | + for i in 1 2 3; do |
| 80 | + git pull --rebase origin develop && git push origin HEAD:develop && exit 0 |
| 81 | + sleep 5 |
| 82 | + done |
| 83 | + echo "::error::could not push dump refresh"; exit 1 |
0 commit comments