Skip to content

Commit be6907e

Browse files
[SL-ONLY] Adapt the open PR automation to force trigger the CI jobs (#240)
1 parent 612153f commit be6907e

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

.github/workflows/silabs-open-csa-pr.yaml

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ jobs:
1919
- uses: actions/checkout@v4
2020
with:
2121
ref: main
22-
token: ${{secrets.WORKFLOW_TOKEN}}
2322

2423
- name: Checkout csa
2524
run: |
@@ -37,18 +36,34 @@ jobs:
3736
3837
**PR MUST BE MERGED WITH MERGE COMMIT - ADMIN MUST ENABLE THE OPTION**
3938
token: ${{secrets.GITHUB_TOKEN}}
40-
branch-token: ${{secrets.WORKFLOW_TOKEN}}
4139
labels: changing-submodules-on-purpose
4240

43-
- name: Comment on Pull Request
44-
uses: actions/github-script@v7
45-
with:
46-
github-token: ${{secrets.GITHUB_TOKEN}}
47-
script: |
48-
const pr_number = context.payload.workflow_run.pull_requests[0].number;
49-
github.issues.createComment({
50-
owner: context.repo.owner,
51-
repo: context.repo.repo,
52-
issue_number: pr_number,
53-
body: "Please merge this PR using **Merge Commit**."
54-
});
41+
# The next two steps are necessary to force the CI to be executed when a PR is opened by the github-bot.
42+
# The PR event isn't triggered when the bot opens the PR and as such doesn't trigger the workflows that use the event as their trigger.
43+
# By closing and opening the PR, it forces the PR event to be triggered.
44+
- name: Check if PR is already closed and reopened
45+
id: check_pr
46+
run: |
47+
PR_NUMBER=$(gh pr list --repo ${{ github.repository }} --state open --head automation/update_main --json number --jq '.[0].number')
48+
if [ -z "$PR_NUMBER" ]; then
49+
echo "PR not found."
50+
exit 1
51+
fi
52+
LABELS=$(gh pr view $PR_NUMBER --repo ${{ github.repository }} --json labels --jq '.labels[].name')
53+
if echo "$LABELS" | grep -q "sl-automation-triggered"; then
54+
echo "pr_needs_reopen=true" >> $GITHUB_OUTPUT
55+
else
56+
echo "pr_needs_reopen=false" >> $GITHUB_OUTPUT
57+
fi
58+
env:
59+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
60+
61+
- name: Close and Reopen PR
62+
if: ${{ steps.check_pr.outputs.pr_needs_reopen }}
63+
run: |
64+
PR_NUMBER=$(gh pr list --repo ${{ github.repository }} --state open --head automation/update_main --json number --jq '.[0].number')
65+
gh pr close $PR_NUMBER --repo ${{ github.repository }}
66+
gh pr reopen $PR_NUMBER --repo ${{ github.repository }}
67+
gh pr edit $PR_NUMBER --add-label "sl-automation-triggered"
68+
env:
69+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

0 commit comments

Comments
 (0)