forked from PyPSA/PyPSA
-
Notifications
You must be signed in to change notification settings - Fork 0
174 lines (148 loc) · 5.36 KB
/
release.yml
File metadata and controls
174 lines (148 loc) · 5.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# SPDX-FileCopyrightText: PyPSA Contributors
#
# SPDX-License-Identifier: MIT
name: Release
on:
push:
tags:
- v*.*.*
env:
PREPARATION_COMMIT: '[github-actions.ci] prepare release ${{ github.ref_name }}'
jobs:
check-preparation:
name: Check if release is prepared
runs-on: ubuntu-latest
outputs:
prepared: ${{ steps.validate.outputs.prepared }}
steps:
- uses: actions/checkout@v6
- name: Validate commit message
id: validate
run: |
# Check if last commit is the expected commit message
COMMIT_MESSAGE=$(git log -1 --pretty=%B)
echo "Expected: '${{ env.PREPARATION_COMMIT }}'"
echo "Received: '$COMMIT_MESSAGE'"
prepared="false"
if [[ "$COMMIT_MESSAGE" == "${{ env.PREPARATION_COMMIT }}" ]]; then
prepared="true"
fi
echo "prepared=$prepared" >> $GITHUB_OUTPUT
prepare-release:
name: Prepare release
needs: [check-preparation]
if: ${{ needs.check-preparation.outputs.prepared == 'false' }}
runs-on: ubuntu-latest
steps:
- name: Generate token for PyPSA Bot
id: generate-token
uses: actions/create-github-app-token@v2
with:
app-id: ${{ vars.PYPSA_BOT_ID }}
private-key: ${{ secrets.PYPSA_BOT_PRIVATE_KEY }}
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Find the branch for commit/ tag
run: |
branch=$(git branch -r --contains ${{ github.sha }} | grep -v 'HEAD' | head -n 1 | sed 's|origin/||' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
echo "Branch found: $branch"
echo "BRANCH_NAME=$branch" >> $GITHUB_ENV
- uses: actions/checkout@v6
with:
fetch-depth: 0
ref: ${{ env.BRANCH_NAME }}
token: ${{ steps.generate-token.outputs.token }}
# Start of preparation script
- uses: actions/setup-python@v6
with:
python-version: 3.12
- name: Install packages
run: |
python -m pip install uv
uv pip install --system toml
uv pip install --system setuptools_scm
uv pip install --system .
- name: Update CITATION.cff
run: |
import re
from setuptools_scm import get_version
version = get_version()
with open('CITATION.cff', 'r') as file:
cff_content = file.read()
cff_content = open('CITATION.cff', 'r').read()
updated_cff_content = re.sub(r"(?<=version: ).+(?= #)",version,cff_content,flags=re.MULTILINE)
with open('CITATION.cff', 'w') as file:
file.write(updated_cff_content)
shell: python
- name: Update example notebooks
run: |
import pypsa
# ac-dc-meshed
n = pypsa.Network("examples/networks/ac-dc-meshed/ac-dc-meshed")
n.export_to_csv_folder("examples/networks/ac-dc-meshed/ac-dc-meshed")
n.export_to_netcdf("examples/networks/ac-dc-meshed/ac-dc-meshed.nc")
# storage-hvdc
n = pypsa.Network("examples/networks/storage-hvdc/storage-hvdc")
n.export_to_csv_folder("examples/networks/storage-hvdc/storage-hvdc")
n.export_to_netcdf("examples/networks/storage-hvdc/storage-hvdc.nc")
# scigrid-de
n = pypsa.Network("examples/networks/scigrid-de/scigrid-de")
n.export_to_csv_folder("examples/networks/scigrid-de/scigrid-de")
n.export_to_netcdf("examples/networks/scigrid-de/scigrid-de.nc")
# model-energy
n = pypsa.Network("examples/networks/model-energy/model-energy")
n.export_to_csv_folder("examples/networks/model-energy/model-energy")
n.export_to_netcdf("examples/networks/model-energy/model-energy.nc")
# stochastic-network
n = pypsa.Network("examples/networks/stochastic-network/stochastic-network.nc")
n.export_to_netcdf("examples/networks/stochastic-network/stochastic-network.nc")
shell: python
# End of preparation script
- name: Remove previous tag
run: |
git tag -d ${{ github.ref_name }}
git push origin --delete ${{ github.ref_name }}
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v7
with:
branch: ${{ env.BRANCH_NAME }}
commit_message: '${{ env.PREPARATION_COMMIT }}'
tagging_message: '${{ github.ref_name }}' # add tag again
push_options: '${{ github.ref_name }}'
add_options: '-u' # Never add untracked files
build:
name: Build and verify package
needs: [check-preparation]
if: ${{ needs.check-preparation.outputs.prepared == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: hynek/build-and-inspect-python-package@v2
release:
name: Create GitHub release
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: softprops/action-gh-release@v2
with:
body: |
Revised release notes are available in the [documentation](https://docs.pypsa.org/latest/release-notes/).
append_body: true
generate_release_notes: true
publish:
name: Publish to PyPI
needs: [build]
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/project/${{ github.event.repository.name }}
permissions:
id-token: write
steps:
- uses: actions/download-artifact@v7
with:
name: Packages
path: dist
- uses: pypa/gh-action-pypi-publish@release/v1