1212 commit_start :
1313 description : " Identifier of commit from which to start"
1414 default : " v0.1.0"
15+ type : string
16+ pattern : ' ^[a-zA-Z0-9._-]+$'
1517 commit_end :
1618 description : " Identifier of commit at which to end"
1719 default : " develop"
20+ type : string
21+ pattern : ' ^[a-zA-Z0-9._-]+$'
1822 ncommits :
1923 description : " Number of commits to benchmark between commit_start and commit_end"
2024 default : " 100"
25+ type : string
26+ pattern : ' ^[0-9]+$'
27+
28+
29+ permissions : {}
2130
2231env :
2332 PYBAMM_DISABLE_TELEMETRY : " true"
2433
2534jobs :
2635 benchmarks :
2736 runs-on : ubuntu-latest
37+ permissions :
38+ contents : read
2839 steps :
2940 - uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
41+ with :
42+ persist-credentials : false
3043 - name : Set up Python 3.12
3144 uses : actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0
3245 with :
@@ -43,11 +56,65 @@ jobs:
4356 run : |
4457 git fetch origin develop:develop
4558
59+ - name : Validate commit_start
60+ id : validate_start
61+ uses : actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
62+ with :
63+ script : |
64+ const input = context.payload.inputs.commit_start;
65+ if (!input || !/^[a-zA-Z0-9._-]+$/.test(input)) {
66+ core.setFailed('Invalid commit_start format');
67+ return;
68+ }
69+ core.setOutput('commit_start', input);
70+
71+ - name : Validate commit_end
72+ id : validate_end
73+ uses : actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
74+ with :
75+ script : |
76+ const input = context.payload.inputs.commit_end;
77+ if (!input || !/^[a-zA-Z0-9._-]+$/.test(input)) {
78+ core.setFailed('Invalid commit_end format');
79+ return;
80+ }
81+ core.setOutput('commit_end', input);
82+
83+ - name : Validate ncommits
84+ id : validate_ncommits
85+ uses : actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
86+ with :
87+ script : |
88+ const input = context.payload.inputs.ncommits;
89+ if (!input || !/^[0-9]+$/.test(input)) {
90+ core.setFailed('Invalid ncommits format');
91+ return;
92+ }
93+ const numValue = parseInt(input, 10);
94+ if (numValue < 1 || numValue > 10000) {
95+ core.setFailed('ncommits must be between 1 and 10000');
96+ return;
97+ }
98+ if (numValue > 5000) {
99+ core.warning('Processing a large number of commits. This may take a while....');
100+ }
101+ core.setOutput('ncommits', numValue.toString());
102+
103+ - name : Set environment variables
104+ env :
105+ COMMIT_START : ${{ steps.validate_start.outputs.commit_start }}
106+ COMMIT_END : ${{ steps.validate_end.outputs.commit_end }}
107+ NCOMMITS : ${{ steps.validate_ncommits.outputs.ncommits }}
108+ run : |
109+ echo "COMMIT_START=$COMMIT_START" >> $GITHUB_ENV
110+ echo "COMMIT_END=$COMMIT_END" >> $GITHUB_ENV
111+ echo "NCOMMITS=$NCOMMITS" >> $GITHUB_ENV
112+
46113 - name : Run benchmarks
47114 run : |
48115 asv machine --machine "GitHubRunner"
49- asv run -m "GitHubRunner" -s ${{ github.event.inputs.ncommits }} \
50- ${{ github.event.inputs.commit_start }}..${{ github.event.inputs.commit_end }}
116+ asv run -m "GitHubRunner" -s ${{ env.NCOMMITS }} \
117+ ${{ env.COMMIT_START }}..${{ env.COMMIT_END }}
51118
52119 - name : Upload results as artifact
53120 uses : actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
@@ -57,10 +124,12 @@ jobs:
57124 if-no-files-found : error
58125
59126 publish-results :
60- if : github.repository_owner == 'pybamm-team'
127+ if : github.repository == 'pybamm-team/PyBaMM '
61128 name : Push and publish results
62129 needs : benchmarks
63130 runs-on : ubuntu-latest
131+ permissions :
132+ contents : write
64133 steps :
65134 - name : Set up Python 3.12
66135 uses : actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0
@@ -75,12 +144,13 @@ jobs:
75144 with :
76145 repository : pybamm-team/pybamm-bench
77146 token : ${{ secrets.BENCH_PAT }}
147+ persist-credentials : false
78148
79149 - name : Download results artifact(s)
80- uses : actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1
150+ uses : actions/download-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
81151 with :
152+ name : asv_over_history_results
82153 path : results
83- merge-multiple : true
84154
85155 - name : Copy new results and push to pybamm-bench repo
86156 env :
95165
96166 - name : Publish results
97167 run : |
98- asv publish
99168 git fetch origin gh-pages:gh-pages
100169 asv gh-pages
0 commit comments