-
Notifications
You must be signed in to change notification settings - Fork 98
53 lines (48 loc) · 1.75 KB
/
Copy pathweekly_check_commits.yml
File metadata and controls
53 lines (48 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
name: Check Commits
on:
schedule:
- cron: '37 2 * * 0'
workflow_dispatch:
jobs:
check-commits:
runs-on: ubuntu-latest
outputs:
should_run: ${{ steps.check.outputs.should_run }}
steps:
- uses: actions/checkout@v3
- name: Install GitHub CLI
run: sudo apt-get update && sudo apt-get install -y gh
- name: Check for new commits since last successful run
id: check
env:
GH_TOKEN: ${{ secrets.WORKFLOW_TOKEN }}
run: |
if [ "${{ github.event_name }}" != "schedule" ]; then
echo "should_run=true" >> $GITHUB_OUTPUT
exit 0
fi
LAST_SUCCESS=$(gh run list --workflow build.yml --branch ${{ github.ref_name }} --status success --limit 1 --json startedAt --jq '.[0].startedAt')
if [ -z "$LAST_SUCCESS" ]; then
echo "No previous successful run, continuing."
echo "should_run=true" >> $GITHUB_OUTPUT
exit 0
fi
NEW_COMMITS=$(git rev-list --count --since="$LAST_SUCCESS" ${{ github.ref_name }})
if [ "$NEW_COMMITS" -eq 0 ]; then
echo "No new commits since last successful run, skipping workflow."
echo "should_run=false" >> $GITHUB_OUTPUT
exit 0
fi
echo "should_run=true" >> $GITHUB_OUTPUT
- name: Trigger Build Workflow
if: steps.check.outputs.should_run == 'true'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.WORKFLOW_TOKEN }}
script: |
await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'build.yml',
ref: context.ref
})