Skip to content

fix: secure auto-format workflow against fork-based CI attacks #3

fix: secure auto-format workflow against fork-based CI attacks

fix: secure auto-format workflow against fork-based CI attacks #3

Workflow file for this run

name: Auto Format
on:
pull_request:
types: [opened, synchronize]
workflow_dispatch:
permissions:
contents: write
jobs:
auto-format:
# Only run on internal PRs (same repo), not forks
if: github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest

Check failure on line 14 in .github/workflows/auto-format.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/auto-format.yml

Invalid workflow file

You have an error in your yaml syntax on line 14
container: osodevops/build-harness:latest
steps:
- uses: actions/checkout@v4
if: github.event.pull_request.state == 'open'
name: Checkout PR branch
with: ref: ${{ github.event.pull_request.head.ref }}
persist-credentials: true
- name: Auto Format
if: github.event.pull_request.state == 'open'
shell: bash
run: make BUILD_HARNESS_PATH=/build-harness PACKAGES_PREFER_HOST=true -f /build-harness/templates/Makefile.build-harness pr/readme/host
# Commit changes (if any) to the PR branch
- name: Commit changes to the PR branch
if: github.event.pull_request.state == 'open'
shell: bash
id: commit
env:
SENDER: ${{ github.event.sender.login }}
run: |
set -x
output=$(git diff --name-only)
if [ -n "$output" ]; then
echo "Changes detected. Pushing to the PR branch"
git config --global user.name 'osotopbot'
git config --global user.email '72751587+osotopbot@users.noreply.github.com'
git add -A
git commit -m "Auto Format"
# Prevent looping by not pushing changes in response to changes from osotopbot
[[ $SENDER == "osotopbot" ]] || git push
# Set status to fail, because the push should trigger another status check,
# and we use success to indicate the checks are finished.
echo "changed=true" >> "$GITHUB_OUTPUT"
exit 1
else
echo "changed=false" >> "$GITHUB_OUTPUT"
echo "No changes detected"
fi