Repository navigation
113 lines (99 loc) · 4.71 KB
/
Copy pathmodels-update.yml
File metadata and controls
113 lines (99 loc) · 4.71 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
name: models-update
permissions:
contents: read
concurrency:
group: update-models
cancel-in-progress: false
on:
workflow_dispatch:
schedule:
# Weekly, Monday 06:00 UTC.
- cron: "0 6 * * 1"
jobs:
refresh-snapshot:
timeout-minutes: 20
if: github.repository == 'docker/docker-agent'
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
# Restore-only: reuses the cache ci's test-linux job saves on main.
- uses: $/.github/actions/setup-go
with:
cache-name: test-linux
- name: Refresh models.dev snapshot
run: task update-models
- name: Compute catalog delta
id: delta
continue-on-error: true
run: |
set -euo pipefail
task models-delta -- --json-out "${RUNNER_TEMP}/delta.json" > "${RUNNER_TEMP}/delta.md"
added=$(jq '.added | length' "${RUNNER_TEMP}/delta.json")
removed=$(jq '.removed | length' "${RUNNER_TEMP}/delta.json")
changed=$(jq '.changed | length' "${RUNNER_TEMP}/delta.json")
if [ "$added" -eq 0 ] && [ "$removed" -eq 0 ] && [ "$changed" -eq 0 ]; then
# Only snapshot_date.txt moved: preserve today's behaviour and still
# open a PR, with a fallback subject/body instead of a rendered delta.
echo "subject=chore: refresh models.dev snapshot (no catalog changes)" >> "$GITHUB_OUTPUT"
{
echo "Automated refresh of the models.dev catalog snapshot embedded in the"
echo "docker-agent binary (\`pkg/modelsdev/snapshot.json\`)."
echo
echo "Only \`pkg/modelsdev/snapshot_date.txt\` changed; the catalog content is unchanged."
echo
echo "Generated by \`task update-models\`."
} > "${RUNNER_TEMP}/pr-body.md"
else
echo "subject=chore: refresh models.dev snapshot (+${added} -${removed} ~${changed})" >> "$GITHUB_OUTPUT"
# Guard the PR body: an unusually large delta gets truncated, never dropped.
if [ "$(wc -c < "${RUNNER_TEMP}/delta.md")" -gt 60000 ]; then
head -c 60000 "${RUNNER_TEMP}/delta.md" > "${RUNNER_TEMP}/delta.trunc.md"
printf '\n\n_(delta truncated at 60 kB)_\n' >> "${RUNNER_TEMP}/delta.trunc.md"
mv "${RUNNER_TEMP}/delta.trunc.md" "${RUNNER_TEMP}/delta.md"
fi
{
echo "Automated refresh of the models.dev catalog snapshot embedded in the"
echo "docker-agent binary (\`pkg/modelsdev/snapshot.json\`)."
echo
cat "${RUNNER_TEMP}/delta.md"
echo
echo "Generated by \`task update-models\`."
} > "${RUNNER_TEMP}/pr-body.md"
fi
- name: Fall back to a static PR body if the delta step failed
if: steps.delta.outcome != 'success'
id: delta-fallback
run: |
set -euo pipefail
echo "::warning::Computing the catalog delta failed; the refresh still proceeds with a static PR description."
echo "subject=chore: refresh models.dev snapshot" >> "$GITHUB_OUTPUT"
{
echo "Automated refresh of the models.dev catalog snapshot embedded in the"
echo "docker-agent binary (\`pkg/modelsdev/snapshot.json\`)."
echo
echo "Computing the catalog delta failed this run — see the \"Compute catalog"
echo "delta\" step log for details. Generated by \`task update-models\`."
} > "${RUNNER_TEMP}/pr-body.md"
- name: Create pull request
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
with:
# sign-commits builds the commit through GitHub's API instead of a
# local `git push`, so it's Verified regardless of which token is
# used. On the default GITHUB_TOKEN (github.token, the default for
# `token:` below) the commit author/committer is github-actions[bot]
# rather than whoever triggered the run.
token: ${{ github.token }}
sign-commits: true
commit-message: ${{ steps.delta.outcome == 'success' && steps.delta.outputs.subject || steps.delta-fallback.outputs.subject }}
title: ${{ steps.delta.outcome == 'success' && steps.delta.outputs.subject || steps.delta-fallback.outputs.subject }}
body-path: ${{ runner.temp }}/pr-body.md
branch: chore/update-models-snapshot
delete-branch: true
add-paths: |
pkg/modelsdev/snapshot.json
pkg/modelsdev/snapshot_date.txt