Skip to content

Commit 5bd5d8e

Browse files
committed
[feat] Add GH Workflows
1 parent a6e0687 commit 5bd5d8e

5 files changed

Lines changed: 237 additions & 5 deletions

File tree

.github/actions/pack_streamlit_component_library/action.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ runs:
2424
fi
2525
2626
- name: Checkout streamlit/streamlit
27-
uses: actions/checkout@v3
27+
uses: actions/checkout@v4
2828
with:
2929
persist-credentials: false
3030
repository: streamlit/streamlit

.github/workflows/ci.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ name: CI
22

33
on:
44
push:
5-
branches:
5+
branches:
66
- "master"
77
pull_request:
8-
branches:
8+
branches:
99
- "master"
1010

1111
jobs:
@@ -37,7 +37,7 @@ jobs:
3737
name: Examples + Templates / node_version=${{ matrix.node_version }} / streamlit_version=${{ matrix.streamlit_version }} / component_lib_version=${{ matrix.component_lib_version }}
3838

3939
steps:
40-
- uses: actions/checkout@v3
40+
- uses: actions/checkout@v4
4141
with:
4242
persist-credentials: false
4343
path: component-template
@@ -87,7 +87,7 @@ jobs:
8787
name: Cookiecutter
8888

8989
steps:
90-
- uses: actions/checkout@v3
90+
- uses: actions/checkout@v4
9191
with:
9292
persist-credentials: false
9393

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
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+
37+
steps:
38+
- name: Checkout repository
39+
uses: actions/checkout@v4
40+
with:
41+
fetch-depth: 1
42+
persist-credentials: true
43+
44+
- name: Setup Python
45+
uses: actions/setup-python@v5
46+
with:
47+
python-version: '3.11'
48+
49+
- name: Setup uv
50+
uses: astral-sh/setup-uv@v3
51+
with:
52+
enable-cache: true
53+
cache-dependency-glob: requirements.txt
54+
55+
- name: Create venv and install deps (uv)
56+
run: |
57+
set -euo pipefail
58+
uv venv .venv
59+
uv pip install -r requirements.txt
60+
61+
- name: Run pipeline
62+
id: pipeline
63+
env:
64+
# The pipeline scripts fall back to GITHUB_TOKEN for GitHub enrichment auth.
65+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
66+
NO_IMAGES: ${{ github.event.inputs.no_images || 'false' }}
67+
ALLOW_ENRICH_FAILURES: ${{ github.event.inputs.allow_enrich_failures || 'false' }}
68+
EXTRA_ARGS: ${{ github.event.inputs.extra_args || '' }}
69+
run: |
70+
set -euo pipefail
71+
72+
ARGS=()
73+
if [[ "${NO_IMAGES}" == "true" ]]; then ARGS+=("--no-images"); fi
74+
if [[ "${ALLOW_ENRICH_FAILURES}" == "true" ]]; then ARGS+=("--allow-enrich-failures"); fi
75+
if [[ -n "${EXTRA_ARGS}" ]]; then
76+
# EXTRA_ARGS is documented as space-separated.
77+
read -r -a EXTRA_ARGS_ARRAY <<< "${EXTRA_ARGS}"
78+
ARGS+=("${EXTRA_ARGS_ARRAY[@]}")
79+
fi
80+
echo "pipeline_args=${ARGS[*]}" >> "${GITHUB_OUTPUT}"
81+
82+
.venv/bin/python ./directory/scripts/run_pipeline.py --enrich-progress-every 10 "${ARGS[@]}"
83+
84+
- name: Detect changes
85+
id: changes
86+
run: |
87+
set -euo pipefail
88+
if [[ -n "$(git status --porcelain)" ]]; then
89+
echo "has_changes=true" >> "${GITHUB_OUTPUT}"
90+
else
91+
echo "has_changes=false" >> "${GITHUB_OUTPUT}"
92+
fi
93+
94+
DATE_PT="$(TZ=America/Los_Angeles date +%Y-%m-%d)"
95+
BRANCH="automation/weekly-pipeline-refresh-${DATE_PT}"
96+
echo "date_pt=${DATE_PT}" >> "${GITHUB_OUTPUT}"
97+
echo "branch=${BRANCH}" >> "${GITHUB_OUTPUT}"
98+
99+
- name: Create branch and commit
100+
if: steps.changes.outputs.has_changes == 'true'
101+
env:
102+
BRANCH: ${{ steps.changes.outputs.branch }}
103+
run: |
104+
set -euo pipefail
105+
git config user.name "component-template-bot"
106+
git config user.email "component-template-bot@users.noreply.github.com"
107+
108+
git checkout -B "${BRANCH}"
109+
git add -A directory/
110+
git commit -m "chore: weekly pipeline refresh"
111+
git push --force-with-lease origin "${BRANCH}"
112+
113+
- name: Create or update PR
114+
if: steps.changes.outputs.has_changes == 'true'
115+
id: pr
116+
uses: actions/github-script@v8
117+
env:
118+
BRANCH: ${{ steps.changes.outputs.branch }}
119+
DATE_PT: ${{ steps.changes.outputs.date_pt }}
120+
PIPELINE_ARGS: ${{ steps.pipeline.outputs.pipeline_args }}
121+
with:
122+
github-token: ${{ secrets.GITHUB_TOKEN }}
123+
script: |
124+
const owner = context.repo.owner;
125+
const repo = context.repo.repo;
126+
const branch = process.env.BRANCH;
127+
const datePt = process.env.DATE_PT;
128+
const pipelineArgs = (process.env.PIPELINE_ARGS || "").trim();
129+
130+
const { data: repoInfo } = await github.rest.repos.get({ owner, repo });
131+
const base = repoInfo.default_branch;
132+
const head = `${owner}:${branch}`;
133+
134+
const title = `chore: weekly pipeline refresh (${datePt})`;
135+
const bodyLines = [
136+
"Automated weekly refresh of the component gallery pipeline outputs.",
137+
"",
138+
`Command: \`.venv/bin/python ./directory/scripts/run_pipeline.py --enrich-progress-every 10${pipelineArgs ? " " + pipelineArgs : ""}\``,
139+
"",
140+
"This PR was created by a scheduled GitHub Actions workflow.",
141+
];
142+
const body = bodyLines.join("\n");
143+
144+
const existing = await github.rest.pulls.list({
145+
owner,
146+
repo,
147+
head,
148+
state: "open",
149+
});
150+
151+
let pr;
152+
if (existing.data.length > 0) {
153+
pr = existing.data[0];
154+
await github.rest.pulls.update({
155+
owner,
156+
repo,
157+
pull_number: pr.number,
158+
title,
159+
body,
160+
});
161+
} else {
162+
const created = await github.rest.pulls.create({
163+
owner,
164+
repo,
165+
title,
166+
head: branch,
167+
base,
168+
body,
169+
draft: false,
170+
});
171+
pr = created.data;
172+
}
173+
174+
core.setOutput("pr_url", pr.html_url);
175+
core.setOutput("pr_number", String(pr.number));
176+
177+
- name: Summary
178+
env:
179+
HAS_CHANGES: ${{ steps.changes.outputs.has_changes }}
180+
BRANCH: ${{ steps.changes.outputs.branch }}
181+
PR_URL: ${{ steps.pr.outputs.pr_url }}
182+
run: |
183+
{
184+
echo "## Weekly pipeline refresh";
185+
echo "- has changes: ${HAS_CHANGES}";
186+
echo "- branch: ${BRANCH}";
187+
if [ "${HAS_CHANGES}" = "true" ]; then
188+
echo "- PR: ${PR_URL:-n/a}";
189+
else
190+
echo "- PR: n/a (no changes detected)";
191+
fi
192+
} >> "$GITHUB_STEP_SUMMARY"
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Validate Component Definitions
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- 'master'
7+
paths:
8+
- 'directory/components/**'
9+
10+
jobs:
11+
validate-submissions:
12+
name: Validate Component Definitions
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v4
18+
19+
- name: Setup Python
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: '3.11'
23+
24+
- name: Setup uv
25+
uses: astral-sh/setup-uv@v3
26+
with:
27+
enable-cache: true
28+
cache-dependency-glob: requirements.txt
29+
30+
- name: Create venv and install deps (uv)
31+
run: |
32+
set -euo pipefail
33+
uv venv .venv
34+
uv pip install -r requirements.txt
35+
36+
- name: Validate Component Definitions
37+
run: |
38+
set -euo pipefail
39+
.venv/bin/python ./directory/scripts/validate.py

directory/components/.gitkeep

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

0 commit comments

Comments
 (0)