Daily Diff #286
This file contains 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: Daily Diff | |
on: | |
schedule: | |
- cron: '0 0 * * *' # Runs at midnight every day (change cron for different timings) | |
workflow_dispatch: | |
permissions: | |
contents: write | |
env: | |
REPOS: ${{ vars.REPOS }} | |
jobs: | |
prepare-matrix: | |
name: Get Repositories List | |
runs-on: ubuntu-latest | |
outputs: | |
repos: ${{ steps.step1.outputs.matrix }} | |
steps: | |
- name: Create Matrix Variable | |
id: step1 | |
run: echo "matrix=${{env.REPOS}}" >> $GITHUB_OUTPUT | |
check-diff: | |
name: Check Diff | |
needs: [prepare-matrix] | |
strategy: | |
matrix: | |
repo: ${{ fromJSON(needs.prepare-matrix.outputs.repos) }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
path: host | |
persist-credentials: false | |
- name: Checkout ${{ matrix.repo }} | |
uses: actions/checkout@v4 | |
with: | |
repository: ${{ matrix.repo }} | |
path: guest | |
fetch-depth: 0 | |
- name: Setup Repository Environment | |
run: | | |
cd host | |
git fetch origin ${{ matrix.repo }} || echo "No remote branch found." | |
git switch ${{ matrix.repo }} || git switch -c ${{ matrix.repo }} | |
mkdir -p diffs | |
- name: Get Repository Description | |
run: curl -sSL -X GET "https://api.github.com/repos/${{ matrix.repo }}" > host/repo.json | |
- name: Find First Commit in Last 24 Hours | |
run: | | |
cd guest | |
FIRST_COMMIT=$(git rev-list --since="1 day ago" HEAD | tail -n 1) | |
if [ -z "$FIRST_COMMIT" ]; then | |
echo "No commits in the last 24 hours." | |
exit 0 # Exit the workflow successfully without error | |
fi | |
echo "FIRST_COMMIT=$FIRST_COMMIT" >> $GITHUB_ENV | |
- name: Get Git Diff | |
if: env.FIRST_COMMIT | |
run: | | |
cd guest | |
DIFF_INDEX=$(ls ../host/diffs -l | wc -l) | |
if git rev-parse --quiet --verify "${FIRST_COMMIT}^1"; then | |
git diff "${FIRST_COMMIT}^1" HEAD -- > ../host/diffs/${DIFF_INDEX}.txt | |
else | |
git show "${FIRST_COMMIT}" > ../host/diffs/${DIFF_INDEX}.txt | |
fi | |
shell: /usr/bin/bash -e {0} | |
env: | |
FIRST_COMMIT: ${{ env.FIRST_COMMIT }} | |
- name: Commit and Push Changes | |
if: env.FIRST_COMMIT | |
run: | | |
cd host | |
git config user.name github-actions | |
git config user.email github-actions@github.com | |
git add . | |
git commit -m "Update diffs for ${{ matrix.repo }} at $(date)" | |
git remote set-url origin https://x-access-token:${{ secrets.PAT }}@github.com/${{ github.repository }} | |
git push -u origin ${{ matrix.repo }} | |
env: | |
FIRST_COMMIT: ${{ env.FIRST_COMMIT }} |