Example result: Write a GitHub Actions workflow
AI-generated example · CI Workflow
Updated

Write a GitHub Actions workflow

This prompt writes a GitHub Actions workflow, for example to run tests, for a project in the language you name.

text-github-actions-workflow — chatgpt — 55 words

Write a GitHub Actions workflow for a [LANGUAGE] project.

It should: [RUN TESTS / LINT / BUILD / DEPLOY] on [EVENT, e.g. pull requests to main].
Deployment target: [TARGET]
Caching needed: [DEPENDENCIES]

Provide the YAML with comments, explain each step, list the secrets I must add and suggest one improvement to make the pipeline faster.

Pin action versions and keep secrets in repository settings, never in the workflow file.

Get a better result

What you will get

A commented workflow YAML for your project that runs your chosen jobs on the event you named, with dependency caching, a step by step explanation, the secrets you need to add and one idea to make it faster.

Why it works

The prompt names the jobs, the trigger and the target, which are the three choices every workflow needs. Asking for comments and an explanation of each step means you can maintain it later. The secrets list stops the most common first run failure, a missing secret, and the speed idea is often caching, which saves minutes on every run.

Common mistake

Secrets are written into the YAML file.

Fix: Keep them in the repository settings and refer to them by name, as the tip says. Ask it to list each name it uses.

Also watch for
  • The deploy job runs on every pull request. Ask for deploy to run only on pushes to main, and only after the test job passes.
  • Actions are used without a version. Ask it to pin every action to a version tag or commit, as the tip says, and to explain how to update them later.
Try a variation: test on several versions

Ask for a matrix that runs the tests on two or three language versions, and how to stop the whole run when one fails.

Still not right? Reply with this

The first run failed at this step: [PASTE LOG]. Explain the cause and give me the corrected YAML for that step.

More chat & writing prompts

See all 465 →