Skip to content

Commit bd2cb5f

Browse files
authored
dataconnect: create python script to post comments about scheduled runs (#6880)
1 parent 51b4a1c commit bd2cb5f

File tree

10 files changed

+913
-29
lines changed

10 files changed

+913
-29
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Data Connect Workflow Notifications
2+
description: Notify a GitHub Issue with the results of a workflow.
3+
4+
inputs:
5+
python-version:
6+
required: true
7+
default: "3.13"
8+
github-issue-for-scheduled-runs:
9+
required: true
10+
job-results-file:
11+
required: true
12+
13+
runs:
14+
using: "composite"
15+
steps:
16+
- uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0
17+
with:
18+
python-version: ${{ inputs.python-version }}
19+
20+
- run: pip install -r requirements.txt
21+
shell: bash
22+
working-directory: firebase-dataconnect/ci
23+
24+
- id: issue-id
25+
name: Determine GitHub Issue For Commenting
26+
working-directory: firebase-dataconnect/ci
27+
shell: bash
28+
run: |
29+
args=(
30+
python
31+
calculate_github_issue_for_commenting.py
32+
--issue-output-file=github_issue_number.txt
33+
--github-repository='${{ github.repository }}'
34+
--github-ref='${{ github.ref }}'
35+
--github-event-name='${{ github.event_name }}'
36+
--pr-body-github-issue-key=trksmnkncd_notification_issue
37+
--github-issue-for-scheduled-run='${{ inputs.github-issue-for-scheduled-runs }}'
38+
)
39+
echo "${args[*]}"
40+
"${args[@]}"
41+
42+
set -xv
43+
issue="$(cat github_issue_number.txt)"
44+
echo "issue=$issue" >> "$GITHUB_OUTPUT"
45+
46+
- name: Post Comment on GitHub Issue
47+
if: steps.issue-id.outputs.issue != ''
48+
working-directory: firebase-dataconnect/ci
49+
shell: bash
50+
run: |
51+
args=(
52+
python
53+
post_comment_for_job_results.py
54+
--github-issue='${{ steps.issue-id.outputs.issue }}'
55+
--github-workflow='${{ github.workflow }}'
56+
--github-repository='${{ github.repository }}'
57+
--github-ref='${{ github.ref }}'
58+
--github-event-name='${{ github.event_name }}'
59+
--github-sha='${{ github.sha }}'
60+
--github-repository-html-url='${{ github.event.repository.html_url }}'
61+
--github-run-id='${{ github.run_id }}'
62+
--github-run-number='${{ github.run_number }}'
63+
--github-run-attempt='${{ github.run_attempt }}'
64+
)
65+
66+
while read -r line; do
67+
args=("${args[@]}" "$line")
68+
done <'${{ inputs.job-results-file }}'
69+
70+
echo "${args[*]}"
71+
exec "${args[@]}"

.github/workflows/dataconnect.yml

Lines changed: 108 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ on:
99
firebaseToolsVersion:
1010
gradleInfoLog:
1111
type: boolean
12+
pythonVersion:
1213
pull_request:
1314
paths:
1415
- .github/workflows/dataconnect.yml
@@ -27,6 +28,7 @@ env:
2728
FDC_FIREBASE_TOOLS_VERSION: ${{ inputs.firebaseToolsVersion || '13.29.1' }}
2829
FDC_FIREBASE_TOOLS_DIR: /tmp/firebase-tools
2930
FDC_FIREBASE_COMMAND: /tmp/firebase-tools/node_modules/.bin/firebase
31+
FDC_PYTHON_VERSION: ${{ inputs.pythonVersion || '3.13' }}
3032

3133
concurrency:
3234
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
@@ -256,30 +258,122 @@ jobs:
256258
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
257259
with:
258260
show-progress: false
261+
sparse-checkout: '.github/'
259262
- uses: docker://rhysd/actionlint:1.7.7
260263
with:
261264
args: -color /github/workspace/.github/workflows/dataconnect.yml
262265

266+
python-ci-unit-tests:
267+
continue-on-error: false
268+
runs-on: ubuntu-latest
269+
steps:
270+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
271+
with:
272+
show-progress: false
273+
sparse-checkout: 'firebase-dataconnect/ci/'
274+
- uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0
275+
with:
276+
python-version: ${{ env.FDC_PYTHON_VERSION }}
277+
- run: pip install -r firebase-dataconnect/ci/requirements.txt
278+
- name: pytest
279+
working-directory: firebase-dataconnect/ci
280+
run: pytest --verbose --full-trace --color=no --strict-config
281+
282+
python-ci-lint:
283+
continue-on-error: false
284+
runs-on: ubuntu-latest
285+
steps:
286+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
287+
with:
288+
show-progress: false
289+
sparse-checkout: 'firebase-dataconnect/ci/'
290+
- uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0
291+
with:
292+
python-version: ${{ env.FDC_PYTHON_VERSION }}
293+
- run: pip install -r firebase-dataconnect/ci/requirements.txt
294+
- name: ruff check
295+
working-directory: firebase-dataconnect/ci
296+
run: ruff check --diff --verbose --no-cache --output-format=github --exit-non-zero-on-fix
297+
298+
python-ci-format:
299+
continue-on-error: false
300+
runs-on: ubuntu-latest
301+
steps:
302+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
303+
with:
304+
show-progress: false
305+
sparse-checkout: 'firebase-dataconnect/ci/'
306+
- uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0
307+
with:
308+
python-version: ${{ env.FDC_PYTHON_VERSION }}
309+
- run: pip install -r firebase-dataconnect/ci/requirements.txt
310+
- name: ruff format
311+
working-directory: firebase-dataconnect/ci
312+
run: ruff format --diff --verbose --no-cache
313+
314+
python-ci-type-check:
315+
continue-on-error: false
316+
runs-on: ubuntu-latest
317+
steps:
318+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
319+
with:
320+
show-progress: false
321+
sparse-checkout: 'firebase-dataconnect/ci/'
322+
- uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0
323+
with:
324+
python-version: ${{ env.FDC_PYTHON_VERSION }}
325+
- run: pip install -r firebase-dataconnect/ci/requirements.txt
326+
- name: pyright
327+
working-directory: firebase-dataconnect/ci
328+
run: pyright --warnings --stats
329+
330+
# The "send-notifications" job adds a comment to GitHub Issue
331+
# https://github.com/firebase/firebase-android-sdk/issues/6857 with the results of the scheduled
332+
# nightly runs. Interested parties can then subscribe to that issue to be aprised of the outcome
333+
# of the nightly runs.
334+
#
335+
# When testing the comment-adding logic itself, you can add the line
336+
# trksmnkncd_notification_issue=6863
337+
# into the PR's description to instead post a comment to issue #6863, an issue specifically
338+
# created for testing, avoiding spamming the main issue to which others are subscribed.
263339
send-notifications:
264-
needs: [integration-test, actionlint-dataconnect-yml]
340+
needs:
341+
- 'integration-test'
342+
- 'actionlint-dataconnect-yml'
343+
- 'python-ci-unit-tests'
344+
- 'python-ci-lint'
345+
- 'python-ci-format'
346+
- 'python-ci-type-check'
265347
if: always()
266348
permissions:
267349
issues: write
268350
runs-on: ubuntu-latest
269351
steps:
270-
- name: Post Comment on Issue #6857
271-
if: github.event_name == 'schedule'
272-
env:
273-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
274-
run: |
275-
set -euo pipefail
352+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
353+
with:
354+
show-progress: false
355+
sparse-checkout: |
356+
firebase-dataconnect/ci/
357+
.github/
358+
359+
- name: gh auth login
360+
run: echo '${{ secrets.GITHUB_TOKEN }}' | gh auth login --with-token
276361

277-
cat >message.txt <<EOF
278-
Result of workflow ${{ github.workflow }} at ${{ github.ref }}: ${{ job.status }}
279-
${{ github.event.repository.html_url }}/actions/runs/${{ github.run_id }}
280-
job=${{ github.job }} run_id=${{ github.run_id }} run_number=${{ github.run_number }} run_attempt=${{ github.run_attempt }}
362+
- name: Create Job Results File
363+
id: create-job-results-file
364+
run: |
365+
set -xveuo pipefail
366+
cat >'${{ runner.temp }}/job_results.txt' <<EOF
367+
integration-test:${{ needs.integration-test.result }}
368+
actionlint-dataconnect-yml:${{ needs.actionlint-dataconnect-yml.result }}
369+
python-ci-unit-tests:${{ needs.python-ci-unit-tests.result }}
370+
python-ci-lint:${{ needs.python-ci-lint.result }}
371+
python-ci-format:${{ needs.python-ci-format.result }}
372+
python-ci-type-check:${{ needs.python-ci-type-check.result }}
281373
EOF
282374
283-
echo "Posting comment on GitHub Issue: https://github.com/firebase/firebase-android-sdk/issues/6857:"
284-
cat message.txt
285-
gh issue comment 6857 --body-file message.txt -R ${{ github.repository }}
375+
- uses: ./.github/actions/dataconnect-send-notifications
376+
with:
377+
python-version: ${{ env.FDC_PYTHON_VERSION }}
378+
github-issue-for-scheduled-runs: "6857"
379+
job-results-file: ${{ runner.temp }}/job_results.txt

.github/workflows/dataconnect_demo_app.yml

Lines changed: 57 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88
javaVersion:
99
gradleInfoLog:
1010
type: boolean
11+
pythonVersion:
1112
pull_request:
1213
paths:
1314
- firebase-dataconnect/demo/**
@@ -21,11 +22,7 @@ env:
2122
FDC_JAVA_VERSION: ${{ inputs.javaVersion || '17' }}
2223
FDC_FIREBASE_TOOLS_DIR: ${{ github.workspace }}/firebase-tools
2324
FDC_FIREBASE_COMMAND: ${{ github.workspace }}/firebase-tools/node_modules/.bin/firebase
24-
25-
defaults:
26-
run:
27-
shell: bash
28-
working-directory: firebase-dataconnect/demo
25+
FDC_PYTHON_VERSION: ${{ inputs.pythonVersion || '3.13' }}
2926

3027
concurrency:
3128
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
@@ -50,8 +47,8 @@ jobs:
5047
node-version: ${{ env.FDC_NODE_VERSION }}
5148
cache: 'npm'
5249
cache-dependency-path: |
53-
firebase-dataconnect/demo/github_actions_demo_test_cache_key.txt
54-
firebase-dataconnect/demo/github_actions_demo_assemble_firebase_tools_version.txt
50+
github_actions_demo_test_cache_key.txt
51+
github_actions_demo_assemble_firebase_tools_version.txt
5552
5653
- name: cache package-lock.json
5754
id: package_json_lock
@@ -84,7 +81,7 @@ jobs:
8481
firebase-dataconnect/demo/build.gradle.kts
8582
firebase-dataconnect/demo/gradle.properties
8683
firebase-dataconnect/demo/gradle/wrapper/gradle-wrapper.properties
87-
firebase-dataconnect/demo/github_actions_demo_test_cache_key.txt
84+
github_actions_demo_test_cache_key.txt
8885
8986
- name: tool versions
9087
continue-on-error: true
@@ -102,12 +99,13 @@ jobs:
10299
run_cmd which node
103100
run_cmd node --version
104101
run_cmd ${{ env.FDC_FIREBASE_COMMAND }} --version
105-
run_cmd ./gradlew --version
102+
run_cmd firebase-dataconnect/demo/gradlew --version
106103
107-
- name: ./gradlew assemble test
104+
- name: gradle assemble test
108105
run: |
109106
set -x
110-
./gradlew \
107+
firebase-dataconnect/demo/gradlew \
108+
--project-dir firebase-dataconnect/demo \
111109
--no-daemon \
112110
${{ (inputs.gradleInfoLog && '--info') || '' }} \
113111
--profile \
@@ -148,7 +146,7 @@ jobs:
148146
firebase-dataconnect/demo/build.gradle.kts
149147
firebase-dataconnect/demo/gradle.properties
150148
firebase-dataconnect/demo/gradle/wrapper/gradle-wrapper.properties
151-
firebase-dataconnect/demo/github_actions_demo_spotless_cache_key.txt
149+
github_actions_demo_spotless_cache_key.txt
152150
153151
- name: tool versions
154152
continue-on-error: true
@@ -158,12 +156,56 @@ jobs:
158156
java -version
159157
which javac
160158
javac -version
161-
./gradlew --version
159+
firebase-dataconnect/demo/gradlew --version
162160
163-
- name: ./gradlew spotlessCheck
161+
- name: gradle spotlessCheck
164162
run: |
165163
set -x
166-
./gradlew \
164+
firebase-dataconnect/demo/gradlew \
165+
--project-dir firebase-dataconnect/demo \
167166
--no-daemon \
168167
${{ (inputs.gradleInfoLog && '--info') || '' }} \
169168
spotlessCheck
169+
170+
# The "send-notifications" job adds a comment to GitHub Issue
171+
# https://github.com/firebase/firebase-android-sdk/issues/6891 with the results of the scheduled
172+
# nightly runs. Interested parties can then subscribe to that issue to be aprised of the outcome
173+
# of the nightly runs.
174+
#
175+
# When testing the comment-adding logic itself, you can add the line
176+
# trksmnkncd_notification_issue=6863
177+
# into the PR's description to instead post a comment to issue #6863, an issue specifically
178+
# created for testing, avoiding spamming the main issue to which others are subscribed.
179+
send-notifications:
180+
needs:
181+
- 'test'
182+
- 'spotlessCheck'
183+
if: always()
184+
permissions:
185+
issues: write
186+
runs-on: ubuntu-latest
187+
steps:
188+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
189+
with:
190+
show-progress: false
191+
sparse-checkout: |
192+
firebase-dataconnect/ci/
193+
.github/
194+
195+
- name: gh auth login
196+
run: echo '${{ secrets.GITHUB_TOKEN }}' | gh auth login --with-token
197+
198+
- name: Create Job Results File
199+
id: create-job-results-file
200+
run: |
201+
set -xveuo pipefail
202+
cat >'${{ runner.temp }}/job_results.txt' <<EOF
203+
test:${{ needs.test.result }}
204+
spotlessCheck:${{ needs.spotlessCheck.result }}
205+
EOF
206+
207+
- uses: ./.github/actions/dataconnect-send-notifications
208+
with:
209+
python-version: ${{ env.FDC_PYTHON_VERSION }}
210+
github-issue-for-scheduled-runs: "6891"
211+
job-results-file: ${{ runner.temp }}/job_results.txt

firebase-dataconnect/ci/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Firebase Data Connect Android SDK Continuous Integration Scripts
2+
3+
These scripts are used by GitHub Actions.
4+
5+
There are GitHub Actions workflows that verify code formatting, lint checks, type annotations,
6+
and running unit tests of code in this directory. Although they are not "required" checks, it
7+
is requested to wait for these checks to pass. See `dataconnect.yaml`.
8+
9+
The minimum required Python version (at the time of writing, April 2025) is 3.13.
10+
See `pyproject.toml` for the most up-to-date requirement.
11+
12+
Before running the scripts, install the required dependencies by running:
13+
14+
```
15+
pip install -r requirements.txt
16+
```
17+
18+
Then, run all of these presubmit checks by running the following command:
19+
20+
```
21+
ruff check && ruff format && pyright && pytest && echo 'SUCCESS!!!!!!!!!!!!!!!'
22+
```

0 commit comments

Comments
 (0)