Skip to content

Commit 19339e6

Browse files
authored
chore: store baseline results as artifacts (#105)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 8dc5f9f6-11f0-4bb0-8127-bd3eb03316a1
1 parent be0a9d7 commit 19339e6

3 files changed

Lines changed: 61 additions & 53 deletions

File tree

.github/workflows/baseline.yml

Lines changed: 3 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ concurrency:
99
cancel-in-progress: false
1010

1111
permissions:
12-
contents: write
13-
pull-requests: write
12+
contents: read
1413

1514
jobs:
1615
setup:
@@ -60,54 +59,5 @@ jobs:
6059
results
6160
artifacts
6261
if-no-files-found: error
63-
64-
publish:
65-
needs: [setup, run]
66-
runs-on: ubuntu-latest
67-
steps:
68-
- name: create github app token
69-
id: app-token
70-
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
71-
with:
72-
app-id: ${{ vars.PRIMER_APP_ID_SHARED }}
73-
private-key: ${{ secrets.PRIMER_APP_PRIVATE_KEY_SHARED }}
74-
- name: checkout repository
75-
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
76-
with:
77-
fetch-depth: 0
78-
ref: ${{ github.event.repository.default_branch }}
79-
token: ${{ steps.app-token.outputs.token }}
80-
- name: download baseline results
81-
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
82-
with:
83-
pattern: baseline-${{ github.run_id }}-*
84-
merge-multiple: true
85-
- name: merge baseline results
86-
env:
87-
RUN_DATE: ${{ needs.setup.outputs.run-date }}
88-
run: |
89-
jq --slurp \
90-
'.[0] + {treatments: [.[].treatments[]], results: [.[].results[]]}' \
91-
results/"$RUN_DATE"/output-*.json > results/"$RUN_DATE"/output.json
92-
rm results/"$RUN_DATE"/output-*.json
93-
- name: open baseline results pull request
94-
env:
95-
GH_TOKEN: ${{ steps.app-token.outputs.token }}
96-
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
97-
RUN_DATE: ${{ needs.setup.outputs.run-date }}
98-
run: |
99-
git config user.name "github-actions[bot]"
100-
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
101-
git add results
102-
if git diff --cached --quiet; then
103-
exit 0
104-
fi
105-
branch="chore/baseline-$RUN_DATE"
106-
git checkout -b "$branch"
107-
git commit -m "chore: record baseline results for $RUN_DATE"
108-
git push origin "$branch"
109-
gh pr create \
110-
--base "$DEFAULT_BRANCH" \
111-
--head "$branch" \
112-
--title "chore: record baseline results for $RUN_DATE" \
113-
--body "Automated weekly baseline results for $RUN_DATE."
62+
retention-days: 90
63+
compression-level: 9

.github/workflows/deploy.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,17 @@ on:
33
push:
44
branches:
55
- main
6+
workflow_run:
7+
workflows:
8+
- baseline
9+
types:
10+
- completed
11+
branches:
12+
- main
613
workflow_dispatch:
714

815
permissions:
16+
actions: read
917
contents: read
1018
pages: write
1119
id-token: write
@@ -16,10 +24,59 @@ concurrency:
1624

1725
jobs:
1826
build:
27+
if: github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success'
1928
runs-on: ubuntu-latest
2029
steps:
2130
- name: checkout repository
2231
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
32+
with:
33+
ref: ${{ github.event.repository.default_branch }}
34+
- name: find latest baseline run
35+
id: baseline
36+
env:
37+
GH_TOKEN: ${{ github.token }}
38+
WORKFLOW_RUN_ID: ${{ github.event.workflow_run.id }}
39+
run: |
40+
run_id="$WORKFLOW_RUN_ID"
41+
if [[ -z "$run_id" ]]; then
42+
run_id="$(gh run list \
43+
--workflow baseline.yml \
44+
--branch "${{ github.event.repository.default_branch }}" \
45+
--status success \
46+
--limit 1 \
47+
--json databaseId \
48+
--jq '.[0].databaseId // empty')"
49+
fi
50+
echo "run-id=$run_id" >> "$GITHUB_OUTPUT"
51+
- name: download baseline results
52+
if: steps.baseline.outputs.run-id != ''
53+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
54+
with:
55+
pattern: baseline-${{ steps.baseline.outputs.run-id }}*
56+
merge-multiple: true
57+
run-id: ${{ steps.baseline.outputs.run-id }}
58+
github-token: ${{ github.token }}
59+
- name: merge baseline results
60+
if: steps.baseline.outputs.run-id != ''
61+
run: |
62+
shard_output="$(find results -type f -name 'output-*.json' -print -quit)"
63+
if [[ -z "$shard_output" ]]; then
64+
exit 0
65+
fi
66+
output_directory="$(dirname "$shard_output")"
67+
jq --slurp '
68+
. as $outputs
69+
| ([$outputs[].treatments[]] | unique_by(.config.name)) as $treatments
70+
| $outputs[0]
71+
| .treatments = $treatments
72+
| .results = [
73+
$outputs[] as $output
74+
| $output.results[]
75+
| . as $result
76+
| ($output.treatments[] | select(.id == $result.treatmentId).config.name) as $name
77+
| .treatmentId = ($treatments[] | select(.config.name == $name).id)
78+
]
79+
' "$output_directory"/output-*.json > "$output_directory/output.json"
2380
- name: set up pnpm
2481
uses: pnpm/action-setup@0ebf47130e4866e96fce0953f49152a61190b271 # v6.0.9
2582
- name: set up Node.js

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ out
3030

3131
# Generated files
3232
artifacts/
33+
results/

0 commit comments

Comments
 (0)