Add testing cron trigger #6
Workflow file for this run
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: Nightly Changelog | |
| on: | |
| schedule: | |
| - cron: '*/2 * * * *' | |
| push: | |
| branches: | |
| - feature/nightlies | |
| workflow_call: | |
| inputs: | |
| branch: | |
| description: 'Branch to check for changes' | |
| required: false | |
| type: string | |
| default: 'main' | |
| outputs: | |
| has_changes: | |
| description: "True if there were changes" | |
| value: ${{ jobs.changelog.outputs.has_changes }} | |
| changelog: | |
| description: "The changelog" | |
| value: ${{ jobs.changelog.outputs.changelog }} | |
| jobs: | |
| changelog: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| has_changes: ${{ steps.changelog.outputs.has_changes }} | |
| changelog: ${{ steps.changelog.outputs.changelog }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Fetch all history for all branches and tags | |
| - name: Determine Branch | |
| id: get_branch | |
| run: | | |
| BRANCH_NAME="" | |
| if [ "${{ github.event_name }}" == "workflow_call" ]; then | |
| BRANCH_NAME="${{ inputs.branch }}" | |
| elif [ "${{ github.event_name }}" == "push" ]; then | |
| BRANCH_NAME="${{ github.ref_name }}" | |
| fi | |
| if [ -z "$BRANCH_NAME" ]; then | |
| echo "Branch name could not be determined, falling back to default 'main'" | |
| BRANCH_NAME="main" | |
| fi | |
| echo "TARGET_BRANCH=$BRANCH_NAME" >> $GITHUB_ENV | |
| echo "Determined branch to check: $BRANCH_NAME" | |
| - name: Restore last commit SHA from cache | |
| id: cache-commit-sha | |
| uses: actions/cache@v4 | |
| with: | |
| path: last_commit_sha.txt | |
| # A unique key is used to force a cache miss and trigger a save post-job. | |
| key: last-commit-sha-${{ github.repository }}-${{ env.TARGET_BRANCH }}-${{ github.run_id }} | |
| # The most recent cache is restored using a partial key match. | |
| restore-keys: | | |
| last-commit-sha-${{ github.repository }}-${{ env.TARGET_BRANCH }}- | |
| - name: Generate changelog | |
| id: changelog | |
| run: | | |
| echo "Working with branch: ${{ env.TARGET_BRANCH }}" | |
| # Get the SHA of the latest commit on the branch | |
| CURRENT_COMMIT_SHA=$(git rev-parse origin/${{ env.TARGET_BRANCH }}) | |
| # Get the previously cached SHA. If the file doesn't exist, the variable will be empty. | |
| LAST_COMMIT_SHA=$(cat last_commit_sha.txt 2>/dev/null || echo "") | |
| # If no SHA was restored, fall back to a time-based comparison. | |
| if [ -z "$LAST_COMMIT_SHA" ]; then | |
| echo "No valid cache found. Comparing against the last 24 hours." | |
| COMMIT_LOG=$(git log origin/${{ env.TARGET_BRANCH }} --first-parent --since="24 hours ago" --pretty=format:"%s") | |
| else | |
| echo "Valid cache found. Comparing against commit $LAST_COMMIT_SHA." | |
| COMMIT_LOG=$(git log $LAST_COMMIT_SHA..$CURRENT_COMMIT_SHA --first-parent --pretty=format:"%s") | |
| fi | |
| # Set outputs | |
| if [ -z "$COMMIT_LOG" ]; then | |
| echo "has_changes=false" >> $GITHUB_OUTPUT | |
| echo "changelog=" >> $GITHUB_OUTPUT | |
| else | |
| echo "has_changes=true" >> $GITHUB_OUTPUT | |
| echo "changelog<<EOF" >> $GITHUB_OUTPUT | |
| echo "$COMMIT_LOG" >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| fi | |
| # Overwrite the local file with the new SHA to be cached post-job. | |
| echo $CURRENT_COMMIT_SHA > last_commit_sha.txt | |
| - name: Debug Outputs | |
| if: always() | |
| run: | | |
| echo "Debug Outputs:" | |
| echo "has_changes: ${{ steps.changelog.outputs.has_changes }}" | |
| echo "changelog: ${{ steps.changelog.outputs.changelog }}" |