Make github actions workflow

From dotnet/dotnet · View interactive version

Make github actions workflow is an AI agent skill from the GitHub repository dotnet/dotnet. Create or modify GitHub Actions workflows for CI, automation, or PR management. Use when asked to create, scaffold, add, extend, or fix a workflow (.yml file under .github/workflows/), including existing pull-request policy and comment automation.

How to use this skill

Skill file

Create GitHub Actions Workflow

Create and configure GitHub Actions workflows that follow this repository's conventions and patterns. Workflows automate tasks like CI validation, PR management, issue labeling, and notifications.

Repository Conventions

This repository uses specific patterns across all workflows. Follow these conventions when creating new workflows:

File Location and Naming

Runner

Permissions

Scripting

Error Handling

Workflow

Step 1: Understand the Requirements

Before writing the workflow, clarify:

Step 2: Choose the Trigger Event

| Use case | Event | Notes |

|----------|-------|-------|

| PR opened/updated | pull_request | Read-only access to PR |

| PR with write access | pull_request_target | Can comment, label, close |

| PR merged | pull_request_target: [closed] | Check github.event.pull_request.merged == true |

| CI checks complete | check_suite: [completed] | Filter app.slug != 'github-actions' to skip self |

| Code pushed | push | Filter by branches/paths |

| Manual trigger | workflow_dispatch | Add inputs: for parameters |

| Scheduled | schedule | Use cron syntax |

Step 3: Write the Workflow

Create the YAML file following this template:

# Description of what this workflow does and why.

name: Descriptive Workflow Name

on:
  <trigger_event>:
    types: [<event_types>]

permissions:
  <resource>: <read|write>

jobs:
  <job-name>:
    if: <guard_condition>  # Optional: skip when not needed
    runs-on: ubuntu-latest
    steps:
      - name: Descriptive step name
        uses: actions/github-script@v8
        with:
          script: |
            // Your logic here

Step 4: Implement Guard Conditions

Add conditions to avoid unnecessary runs:

For pull_request_target policy workflows that react to opened, edited, and reopened:

Step 5: Validate

After creating the workflow:

Existing Workflows in This Repository

Study these workflows as reference:

| Workflow | Trigger | Purpose |

|----------|---------|---------|

| validate-pr-target-branch.yml | pull_request_target: [opened, edited, reopened] | Closes external PRs targeting release branches, adds community labels |

| label-and-milestone-issues.yml | pull_request_target: [closed] | Labels and milestones issues when their fixing PR is merged |

| copilot-setup-steps.yml | workflow_dispatch, push, pull_request | Sets up the development environment for Copilot |

| inter-branch-merge-flow.yml | push to release/** | Triggers inter-branch merge via arcade |

Common Patterns

Commenting on a PR

await github.rest.issues.createComment({
  owner: context.repo.owner,
  repo: context.repo.repo,
  issue_number: prNumber,
  body: 'Comment text'
});

Checking User Permissions

const { data: permissions } = await github.rest.repos.getCollaboratorPermissionLevel({
  owner: context.repo.owner,
  repo: context.repo.repo,
  username: context.actor
});
const hasWriteAccess = ['admin', 'write'].includes(permissions.permission);

Updating Bot-Owned Comments Idempotently

A hidden marker identifies the workflow's comment but does not establish ownership: contributors and other apps can place the same marker in their comments. Match both the marker and the exact github-actions[bot] login, then update that comment or create a new one. A generic user.type === 'Bot' check does not establish workflow ownership. Preserve the workflow's pinned action SHA and never execute code from a pull-request fork in a pull_request_target job.

const marker = '<!-- validate-pr-target-branch -->';
const comments = await github.paginate(github.rest.issues.listComments, {
  owner: context.repo.owner,
  repo: context.repo.repo,
  issue_number: prNumber,
  per_page: 100
});

const body = `${marker}\nComment text`;
const existing = comments.find(comment =>
  comment.user?.login === 'github-actions[bot]' && comment.body?.includes(marker));

if (existing) {
  await github.rest.issues.updateComment({
    owner: context.repo.owner,
    repo: context.repo.repo,
    comment_id: existing.id,
    body
  });
} else {
  await github.rest.issues.createComment({
    owner: context.repo.owner,
    repo: context.repo.repo,
    issue_number: prNumber,
    body
  });
}

Reading Repository Files at a Specific Commit

const { data: fileData } = await github.rest.repos.getContent({
  owner, repo,
  path: 'eng/Versions.props',
  ref: commitSha
});
const content = Buffer.from(fileData.content, 'base64').toString('utf-8');

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.