Skip to content

Commit 372fbe9

Browse files
authored
Handle empty commit in sync audit log (#55709)
1 parent 5b09d3b commit 372fbe9

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

.github/workflows/sync-audit-logs.yml

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,34 +51,38 @@ jobs:
5151
# Needed for gh
5252
GITHUB_TOKEN: ${{ secrets.DOCS_BOT_PAT_BASE }}
5353
run: |
54-
# If nothing to commit, exit now. It's fine. No orphans.
55-
changes=$(git diff --name-only | wc -l)
56-
untracked=$(git status --untracked-files --short | wc -l)
57-
filesChanged=$(git diff --name-only)
58-
# There will always be at least one file changed:
59-
# src/audit-logs/lib/config.json
60-
# If the config file is the only file changed, exit.
61-
if [[ $changes -eq 1 ]] && [[ $untracked -eq 1 ]] && [[ $filesChanged == *lib/config.json ]]; then
62-
echo "There are no changes to commit or untracked files. Exiting..."
54+
echo "Creating a new branch if needed..."
55+
branchname=audit-logs-schema-update-${{ steps.audit-log-allowlists.outputs.COMMIT_SHA }}
56+
remotesha=$(git ls-remote --heads origin $branchname)
57+
if [ -n "$remotesha" ]; then
58+
# output is not empty, it means the remote branch exists
59+
echo "Branch $branchname already exists in 'github/docs-internal'. Exiting..."
6360
exit 0
6461
fi
62+
git checkout -b $branchname
63+
echo "Created a new branch $branchname"
6564
65+
echo "Preparing commit..."
6666
git config --global user.name "docs-bot"
6767
git config --global user.email "[email protected]"
68+
git add -A .
69+
echo "Prepared commit"
6870
69-
branchname=audit-logs-schema-update-${{ steps.audit-log-allowlists.outputs.COMMIT_SHA }}
70-
71-
remotesha=$(git ls-remote --heads origin $branchname)
72-
if [ -n "$remotesha" ]; then
73-
# output is not empty, it means the remote branch exists
74-
echo "Branch $branchname already exists in 'github/docs-internal'. Exiting..."
71+
echo "Check if there are changes..."
72+
if git diff-index --cached --quiet HEAD -- . ':(exclude)src/audit-logs/lib/config.json'
73+
then
74+
echo "No real changes (only the SHA in config.json moved). Exiting…"
7575
exit 0
7676
fi
77+
echo "Changes detected, proceeding"
7778
78-
git checkout -b $branchname
79-
git add .
79+
echo "Creating commit..."
8080
git commit -m "Add updated audit log event data"
81+
echo "Created commit"
82+
83+
echo "Pushing commit..."
8184
git push origin $branchname
85+
echo "Pushed commit"
8286
8387
echo "Creating pull request..."
8488
gh pr create \
@@ -89,16 +93,21 @@ jobs:
8993
--repo github/docs-internal \
9094
--label audit-log-pipeline \
9195
--head=$branchname
96+
echo "Created pull request"
9297
9398
# can't approve your own PR, approve with Actions
99+
echo "Approving pull request..."
94100
unset GITHUB_TOKEN
95101
gh auth login --with-token <<< "${{ secrets.GITHUB_TOKEN }}"
96102
gh pr review --approve
103+
echo "Approved pull request"
97104
98105
# Actions can't merge the PR so back to docs-bot to merge the PR
106+
echo "Setting pull request to auto merge..."
99107
unset GITHUB_TOKEN
100108
gh auth login --with-token <<< "${{ secrets.DOCS_BOT_PAT_BASE }}"
101109
gh pr merge --auto
110+
echo "Set pull request to auto merge"
102111
103112
- uses: ./.github/actions/slack-alert
104113
if: ${{ failure() && github.event_name != 'workflow_dispatch' }}

0 commit comments

Comments
 (0)