Sorts GitHub Actions workflow or composite action files following these rules:
- The known properties are sorted following the order in the Workflow syntax for GitHub Actions or Metadata syntax for GitHub Actions.
- All other properties are sorted in alphabetical order.
Having a consistent properties order in the files helps with the readability and maintainability but following the exact order of the docs can be tricky when done manually. We resolved the same problem in the past for package.json files and now was the turn of these YAML files.
This package can be installed globally, then used to sort GitHub Actions files:
npm install --global better-sort-github-actions
better-sort-github-actions <path-to-a-github-actions-file-to-sort>In addition, it can be used without installing it:
npx better-sort-github-actions <path-to-a-github-actions-file-to-sort>Install the package:
npm install better-sort-github-actionsThen use it to sort the contents of a YAML file:
const fs = require("node:fs");
const { sort } = require("better-sort-github-actions");
fs.writeFileSync(path, sort(fs.readFileSync(path, "utf8")));To let lint-staged take care of sorting the GitHub Actions files automatically use:
{
".github/workflows/*.yml": ["better-sort-github-actions"]
}