Skip to content

Commit a1dee3f

Browse files
euronionpre-commit-ci[bot]lkstrp
authored
doc: Automatically update DAGs in documentation (#1880)
* doc: Automatically update DAGs in documentation * doc: Update release notes * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * I find working with the CI always tricky * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * some adjustments --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: lkstrp <[email protected]>
1 parent dd7b149 commit a1dee3f

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed

.github/workflows/release.yaml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- v*.*.*
7+
8+
env:
9+
PREPARATION_COMMIT: '[github-actions.ci] prepare release ${{ github.ref_name }}'
10+
BASE_ENV: envs/environment.yaml
11+
12+
jobs:
13+
check-preparation:
14+
name: Check if release is prepared
15+
runs-on: ubuntu-latest
16+
outputs:
17+
prepared: ${{ steps.validate.outputs.prepared }}
18+
steps:
19+
- uses: actions/checkout@v5
20+
21+
- name: Validate commit message
22+
id: validate
23+
run: |
24+
# Check if last commit is the expected commit message
25+
COMMIT_MESSAGE=$(git log -1 --pretty=%B)
26+
echo "Expected: '${{ env.PREPARATION_COMMIT }}'"
27+
echo "Received: '$COMMIT_MESSAGE'"
28+
29+
prepared="false"
30+
if [[ "$COMMIT_MESSAGE" == "${{ env.PREPARATION_COMMIT }}" ]]; then
31+
prepared="true"
32+
fi
33+
34+
echo "prepared=$prepared" >> $GITHUB_OUTPUT
35+
36+
prepare-release:
37+
name: Prepare release
38+
needs: [check-preparation]
39+
if: ${{ needs.check-preparation.outputs.prepared == 'false' }}
40+
runs-on: ubuntu-latest
41+
steps:
42+
- name: Generate token for PyPSA Bot
43+
id: generate-token
44+
uses: actions/create-github-app-token@v2
45+
with:
46+
app-id: ${{ vars.PYPSA_BOT_ID }}
47+
private-key: ${{ secrets.PYPSA_BOT_PRIVATE_KEY }}
48+
49+
- uses: actions/checkout@v5
50+
with:
51+
fetch-depth: 0
52+
53+
- name: Find the branch for commit/ tag
54+
run: |
55+
branch=$(git branch -r --contains ${{ github.sha }} | grep -v 'HEAD' | head -n 1 | sed 's|origin/||' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
56+
echo "Branch found: $branch"
57+
echo "BRANCH_NAME=$branch" >> $GITHUB_ENV
58+
59+
- uses: actions/checkout@v5
60+
with:
61+
fetch-depth: 0
62+
ref: ${{ env.BRANCH_NAME }}
63+
token: ${{ steps.generate-token.outputs.token }}
64+
65+
- name: Setup conda environment
66+
uses: conda-incubator/setup-miniconda@v3
67+
with:
68+
miniforge-version: latest
69+
environment-file: ${{ env.BASE_ENV }}
70+
activate-environment: pypsa-eur
71+
channel-priority: strict
72+
73+
# Start of preparation script
74+
75+
- name: Update DAGs in documentation
76+
run: |
77+
conda run -n pypsa-eur make update-dags
78+
79+
# End of preparation script
80+
81+
- name: Remove previous tag
82+
run: |
83+
git tag -d ${{ github.ref_name }}
84+
git push origin --delete ${{ github.ref_name }}
85+
86+
- name: Commit changes
87+
uses: stefanzweifel/git-auto-commit-action@v7
88+
with:
89+
branch: ${{ env.BRANCH_NAME }}
90+
commit_message: '${{ env.PREPARATION_COMMIT }}'
91+
tagging_message: '${{ github.ref_name }}' # add tag again
92+
push_options: '${{ github.ref_name }}'
93+
add_options: '-u' # Never add untracked files

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,9 @@ reset:
109109
rm -r ./.snakemake || true; \
110110
echo "Reset completed." \
111111
) || echo "Reset cancelled."
112+
113+
# Update the DAGs in the documentation
114+
# use sed to remove everything up to 'Building DAG' outputs, e.g. from pulp/Gurobi before passing to dot
115+
update-dags:
116+
snakemake results/networks/base_s_128_elec_.nc -F --dag | sed -n "/digraph/,/}/p" | dot -Tpng -o doc/img/intro-workflow.png
117+
snakemake --rulegraph -F | sed -n "/digraph/,/}/p" | dot -Tpng -o doc/img/workflow.png

doc/release_notes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ Upcoming Release
7676
* Misc: Empty folders that are automatically generated by ``snakemake`` have been added to the repository, e.g. ``resources/`` and ``results/``.
7777
The ``purge`` rule now removes their contents but keeps the folders (https://github.com/PyPSA/pypsa-eur/pull/1764).
7878

79+
* Misc: Automatically update the DAGs shown in the documentation (https://github.com/PyPSA/pypsa-eur/pull/1880).
80+
7981
PyPSA-Eur v2025.07.0 (11th July 2025)
8082
=====================================
8183

0 commit comments

Comments
 (0)