Skip to content

Commit 782fed3

Browse files
committed
[feat] Add GH Workflows
1 parent 3a189b4 commit 782fed3

3 files changed

Lines changed: 224 additions & 0 deletions

File tree

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
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: false
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 --no-dev
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 || 'false' }}
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
77+
id: changes
78+
run: |
79+
set -euo pipefail
80+
if [[ -n "$(git status --porcelain)" ]]; then
81+
echo "has_changes=true" >> "${GITHUB_OUTPUT}"
82+
else
83+
echo "has_changes=false" >> "${GITHUB_OUTPUT}"
84+
fi
85+
86+
DATE_PT="$(TZ=America/Los_Angeles date +%Y-%m-%d)"
87+
BRANCH="automation/weekly-pipeline-refresh-${DATE_PT}"
88+
echo "date_pt=${DATE_PT}" >> "${GITHUB_OUTPUT}"
89+
echo "branch=${BRANCH}" >> "${GITHUB_OUTPUT}"
90+
91+
- name: Create branch and commit
92+
if: steps.changes.outputs.has_changes == 'true'
93+
env:
94+
BRANCH: ${{ steps.changes.outputs.branch }}
95+
run: |
96+
set -euo pipefail
97+
git config user.name "Streamlit Bot"
98+
git config user.email "core+streamlitbot-github@streamlit.io"
99+
100+
git checkout -B "${BRANCH}"
101+
git add -A components/registry/
102+
git commit -m "[chore] Weekly pipeline refresh"
103+
git push --force-with-lease origin "${BRANCH}"
104+
105+
- name: Create or update PR
106+
if: steps.changes.outputs.has_changes == 'true'
107+
id: pr
108+
uses: actions/github-script@v8
109+
env:
110+
BRANCH: ${{ steps.changes.outputs.branch }}
111+
DATE_PT: ${{ steps.changes.outputs.date_pt }}
112+
PIPELINE_ARGS: ${{ steps.pipeline.outputs.pipeline_args }}
113+
with:
114+
github-token: ${{ secrets.GITHUB_TOKEN }}
115+
script: |
116+
const owner = context.repo.owner;
117+
const repo = context.repo.repo;
118+
const branch = process.env.BRANCH;
119+
const datePt = process.env.DATE_PT;
120+
const pipelineArgs = (process.env.PIPELINE_ARGS || "").trim();
121+
122+
const { data: repoInfo } = await github.rest.repos.get({ owner, repo });
123+
const base = repoInfo.default_branch;
124+
const head = `${owner}:${branch}`;
125+
126+
const title = `chore: weekly pipeline refresh (${datePt})`;
127+
const bodyLines = [
128+
"Automated weekly refresh of the component gallery pipeline outputs.",
129+
"",
130+
`Command: \`uv run python components/registry/scripts/run_pipeline.py --enrich-progress-every 10${pipelineArgs ? " " + pipelineArgs : ""}\``,
131+
"",
132+
"This PR was created by a scheduled GitHub Actions workflow.",
133+
];
134+
const body = bodyLines.join("\n");
135+
136+
const existing = await github.rest.pulls.list({
137+
owner,
138+
repo,
139+
head,
140+
state: "open",
141+
});
142+
143+
let pr;
144+
if (existing.data.length > 0) {
145+
pr = existing.data[0];
146+
await github.rest.pulls.update({
147+
owner,
148+
repo,
149+
pull_number: pr.number,
150+
title,
151+
body,
152+
});
153+
} else {
154+
const created = await github.rest.pulls.create({
155+
owner,
156+
repo,
157+
title,
158+
head: branch,
159+
base,
160+
body,
161+
draft: false,
162+
});
163+
pr = created.data;
164+
}
165+
166+
core.setOutput("pr_url", pr.html_url);
167+
core.setOutput("pr_number", String(pr.number));
168+
169+
- name: Summary
170+
env:
171+
HAS_CHANGES: ${{ steps.changes.outputs.has_changes }}
172+
BRANCH: ${{ steps.changes.outputs.branch }}
173+
PR_URL: ${{ steps.pr.outputs.pr_url }}
174+
run: |
175+
{
176+
echo "## Weekly pipeline refresh";
177+
echo "- has changes: ${HAS_CHANGES}";
178+
echo "- branch: ${BRANCH}";
179+
if [ "${HAS_CHANGES}" = "true" ]; then
180+
echo "- PR: ${PR_URL:-n/a}";
181+
else
182+
echo "- PR: n/a (no changes detected)";
183+
fi
184+
} >> "$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)