Skip to content

Commit 6194e5c

Browse files
Merge pull request #1657 from priyanshuone6/auto_baseline
Automate baseline in vcpkg-config
2 parents 0612406 + da20012 commit 6194e5c

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Update vcpkg-configuration baseline
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
paths:
8+
- vcpkg-configuration.json
9+
schedule:
10+
# Run at 3 am UTC on 20th every month
11+
- cron: 0 3 20 * *
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
python-version: [3.8]
19+
20+
steps:
21+
- uses: actions/checkout@v2
22+
- name: Set up Python ${{ matrix.python-version }}
23+
uses: actions/setup-python@v2
24+
with:
25+
python-version: ${{ matrix.python-version }}
26+
- name: Install dependencies
27+
run: |
28+
pip install wheel
29+
pip install --editable .
30+
- name: Update baseline
31+
run: python scripts/update_vcpkg_baseline.py
32+
- name: Create Pull Request
33+
uses: peter-evans/create-pull-request@v3
34+
with:
35+
delete-branch: true
36+
branch-suffix: short-commit-hash
37+
commit-message: update baseline
38+
title: Update vcpkg-configuration.json baseline
39+
body: |
40+
Update baseline of vcpkg-configuration.json with the latest commit id
41+
42+
Auto-generated pull request

scripts/update_vcpkg_baseline.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""
2+
Automatically update the baseline of vcpkg-configuration.json
3+
"""
4+
5+
import json
6+
import os
7+
8+
import pybamm
9+
10+
11+
def update_baseline():
12+
"""
13+
Opens vcpkg-configuration.json and updates the baseline with the latest commit id
14+
"""
15+
# Get latest commit id from pybamm-team/sundials-vcpkg-registry
16+
cmd = "git ls-remote https://github.com/pybamm-team/sundials-vcpkg-registry | grep refs/heads/main | cut -f 1 | tr -d '\n'" # noqa: E501
17+
commit_id = os.popen(cmd).read()
18+
19+
# Open file and write it
20+
with open(
21+
os.path.join(pybamm.root_dir(), "vcpkg-configuration.json"), "r+"
22+
) as file:
23+
output = file.read()
24+
json_commit_id = json.loads(output)["registries"][0]["baseline"]
25+
output = output.replace(json_commit_id, commit_id)
26+
file.truncate(0)
27+
file.seek(0)
28+
file.write(output)
29+
30+
31+
if __name__ == "__main__":
32+
update_baseline()

0 commit comments

Comments
 (0)