Skip to content

CICD-181 · Separate PR runs from trusted publishing ​

Encyclopedia · Workflow security fundamentals · All snippets

Previous · CICD-180 · Next · CICD-182

1. Where it fits ​

  • Placement .github/workflows/ci.yml, inside the relevant job.
  • Prerequisites trusted repository, verified inputs and read-only default access.
  • Platforms github-actions, gitea-actions.

2. Copy the snippet ​

yaml
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
permissions:
  contents: read
  packages: write

3. How it works ​

The condition limits publishing to a push updating main. The permissions block grants source read and package write only to that trusted job.

4. Verify the result ​

Put on the publish job and require protected main.

Validation syntax-validated (YAML parse). Status definitions.