Check Commits #12
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}) |