Skip to content

Commit cfa06d1

Browse files
Copilotmchammer01
andauthored
Fix the sync-secret-scanning workflow to enable automerge without human intervention (#61528)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: mchammer01 <42146119+mchammer01@users.noreply.github.com>
1 parent deb8c6f commit cfa06d1

1 file changed

Lines changed: 32 additions & 49 deletions

File tree

.github/workflows/sync-secret-scanning.yml

Lines changed: 32 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -37,61 +37,44 @@ jobs:
3737
run: |
3838
npm run sync-secret-scanning
3939
40-
- name: Create a pull request
40+
- name: Create pull request
41+
id: create-pull-request
42+
uses: peter-evans/create-pull-request@98357b18bf14b5342f975ff684046ec3b2a07725 # pin @v8.0.0
4143
env:
42-
# Needed for gh
43-
GITHUB_TOKEN: ${{ secrets.DOCS_BOT_PAT_BASE }}
44-
run: |
45-
# If nothing to commit, exit now. It's fine.
46-
changes=$(git diff --name-only | wc -l)
47-
untracked=$(git status --untracked-files --short | wc -l)
48-
if [[ $changes -eq 0 ]] && [[ $untracked -eq 0 ]]; then
49-
echo "There are no changes to commit. Exiting..."
50-
exit 0
51-
fi
52-
53-
git config --global user.name "docs-bot"
54-
git config --global user.email "77750099+docs-bot@users.noreply.github.com"
55-
56-
branchname=sync-secret-scanning-`date +%Y%m%d%H%M%S`
57-
58-
remotesha=$(git ls-remote --heads origin $branchname)
59-
if [ -n "$remotesha" ]; then
60-
# output is not empty, it means the remote branch exists
61-
echo "Branch $branchname already exists in 'github/docs-internal'. Exiting..."
62-
exit 0
63-
fi
64-
65-
git checkout -b $branchname
66-
git add .
67-
git commit -m "Add updated secret scanning data"
68-
git push origin $branchname
69-
70-
echo "Creating pull request..."
71-
gh pr create \
72-
--title "Sync secret scanning data" \
73-
--body '👋 humans. This PR updates the secret scanning data with the latest changes from github/token-scanning-service.
44+
# Disable pre-commit hooks; they don't play nicely here
45+
HUSKY: '0'
46+
with:
47+
# need to use a token with repo and workflow scopes for this step
48+
token: ${{ secrets.DOCS_BOT_PAT_BASE }}
49+
commit-message: 'Add updated secret scanning data'
50+
title: Sync secret scanning data
51+
body: |
52+
👋 humans. This PR updates the secret scanning data with the latest changes from github/token-scanning-service.
7453
7554
If CI passes, this PR will be auto-merged. :green_heart:
7655
77-
If CI does not pass or other problems arise, contact #docs-engineering on Slack.' \
78-
--repo github/docs-internal \
79-
--label secret-scanning-pipeline,'skip FR board',workflow-generated \
80-
--head=$branchname
56+
If CI does not pass or other problems arise, contact #docs-engineering on Slack.
57+
58+
This automated PR was created by [this workflow](https://github.com/github/docs-internal/blob/main/.github/workflows/sync-secret-scanning.yml).
59+
branch: sync-secret-scanning-data
60+
labels: |
61+
secret-scanning-pipeline
62+
skip FR board
63+
workflow-generated
8164
82-
# can't approve your own PR, approve with Actions
83-
echo "Approving pull request..."
84-
unset GITHUB_TOKEN
85-
gh auth login --with-token <<< "${{ secrets.GITHUB_TOKEN }}"
86-
gh pr review --approve
87-
echo "Approved pull request"
65+
- name: Enable GitHub auto-merge
66+
if: ${{ steps.create-pull-request.outputs.pull-request-number }}
67+
env:
68+
GITHUB_TOKEN: ${{ secrets.DOCS_BOT_PAT_BASE }}
69+
AUTOMERGE_PR_NUMBER: ${{ steps.create-pull-request.outputs.pull-request-number }}
70+
run: npm run enable-automerge
8871

89-
# Actions can't merge the PR so back to docs-bot to merge
90-
echo "Setting pull request to auto merge..."
91-
unset GITHUB_TOKEN
92-
gh auth login --with-token <<< "${{ secrets.DOCS_BOT_PAT_BASE }}"
93-
gh pr merge --auto --merge
94-
echo "Set pull request to auto merge"
72+
- if: ${{ steps.create-pull-request.outputs.pull-request-number }}
73+
name: Approve
74+
uses: juliangruber/approve-pull-request-action@dcc4effb325c0b503408619918d56e40653dcc91
75+
with:
76+
github-token: ${{ secrets.GITHUB_TOKEN }}
77+
number: ${{ steps.create-pull-request.outputs.pull-request-number }}
9578

9679
- uses: ./.github/actions/slack-alert
9780
if: ${{ failure() && github.event_name != 'workflow_dispatch' }}

0 commit comments

Comments
 (0)