-
Notifications
You must be signed in to change notification settings - Fork 255
192 lines (170 loc) · 6.25 KB
/
Copy pathrun-refresh-pipeline.yml
File metadata and controls
192 lines (170 loc) · 6.25 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
name: Run Refresh Pipeline
on:
schedule:
# GitHub cron is evaluated in UTC. 03:00 UTC Monday == Sunday evening PT.
- cron: '0 3 * * 1'
workflow_dispatch:
inputs:
no_images:
description: Pass --no-images to the pipeline
type: boolean
required: false
default: false
allow_enrich_failures:
description: Pass --allow-enrich-failures to the pipeline
type: boolean
required: false
default: false
extra_args:
description: Extra args appended to run_pipeline.py (space-separated)
type: string
required: false
default: ''
permissions:
contents: write
pull-requests: write
concurrency:
group: weekly-pipeline-refresh
cancel-in-progress: true
jobs:
run-pipeline-and-open-pr:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1
persist-credentials: true
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Setup uv
uses: astral-sh/setup-uv@v3
with:
enable-cache: true
cache-dependency-glob: requirements.txt
- name: Create venv and install deps (uv)
run: |
set -euo pipefail
uv venv .venv
uv pip install -r requirements.txt
- name: Run pipeline
id: pipeline
env:
# The pipeline scripts fall back to GITHUB_TOKEN for GitHub enrichment auth.
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NO_IMAGES: ${{ github.event.inputs.no_images || 'false' }}
ALLOW_ENRICH_FAILURES: ${{ github.event.inputs.allow_enrich_failures || 'false' }}
EXTRA_ARGS: ${{ github.event.inputs.extra_args || '' }}
run: |
set -euo pipefail
ARGS=()
if [[ "${NO_IMAGES}" == "true" ]]; then ARGS+=("--no-images"); fi
if [[ "${ALLOW_ENRICH_FAILURES}" == "true" ]]; then ARGS+=("--allow-enrich-failures"); fi
if [[ -n "${EXTRA_ARGS}" ]]; then
# EXTRA_ARGS is documented as space-separated.
read -r -a EXTRA_ARGS_ARRAY <<< "${EXTRA_ARGS}"
ARGS+=("${EXTRA_ARGS_ARRAY[@]}")
fi
echo "pipeline_args=${ARGS[*]}" >> "${GITHUB_OUTPUT}"
.venv/bin/python ./directory/scripts/run_pipeline.py --enrich-progress-every 10 "${ARGS[@]}"
- name: Detect changes
id: changes
run: |
set -euo pipefail
if [[ -n "$(git status --porcelain)" ]]; then
echo "has_changes=true" >> "${GITHUB_OUTPUT}"
else
echo "has_changes=false" >> "${GITHUB_OUTPUT}"
fi
DATE_PT="$(TZ=America/Los_Angeles date +%Y-%m-%d)"
BRANCH="automation/weekly-pipeline-refresh-${DATE_PT}"
echo "date_pt=${DATE_PT}" >> "${GITHUB_OUTPUT}"
echo "branch=${BRANCH}" >> "${GITHUB_OUTPUT}"
- name: Create branch and commit
if: steps.changes.outputs.has_changes == 'true'
env:
BRANCH: ${{ steps.changes.outputs.branch }}
run: |
set -euo pipefail
git config user.name "component-template-bot"
git config user.email "component-template-bot@users.noreply.github.com"
git checkout -B "${BRANCH}"
git add -A directory/
git commit -m "chore: weekly pipeline refresh"
git push --force-with-lease origin "${BRANCH}"
- name: Create or update PR
if: steps.changes.outputs.has_changes == 'true'
id: pr
uses: actions/github-script@v8
env:
BRANCH: ${{ steps.changes.outputs.branch }}
DATE_PT: ${{ steps.changes.outputs.date_pt }}
PIPELINE_ARGS: ${{ steps.pipeline.outputs.pipeline_args }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
const branch = process.env.BRANCH;
const datePt = process.env.DATE_PT;
const pipelineArgs = (process.env.PIPELINE_ARGS || "").trim();
const { data: repoInfo } = await github.rest.repos.get({ owner, repo });
const base = repoInfo.default_branch;
const head = `${owner}:${branch}`;
const title = `chore: weekly pipeline refresh (${datePt})`;
const bodyLines = [
"Automated weekly refresh of the component gallery pipeline outputs.",
"",
`Command: \`.venv/bin/python ./directory/scripts/run_pipeline.py --enrich-progress-every 10${pipelineArgs ? " " + pipelineArgs : ""}\``,
"",
"This PR was created by a scheduled GitHub Actions workflow.",
];
const body = bodyLines.join("\n");
const existing = await github.rest.pulls.list({
owner,
repo,
head,
state: "open",
});
let pr;
if (existing.data.length > 0) {
pr = existing.data[0];
await github.rest.pulls.update({
owner,
repo,
pull_number: pr.number,
title,
body,
});
} else {
const created = await github.rest.pulls.create({
owner,
repo,
title,
head: branch,
base,
body,
draft: false,
});
pr = created.data;
}
core.setOutput("pr_url", pr.html_url);
core.setOutput("pr_number", String(pr.number));
- name: Summary
env:
HAS_CHANGES: ${{ steps.changes.outputs.has_changes }}
BRANCH: ${{ steps.changes.outputs.branch }}
PR_URL: ${{ steps.pr.outputs.pr_url }}
run: |
{
echo "## Weekly pipeline refresh";
echo "- has changes: ${HAS_CHANGES}";
echo "- branch: ${BRANCH}";
if [ "${HAS_CHANGES}" = "true" ]; then
echo "- PR: ${PR_URL:-n/a}";
else
echo "- PR: n/a (no changes detected)";
fi
} >> "$GITHUB_STEP_SUMMARY"