@@ -158,6 +158,7 @@ jobs:
158158 REPO : ${{ steps.target.outputs.repository }}
159159
160160 - name : Create branch and add SAST workflow
161+ id : create_branch
161162 if : steps.check_opt_out.outputs.opted_out != 'true'
162163 working-directory : target-repo
163164 env :
@@ -176,15 +177,20 @@ jobs:
176177 git checkout -b "$BRANCH_NAME"
177178 fi
178179
179- # Create .github/workflows directory if it doesn't exist
180180 mkdir -p .github/workflows
181181
182- # Copy the security scanner workflow template and replace placeholders
183182 sed "s|{ DEFAULT_BRANCH }|$BASE_BRANCH|g" \
184183 ../scanner-repo/.github/templates/security-code-scanner.yml \
185184 > .github/workflows/security-code-scanner.yml
186185
187186 git add .github/workflows/security-code-scanner.yml
187+
188+ if git diff --cached --quiet; then
189+ echo "::notice::Workflow file already exists and matches — nothing to commit"
190+ echo "skipped=true" >> "$GITHUB_OUTPUT"
191+ exit 0
192+ fi
193+
188194 git commit -m "chore: add MetaMask Security Code Scanner workflow
189195
190196 This PR adds the MetaMask Security Code Scanner workflow to enable
@@ -198,16 +204,16 @@ jobs:
198204 To configure the scanner for your repository's specific needs,
199205 please review the workflow file and adjust as necessary."
200206
201- # For empty repos, rename the branch to match the base branch
202207 if [ "$IS_EMPTY" = "true" ]; then
203208 git branch -M "$BRANCH_NAME"
204209 fi
205210
206211 git push -u origin "$BRANCH_NAME"
212+ echo "skipped=false" >> "$GITHUB_OUTPUT"
207213 shell : bash
208214
209215 - name : Create Pull Request
210- if : steps.check_opt_out.outputs.opted_out != 'true' && steps.check_empty.outputs.is_empty == 'false'
216+ if : steps.check_opt_out.outputs.opted_out != 'true' && steps.check_empty.outputs.is_empty == 'false' && steps.create_branch.outputs.skipped != 'true'
211217 working-directory : target-repo
212218 env :
213219 GH_TOKEN : ${{ secrets.ONBOARDING_TOKEN }}
@@ -231,7 +237,7 @@ jobs:
231237 shell : bash
232238
233239 - name : Output PR URL
234- if : steps.check_opt_out.outputs.opted_out != 'true' && steps.check_empty.outputs.is_empty == 'false'
240+ if : steps.check_opt_out.outputs.opted_out != 'true' && steps.check_empty.outputs.is_empty == 'false' && steps.create_branch.outputs.skipped != 'true'
235241 working-directory : target-repo
236242 env :
237243 GH_TOKEN : ${{ secrets.ONBOARDING_TOKEN }}
@@ -242,11 +248,23 @@ jobs:
242248 shell : bash
243249
244250 - name : Output commit info for empty repo
245- if : steps.check_opt_out.outputs.opted_out != 'true' && steps.check_empty.outputs.is_empty == 'true'
251+ if : steps.check_opt_out.outputs.opted_out != 'true' && steps.check_empty.outputs.is_empty == 'true' && steps.create_branch.outputs.skipped != 'true'
246252 run : |
247253 echo "✅ Initial commit pushed to https://github.com/$REPO/tree/$BASE_BRANCH"
248254 echo "Repository was empty - workflow file added directly to $BASE_BRANCH branch"
249255 shell : bash
250256 env :
251257 REPO : ${{ steps.target.outputs.repository }}
252258 BASE_BRANCH : ${{ steps.target.outputs.base_branch }}
259+
260+ - name : Post to Slack channel on failure
261+ if : ${{ failure() && env.SLACK_WEBHOOK_URL != '' }}
262+ uses : slackapi/slack-github-action@007b2c3c751a190b6f0f040e47ed024deaa72844
263+ with :
264+ payload : |
265+ {
266+ "text": "Onboarding failed for ${{ steps.target.outputs.repository }} - Run: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
267+ }
268+ env :
269+ SLACK_WEBHOOK_URL : ${{ secrets.APPSEC_BOT_SLACK_WEBHOOK }}
270+ SLACK_WEBHOOK_TYPE : INCOMING_WEBHOOK
0 commit comments