Skip to content

Commit a2ea272

Browse files
committed
[feat] Add GH Workflows
1 parent 0c7c242 commit a2ea272

3 files changed

Lines changed: 237 additions & 0 deletions

File tree

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
name: Run Refresh Pipeline
2+
3+
on:
4+
schedule:
5+
# GitHub cron is evaluated in UTC. 03:00 UTC Monday == Sunday evening PT.
6+
- cron: "0 3 * * 1"
7+
workflow_dispatch:
8+
inputs:
9+
no_images:
10+
description: Pass --no-images to the pipeline
11+
type: boolean
12+
required: false
13+
default: false
14+
allow_enrich_failures:
15+
description: Pass --allow-enrich-failures to the pipeline
16+
type: boolean
17+
required: false
18+
default: true
19+
extra_args:
20+
description: Extra args appended to run_pipeline.py (space-separated)
21+
type: string
22+
required: false
23+
default: ""
24+
25+
permissions:
26+
contents: write
27+
pull-requests: write
28+
29+
concurrency:
30+
group: weekly-pipeline-refresh
31+
cancel-in-progress: true
32+
33+
jobs:
34+
run-pipeline-and-open-pr:
35+
runs-on: ubuntu-latest
36+
timeout-minutes: 15
37+
38+
steps:
39+
- name: Checkout repository
40+
uses: actions/checkout@v6
41+
with:
42+
fetch-depth: 1
43+
persist-credentials: true
44+
45+
- name: Set up uv
46+
uses: astral-sh/setup-uv@v7
47+
with:
48+
python-version: "3.12"
49+
50+
- name: Install dependencies
51+
run: uv sync --locked
52+
53+
- name: Run pipeline
54+
id: pipeline
55+
env:
56+
# The pipeline scripts fall back to GITHUB_TOKEN for GitHub enrichment auth.
57+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
58+
NO_IMAGES: ${{ github.event.inputs.no_images || 'false' }}
59+
ALLOW_ENRICH_FAILURES: ${{ github.event.inputs.allow_enrich_failures || 'true' }}
60+
EXTRA_ARGS: ${{ github.event.inputs.extra_args || '' }}
61+
run: |
62+
set -euo pipefail
63+
64+
ARGS=()
65+
if [[ "${NO_IMAGES}" == "true" ]]; then ARGS+=("--no-images"); fi
66+
if [[ "${ALLOW_ENRICH_FAILURES}" == "true" ]]; then ARGS+=("--allow-enrich-failures"); fi
67+
if [[ -n "${EXTRA_ARGS}" ]]; then
68+
# EXTRA_ARGS is documented as space-separated.
69+
read -r -a EXTRA_ARGS_ARRAY <<< "${EXTRA_ARGS}"
70+
ARGS+=("${EXTRA_ARGS_ARRAY[@]}")
71+
fi
72+
echo "pipeline_args=${ARGS[*]}" >> "${GITHUB_OUTPUT}"
73+
74+
uv run python components/registry/scripts/run_pipeline.py --enrich-progress-every 10 "${ARGS[@]}"
75+
76+
- name: Detect changes (and run pre-commit if needed)
77+
id: changes
78+
run: |
79+
set -euo pipefail
80+
81+
HAS_CHANGES_BEFORE="false"
82+
if [[ -n "$(git status --porcelain)" ]]; then
83+
HAS_CHANGES_BEFORE="true"
84+
fi
85+
86+
if [[ "${HAS_CHANGES_BEFORE}" == "true" ]]; then
87+
echo "Changes detected; running pre-commit on all files."
88+
# Run twice: first pass may auto-fix and exit non-zero; second pass must be clean.
89+
uv run pre-commit run --all-files || true
90+
uv run pre-commit run --all-files
91+
fi
92+
93+
if [[ -n "$(git status --porcelain)" ]]; then
94+
echo "has_changes=true" >> "${GITHUB_OUTPUT}"
95+
else
96+
echo "has_changes=false" >> "${GITHUB_OUTPUT}"
97+
fi
98+
99+
DATE_PT="$(TZ=America/Los_Angeles date +%Y-%m-%d)"
100+
BRANCH="automation/weekly-pipeline-refresh-${DATE_PT}"
101+
echo "date_pt=${DATE_PT}" >> "${GITHUB_OUTPUT}"
102+
echo "branch=${BRANCH}" >> "${GITHUB_OUTPUT}"
103+
104+
- name: Create branch and commit
105+
if: steps.changes.outputs.has_changes == 'true'
106+
env:
107+
BRANCH: ${{ steps.changes.outputs.branch }}
108+
run: |
109+
set -euo pipefail
110+
git config user.name "Streamlit Bot"
111+
git config user.email "core+streamlitbot-github@streamlit.io"
112+
113+
git checkout -B "${BRANCH}"
114+
git add -A components/registry/
115+
git commit -m "[chore] Weekly pipeline refresh"
116+
git push --force-with-lease origin "${BRANCH}"
117+
118+
- name: Create or update PR
119+
if: steps.changes.outputs.has_changes == 'true'
120+
id: pr
121+
uses: actions/github-script@v8
122+
env:
123+
BRANCH: ${{ steps.changes.outputs.branch }}
124+
DATE_PT: ${{ steps.changes.outputs.date_pt }}
125+
PIPELINE_ARGS: ${{ steps.pipeline.outputs.pipeline_args }}
126+
with:
127+
github-token: ${{ secrets.GITHUB_TOKEN }}
128+
script: |
129+
const owner = context.repo.owner;
130+
const repo = context.repo.repo;
131+
const branch = process.env.BRANCH;
132+
const datePt = process.env.DATE_PT;
133+
const pipelineArgs = (process.env.PIPELINE_ARGS || "").trim();
134+
135+
const { data: repoInfo } = await github.rest.repos.get({ owner, repo });
136+
const base = repoInfo.default_branch;
137+
const head = `${owner}:${branch}`;
138+
139+
const title = `chore: weekly pipeline refresh (${datePt})`;
140+
const bodyLines = [
141+
"Automated weekly refresh of the component gallery pipeline outputs.",
142+
"",
143+
`Command: \`uv run python components/registry/scripts/run_pipeline.py --enrich-progress-every 10${pipelineArgs ? " " + pipelineArgs : ""}\``,
144+
"",
145+
"This PR was created by a scheduled GitHub Actions workflow.",
146+
];
147+
const body = bodyLines.join("\n");
148+
149+
const existing = await github.rest.pulls.list({
150+
owner,
151+
repo,
152+
head,
153+
state: "open",
154+
});
155+
156+
let pr;
157+
if (existing.data.length > 0) {
158+
pr = existing.data[0];
159+
await github.rest.pulls.update({
160+
owner,
161+
repo,
162+
pull_number: pr.number,
163+
title,
164+
body,
165+
});
166+
} else {
167+
const created = await github.rest.pulls.create({
168+
owner,
169+
repo,
170+
title,
171+
head: branch,
172+
base,
173+
body,
174+
draft: false,
175+
});
176+
pr = created.data;
177+
}
178+
179+
core.setOutput("pr_url", pr.html_url);
180+
core.setOutput("pr_number", String(pr.number));
181+
182+
- name: Summary
183+
env:
184+
HAS_CHANGES: ${{ steps.changes.outputs.has_changes }}
185+
BRANCH: ${{ steps.changes.outputs.branch }}
186+
PR_URL: ${{ steps.pr.outputs.pr_url }}
187+
run: |
188+
{
189+
echo "## Weekly pipeline refresh";
190+
echo "- has changes: ${HAS_CHANGES}";
191+
echo "- branch: ${BRANCH}";
192+
if [ "${HAS_CHANGES}" = "true" ]; then
193+
echo "- PR: ${PR_URL:-n/a}";
194+
else
195+
echo "- PR: n/a (no changes detected)";
196+
fi
197+
} >> "$GITHUB_STEP_SUMMARY"
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Validate Component Definitions
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- "components/registry/components/**"
7+
- "components/registry/schemas/**"
8+
- "components/registry/scripts/**"
9+
- "pyproject.toml"
10+
- "uv.lock"
11+
- ".github/workflows/validate-component-definitions.yml"
12+
13+
jobs:
14+
validate-submissions:
15+
name: Validate Component Definitions
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v6
21+
22+
- name: Set up uv
23+
uses: astral-sh/setup-uv@v7
24+
with:
25+
python-version: "3.12"
26+
27+
- name: Install dependencies
28+
run: uv sync --locked --no-dev
29+
30+
- name: Validate Component Definitions
31+
run: |
32+
set -euo pipefail
33+
uv run python components/registry/scripts/validate.py

.pre-commit-config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,10 @@ repos:
2828
additional_dependencies: ["prettier@3.8.1"]
2929
entry: prettier --write
3030
files: "\\.json$"
31+
32+
- id: prettier-yaml
33+
name: prettier (yaml)
34+
language: node
35+
additional_dependencies: ["prettier@3.8.1"]
36+
entry: prettier --write
37+
files: "\\.(ya?ml)$"

0 commit comments

Comments
 (0)