Skip to content

Commit 28d14f7

Browse files
committed
fix: update scheduler to fetch data every 5 minutes instead of 24 hours
1 parent 7020056 commit 28d14f7

3 files changed

Lines changed: 94 additions & 3 deletions

File tree

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Auto-merge on successful release pipeline
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
head_branch:
7+
description: 'Branch name to find PR for'
8+
required: false
9+
type: string
10+
11+
permissions:
12+
contents: write
13+
pull-requests: write
14+
15+
jobs:
16+
auto-merge:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Auto-merge matching PR
20+
uses: actions/github-script@v7
21+
with:
22+
github-token: ${{ secrets.GITHUB_TOKEN }}
23+
script: |
24+
// Support both automatic workflow_run triggers and explicit workflow_call inputs.
25+
const run = context.payload.workflow_run;
26+
let head_branch = '';
27+
if (run && run.head_branch) {
28+
head_branch = run.head_branch;
29+
} else if (context.payload && context.payload.inputs && context.payload.inputs.head_branch) {
30+
head_branch = context.payload.inputs.head_branch;
31+
}
32+
33+
const owner = context.repo.owner;
34+
const repo = context.repo.repo;
35+
36+
if (!head_branch) {
37+
core.info('No head_branch provided; nothing to do.');
38+
return;
39+
}
40+
41+
core.info(`Auto-merge triggered for branch: ${head_branch}`);
42+
43+
// Find an open PR whose head ref matches the branch
44+
const prs = await github.rest.pulls.list({
45+
owner,
46+
repo,
47+
head: `${owner}:${head_branch}`,
48+
state: 'open',
49+
});
50+
51+
if (!prs.data || prs.data.length === 0) {
52+
core.info(`No open pull request found for branch ${head_branch}`);
53+
return;
54+
}
55+
56+
const pr = prs.data[0];
57+
58+
if (pr.draft) {
59+
core.info(`Pull request #${pr.number} is a draft; skipping merge.`);
60+
return;
61+
}
62+
63+
try {
64+
const res = await github.rest.pulls.merge({
65+
owner,
66+
repo,
67+
pull_number: pr.number,
68+
merge_method: 'merge',
69+
commit_title: head_branch,
70+
commit_message: '',
71+
});
72+
73+
if (res.data.merged) {
74+
core.info(`Successfully merged PR #${pr.number} (branch ${head_branch}).`);
75+
} else {
76+
core.info(`Merge attempt returned: ${JSON.stringify(res.data)}`);
77+
}
78+
} catch (err) {
79+
core.setFailed(`Failed to merge PR #${pr.number}: ${err}`);
80+
}
81+
82+
- name: Done
83+
run: echo "auto-merge finished"

.github/workflows/ci-cd.yaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
needs: [lint, cache]
2424
uses: milsman2/python-app-template/.github/workflows/pytest.yaml@main
2525

26-
docker:
26+
docker-build-and-image-scan:
2727
if: github.event_name == 'push'
2828
needs: test
2929
uses: milsman2/python-app-template/.github/workflows/docker-build-and-scan.yaml@main
@@ -37,8 +37,16 @@ jobs:
3737

3838
release:
3939
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
40-
needs: [test, docker]
40+
needs: [test, docker-build-and-image-scan]
4141
uses: ./.github/workflows/release.yaml
4242
permissions:
4343
contents: write
4444
secrets: inherit
45+
46+
trigger-auto-merge:
47+
needs: release
48+
if: needs.release.result == 'success'
49+
uses: ./.github/workflows/auto-merge-on-release.yml
50+
with:
51+
head_branch: ${{ github.ref_name }}
52+
secrets: inherit

src/sample_python_app/app/scheduler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def shutdown(signum, frame):
3737
scheduler.add_job(
3838
fetcher.fetch,
3939
trigger="interval",
40-
hours=24,
40+
minutes=5,
4141
next_run_time=datetime.now(UTC),
4242
misfire_grace_time=3600,
4343
coalesce=True,

0 commit comments

Comments
 (0)