1# Snapshot builds one city's .atlas on a schedule and publishes it only when2# the city changed. It is reusable: a caller names the city and provides the3# state -- an fmg-archive committed to a branch of the calling repository --4# and this workflow crawls, composes, gates on the bundle's own content5# stamp, and publishes to the caller's releases. A city IT team runs their6# own copy in a private repository with their curation and their key; this7# repository's scheduler runs it over the public proof cities as the living8# test of the same path.9name: Snapshot1011on:12 workflow_call:13 inputs:14 city:15 description: "curated city slug, e.g. bend-or"16 required: true17 type: string18 atlas-ref:19 description: "atlas ref to build with"20 required: false21 type: string22 default: main23 state-branch:24 description: "branch of the calling repository holding the fmg-archive"25 required: false26 type: string27 default: snapshots2829permissions:30 contents: write3132env:33 CGO_ENABLED: "0"34 GOFLAGS: -trimpath -buildvcs=false3536jobs:37 snapshot:38 runs-on: ubuntu-24.0439 steps:40 - name: Check out snapshot state41 uses: actions/checkout@v442 with:43 ref: ${{ inputs.state-branch }}44 path: state45 # The state branch must exist; docs/snapshots.md shows the one-time46 # orphan-branch setup.4748 - name: Check out atlas49 uses: actions/checkout@v450 with:51 repository: FelineStateMachine/atlas52 ref: ${{ inputs.atlas-ref }}53 path: atlas5455 - name: Adopt private curation56 run: |57 if [ -f state/cities_local.go ]; then58 cp state/cities_local.go atlas/internal/arcgismap/cities_local.go59 echo "private curation adopted"60 fi6162 - uses: actions/setup-go@v563 with:64 go-version-file: atlas/go.mod65 cache-dependency-path: atlas/go.sum6667 - name: Crawl68 working-directory: atlas69 run: go run ./tools/crawl -archive ../state/fmg-archive -arcgis "${{ inputs.city }}"7071 - name: Compose72 working-directory: atlas73 run: |74 go run ./tools/tiles -source ../state/fmg-archive -output build/tiles75 go run ./tools/generate -source ../state -tiles build/tiles/index.json -bundles ../out7677 - name: Gate on the stamp78 id: gate79 working-directory: out80 env:81 GH_TOKEN: ${{ github.token }}82 run: |83 FILE=$(ls ${{ inputs.city }}-*.atlas | sort | tail -1)84 echo "file=$FILE" >> "$GITHUB_OUTPUT"85 if gh release view "snapshot-${{ inputs.city }}" --repo "$GITHUB_REPOSITORY" \86 --json assets -q '.assets[].name' 2>/dev/null | grep -qx "$FILE"; then87 echo "unchanged: $FILE is already published"88 echo "changed=false" >> "$GITHUB_OUTPUT"89 else90 echo "changed=true" >> "$GITHUB_OUTPUT"91 fi9293 - name: Commit the archive94 if: steps.gate.outputs.changed == 'true'95 working-directory: state96 run: |97 git config user.name "atlas-snapshot"98 git config user.email "snapshot@users.noreply.github.com"99 git add -A100 git diff --cached --quiet || git commit -m "snapshot ${{ inputs.city }}: ${{ steps.gate.outputs.file }}"101 git push102103 - name: Publish104 if: steps.gate.outputs.changed == 'true'105 env:106 GH_TOKEN: ${{ github.token }}107 run: |108 FILE="${{ steps.gate.outputs.file }}"109 RELEASE="snapshot-${{ inputs.city }}"110 if ! gh release view "$RELEASE" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then111 gh release create "$RELEASE" --repo "$GITHUB_REPOSITORY" \112 --title "Snapshots: ${{ inputs.city }}" \113 --notes "Scheduled .atlas snapshots. Every published version stays; *-latest.atlas always names the newest." \114 --target "${{ inputs.state-branch }}"115 fi116 cp "out/$FILE" "out/${{ inputs.city }}-latest.atlas"117 gh release upload "$RELEASE" --repo "$GITHUB_REPOSITORY" \118 "out/$FILE" "out/${{ inputs.city }}-latest.atlas#${{ inputs.city }}-latest.atlas" --clobber119 echo "published $FILE"