Skip to content

Commit df123d1

Browse files
authored
fix: consolidate baseline artifacts before deploy (#106)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
1 parent 19339e6 commit df123d1

2 files changed

Lines changed: 48 additions & 44 deletions

File tree

.github/workflows/baseline.yml

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,44 @@ jobs:
5454
if: ${{ always() }}
5555
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
5656
with:
57-
name: baseline-${{ github.run_id }}-${{ matrix.order }}
57+
name: baseline-shard-${{ github.run_id }}-${{ matrix.order }}
58+
path: |
59+
results
60+
artifacts
61+
if-no-files-found: error
62+
retention-days: 1
63+
compression-level: 9
64+
65+
merge:
66+
needs: run
67+
runs-on: ubuntu-latest
68+
steps:
69+
- name: download baseline results
70+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
71+
with:
72+
pattern: baseline-shard-${{ github.run_id }}-*
73+
merge-multiple: true
74+
- name: merge baseline results
75+
run: |
76+
output_directory="$(dirname "$(find results -type f -name 'output-*.json' -print -quit)")"
77+
jq --slurp '
78+
. as $outputs
79+
| ([$outputs[].treatments[]] | unique_by(.config.name)) as $treatments
80+
| $outputs[0]
81+
| .treatments = $treatments
82+
| .results = [
83+
$outputs[] as $output
84+
| $output.results[]
85+
| . as $result
86+
| ($output.treatments[] | select(.id == $result.treatmentId).config.name) as $name
87+
| .treatmentId = ($treatments[] | select(.config.name == $name).id)
88+
]
89+
' "$output_directory"/output-*.json > "$output_directory/output.json"
90+
rm "$output_directory"/output-*.json
91+
- name: upload baseline results
92+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
93+
with:
94+
name: baseline-${{ github.run_id }}
5895
path: |
5996
results
6097
artifacts

.github/workflows/deploy.yml

Lines changed: 10 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -31,52 +31,19 @@ jobs:
3131
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
3232
with:
3333
ref: ${{ github.event.repository.default_branch }}
34-
- name: find latest baseline run
35-
id: baseline
34+
- name: download baseline results
3635
env:
3736
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 != ''
6137
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"
38+
gh api --paginate \
39+
"/repos/$GITHUB_REPOSITORY/actions/artifacts?per_page=100" \
40+
--jq '.artifacts[] | select(.expired == false and (.name | test("^baseline-[0-9]+$"))) | [.created_at, .id] | @tsv' |
41+
sort |
42+
cut -f2 |
43+
while read -r artifact_id; do
44+
gh api "/repos/$GITHUB_REPOSITORY/actions/artifacts/$artifact_id/zip" > "$RUNNER_TEMP/$artifact_id.zip"
45+
unzip -o -q "$RUNNER_TEMP/$artifact_id.zip"
46+
done
8047
- name: set up pnpm
8148
uses: pnpm/action-setup@0ebf47130e4866e96fce0953f49152a61190b271 # v6.0.9
8249
- name: set up Node.js

0 commit comments

Comments
 (0)