Use GitHub Actions native features and follow best practices to create maintainable, secure, and reliable CI workflows:

  1. Use working-directory instead of manual cd commands ```yaml

    DO THIS

    INSTEAD OF THIS

  2. Pin specific SHA commits for third-party actions ```yaml

    DO THIS

    INSTEAD OF THIS

  3. Handle all possible job states in conditional logic
    update-existing: $
    
  4. Scope permissions to the minimum required level
    # DO THIS - scope permissions per job
    jobs:
      build:
        permissions:
          contents: read
          attestations: write
          id-token: write
    
    # INSTEAD OF THIS - overly broad permissions
    permissions:
      contents: read
      attestations: write
      id-token: write
    

These practices improve workflow reliability, security, and maintainability while making troubleshooting easier.