Analyze #83
This file contains 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: Analyze | |
on: | |
workflow_dispatch: | |
inputs: | |
refresh_cache: | |
description: Refresh OpenSkiMap download | |
type: boolean | |
required: true | |
default: false | |
solar_segment_count: | |
description: Number of uncached run segments to compute solar irradiation for | |
type: number | |
required: false | |
default: 5000 | |
schedule: | |
- cron: "0 10 * * SAT" # https://crontab.guru/#0_10_*_*_SAT | |
jobs: | |
analyze: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
# default timeout of 360 minutes is the max supported by GitHub-hosted runners, | |
# which is too short to compute all solar irradiation values | |
timeout-minutes: 360 | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: ./.github/workflows/setup-python | |
- uses: ./.github/workflows/setup-r | |
- uses: ./.github/workflows/setup-quarto | |
- name: install fonts | |
run: sudo apt-get install --yes --quiet fonts-dejavu-core fonts-noto-cjk | |
- name: Process inputs | |
id: inputs | |
run: | | |
echo "refresh_cache=${{ fromJSON(inputs.refresh_cache) || github.event_name == 'schedule' }}" >> "$GITHUB_OUTPUT" | |
echo "solar_segment_count=${{ inputs.solar_segment_count || 300000 }}" >> "$GITHUB_OUTPUT" | |
# GitHub will remove any cache entries that have not been accessed in over 7 days | |
- name: Restore OpenSkiMap Cache | |
id: restore-openskimap | |
if: ${{ steps.inputs.outputs.refresh_cache != 'true' }} | |
uses: actions/cache/restore@v4 | |
with: | |
path: data/openskimap | |
key: openskimap | |
- name: Download OpenSkiMap | |
id: download-openskimap | |
# confusing behavior where inputs.refresh_cache acts like a string not a boolean | |
# https://stackoverflow.com/questions/76292948/github-action-boolean-input-with-default-value | |
# https://github.com/actions/runner/issues/1483 | |
# the step if condition stopped working around 2025-01-03, so use bash condition to skip the download if files exist | |
if: steps.inputs.outputs.refresh_cache == 'true' || steps.restore-openskimap.outputs.cache-hit != 'true' | |
run: | | |
if [ ! -f "data/openskimap/runs.geojson.xz" ]; then | |
uv run openskistats download | |
echo "downloaded=true" >> "$GITHUB_OUTPUT" | |
fi | |
shell: bash | |
- name: Save OpenSkiMap Cache | |
if: steps.download-openskimap.outputs.downloaded == 'true' | |
uses: actions/cache/save@v4 | |
with: | |
path: data/openskimap | |
key: openskimap | |
- name: Python Analysis | |
env: | |
OPENSKISTATS_SOLAR_SEGMENT_COUNT: ${{ steps.inputs.outputs.solar_segment_count }} | |
run: | | |
uv run openskistats analyze | |
uv run openskistats validate | |
uv run openskistats visualize | |
shell: bash | |
- name: Make story plots | |
working-directory: r/ | |
run: | | |
Rscript 01.data.R | |
Rscript 02.plot.R | |
- name: Quarto Render | |
run: uv run quarto render website | |
- name: Publish data | |
uses: peaceiris/actions-gh-pages@v4 | |
if: github.ref == 'refs/heads/main' | |
with: | |
publish_branch: data | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
publish_dir: ./data | |
# it's not clear how exclude_assets works | |
# https://github.com/peaceiris/actions-gh-pages/blob/ababa3d330af34b07419f6bc9f4a6b817ed7930b/src/git-utils.ts#L21-L39 | |
exclude_assets: "data/website,data/openskistats" | |
force_orphan: true | |
# remove the unnecessary .nojekyll file | |
enable_jekyll: true | |
- name: Deploy website | |
uses: peaceiris/actions-gh-pages@v4 | |
if: github.ref == 'refs/heads/main' | |
with: | |
publish_branch: gh-pages | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
publish_dir: ./data/webapp | |
exclude_assets: "**.xz,**.parquet" | |
force_orphan: true | |
cname: openskistats.org |