|
| 1 | +name: Tutorial data |
| 2 | + |
| 3 | +# Builds the pre-built example FlowSystems and uploads them (plus registry.txt) as |
| 4 | +# assets to the GitHub release that `flixopt.tutorials.load_example` downloads from. |
| 5 | +# Run manually whenever the example systems change. The release tag must match |
| 6 | +# `flixopt.tutorials._examples.DATA_RELEASE` (default: tutorial-data-v1). |
| 7 | + |
| 8 | +on: |
| 9 | + workflow_dispatch: |
| 10 | + inputs: |
| 11 | + release_tag: |
| 12 | + description: "Release tag to (re)upload the data assets to (must match DATA_RELEASE)." |
| 13 | + required: true |
| 14 | + default: "tutorial-data-v1" |
| 15 | + |
| 16 | +env: |
| 17 | + PYTHON_VERSION: "3.11" |
| 18 | + |
| 19 | +jobs: |
| 20 | + build-and-upload: |
| 21 | + name: Build and upload example systems |
| 22 | + runs-on: ubuntu-24.04 |
| 23 | + permissions: |
| 24 | + contents: write |
| 25 | + steps: |
| 26 | + - uses: actions/checkout@v6 |
| 27 | + with: |
| 28 | + fetch-depth: 0 |
| 29 | + persist-credentials: false |
| 30 | + |
| 31 | + - uses: astral-sh/setup-uv@v7 |
| 32 | + with: |
| 33 | + version: "0.10.9" |
| 34 | + enable-cache: true |
| 35 | + |
| 36 | + - uses: actions/setup-python@v6 |
| 37 | + with: |
| 38 | + python-version: ${{ env.PYTHON_VERSION }} |
| 39 | + |
| 40 | + # docs extra provides demandlib/pvlib/holidays used by the example generators. |
| 41 | + - name: Install build dependencies |
| 42 | + run: uv pip install --system -e ".[docs,full]" |
| 43 | + |
| 44 | + - name: Verify DATA_RELEASE matches the requested tag |
| 45 | + run: | |
| 46 | + EXPECTED=$(python -c "from flixopt.tutorials._examples import DATA_RELEASE; print(DATA_RELEASE)") |
| 47 | + if [[ "$EXPECTED" != "$TAG" ]]; then |
| 48 | + echo "::error::DATA_RELEASE is '$EXPECTED' but the workflow was asked to upload to '$TAG'." |
| 49 | + echo "Update flixopt/tutorials/_examples.py or pass the matching tag." |
| 50 | + exit 1 |
| 51 | + fi |
| 52 | + env: |
| 53 | + TAG: ${{ inputs.release_tag }} |
| 54 | + |
| 55 | + - name: Build example systems |
| 56 | + run: python scripts/build_tutorial_datasets.py --out-dir dist/tutorial_datasets |
| 57 | + |
| 58 | + - name: Create the data release if it does not exist |
| 59 | + run: | |
| 60 | + if ! gh release view "$TAG" >/dev/null 2>&1; then |
| 61 | + gh release create "$TAG" \ |
| 62 | + --title "Tutorial data ($TAG)" \ |
| 63 | + --notes "Pre-built example FlowSystems downloaded by flixopt.tutorials.load_example." \ |
| 64 | + --prerelease |
| 65 | + fi |
| 66 | + env: |
| 67 | + GH_TOKEN: ${{ github.token }} |
| 68 | + TAG: ${{ inputs.release_tag }} |
| 69 | + |
| 70 | + - name: Upload data assets |
| 71 | + run: gh release upload "$TAG" dist/tutorial_datasets/* --clobber |
| 72 | + env: |
| 73 | + GH_TOKEN: ${{ github.token }} |
| 74 | + TAG: ${{ inputs.release_tag }} |
0 commit comments