Skip to content

Scrape

Scrape #20520

Workflow file for this run

name: Scrape
on:
schedule:
- cron: "*/12 * * * *"
workflow_dispatch:
jobs:
scrape:
name: "Scrape latest photo"
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
deno-version: [v1.x]
outputs:
time: ${{ steps.scrape.outputs.time }}
size: ${{ steps.scrape.outputs.size }}
diff: ${{ steps.scrape.outputs.diff }}
hash: ${{ steps.scrape.outputs.hash }}
path: ${{ steps.scrape.outputs.path }}
key: ${{ steps.scrape.outputs.key }}
steps:
- name: "(git) configure repo"
run: |
git config --global user.email "github-actions@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
git config --global fetch.parallel 32
- name: "(git) checkout repo"
uses: actions/checkout@v4
with:
# sparse-checkout: .
ref: main
- name: "(run) setup deno"
uses: denoland/setup-deno@v1
with:
deno-version: ${{ matrix.deno-version }}
- id: scrape
name: "(run) deno task scrape"
env:
TZ: "London" # ensure we are running in UTC±00:00
DENO_KV_PATH: ${{ secrets.DENO_KV_PATH }}
DENO_KV_ACCESS_TOKEN: ${{ secrets.DENO_KV_ACCESS_TOKEN }}
run: deno task scrape
- name: "(git) commit + push"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OUTPUT_TIME: ${{ fromJSON(steps.scrape.outputs.time) }}
OUTPUT_SIZE: ${{ steps.scrape.outputs.size }}
OUTPUT_DIFF: ${{ steps.scrape.outputs.diff }}
OUTPUT_HASH: ${{ steps.scrape.outputs.hash }}
OUTPUT_PATH: ${{ steps.scrape.outputs.path }}
OUTPUT_KEY: ${{ steps.scrape.outputs.key }}
run: |
OUTPUT_DATE="$(echo -n "${OUTPUT_TIME-}" | cut -dT -f1)"
message=""
message+='[%s]: 📸 new photo captured\n\nTasks completed by this commit:\n\n'
message+='- [x] updated latest image with the new data\n- [x] saved in the assets folder under %s\n'
message+='- [x] saved blob in Deno KV under the key below\n- [x] hash indexed in Deno KV for de-duping\n\n'
message+='📎 View: %s\n\n| Description | %-64s |\n| ------------- | %-64s |\n| Time (in UTC) | %-64s |\n'
message+='| Hash (SHA256) | %-64s |\n| Size (KBytes) | %-64.2f |\n| Diff (KBytes) | %+-64.2f |\n'
message+='| Path (local) | %-64s |\n| Key (Deno KV) | %-64s |\n\n'
message+='Note: the term "hash" used above refers to the image data sha256sum.\n\n'
message+='> **Warning**: this commit message is auto-generated and may contain errors.\n'
message="$(
printf \
"$message" \
"${OUTPUT_TIME-}" \
"${OUTPUT_DATE-}" \
"https://github.com/nberlette/f1/raw/main/${OUTPUT_PATH#./}" \
"Value" \
"$(printf '%-64s' "-" | tr ' ' '-')" \
"${OUTPUT_TIME-}" \
"${OUTPUT_HASH-}" \
"$((OUTPUT_SIZE / 1024))" \
"$((OUTPUT_DIFF / 1024))" \
"${OUTPUT_PATH-}" \
"${OUTPUT_KEY-}" \
)"
git add ./assets && git commit -m "${message}" && git push
- if: success()
name: "(run) upload artifacts"
uses: actions/upload-artifact@v3
with:
path: ${{ steps.scrape.outputs.path }}
name: ${{ steps.scrape.outputs.hash }}