Complete GitHub Actions toolkit with generation and validation capabilities for workflows, custom actions, and CI/CD configurations
97
97%
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Advisory
Suggest reviewing before use
A popular open-source project on GitHub receives many pull requests from external contributors (forks). The maintainers want two automated behaviours:
Auto-label PRs based on the PR title: if the title starts with fix: apply the bug label; if it starts with feat: apply the enhancement label. This requires write access to the repository to add labels.
Upload code coverage to an external service after CI passes. The upload requires a CODECOV_TOKEN secret that must not be exposed to untrusted fork code.
A previous engineer drafted a single workflow that uses pull_request_target so it can access secrets, and it checks out the PR's head commit directly. Before shipping this, the team wants it reviewed and rewritten following safe patterns. The draft is provided below.
Produce a corrected and production-ready YAML file (or files) that implement both requirements safely. Save your output as .github/workflows/pr-automation.yml (and optionally a second workflow file if splitting is the safer approach).
The following draft workflow is provided. Extract it before beginning.
=============== FILE: draft-pr-automation.yml =============== name: PR Automation
on: pull_request_target: types: [opened, synchronize]
jobs: label-and-coverage: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: ref: ${{ github.event.pull_request.head.sha }}
- name: Run tests and coverage
run: npm test -- --coverage
- name: Upload coverage
run: |
curl -s https://codecov.io/bash -o codecov.sh
bash codecov.sh -t ${{ secrets.CODECOV_TOKEN }}
- name: Label PR based on title
run: |
TITLE="${{ github.event.pull_request.title }}"
if echo "$TITLE" | grep -q "^fix:"; then
gh pr edit ${{ github.event.number }} --add-label bug
elif echo "$TITLE" | grep -q "^feat:"; then
gh pr edit ${{ github.event.number }} --add-label enhancement
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}