GitHub Action: auto-format
Github Action Auto-Format runs several repository "hygiene" tasks for repositories:
- The
readmetarget will rebuildREADME.mdfromREADME.yaml. - The
github_formattarget adds all of Cloud Posse's standard repository housekeeping files (including GitHub Actions workflows) to the repository's.githubfolder. - The
terraform_formattarget ensures consistent formatting across all Terraform files in the repository.
Usage
If you haven't already, follow the steps in the quickstart section.
To choose which pieces of functionality will be executed, modify the script-names: input to the cloudposse/github-action-auto-format step to be a comma-separated list of one or more targets (e.g., script-names: readme,terraform_format,github_format).
This is an exhaustive list of all valid script-names:
readmegithub_formatterraform_formatIf you're using theauto-format.ymlworkflow file distributed within this repository, then the Auto-format GitHub Action will trigger on pull request events, once a day at 7am UTC, and upon manual triggering via theworkflow_dispatchmechanism.
Quick Start
Here's how to get started...
- Copy
.github/workflows/auto-format.ymlto the corresponding folder in your target repo. - Generate a Personal Access Token (PAT) that with the
workflowpermission using a GitHub account that haswritepermissions in the target repo by following the directions here and selecting theworkflowtick box on the token creation screen. - Add this token as a GitHub secret in your target repository and set the
workflow-tokeninput of thegithub-action-auto-formatstep to the name of your secret. - Set the
bot-nameinput of thegithub-action-auto-formatstep to the GitHub username of the user who generated the token in step 2. *This user must havewritepermissions in the target repo.` - By default, the Auto-Format GitHub Action will execute all of its scripts when run. If you'd like to use a subset of the full functionality, modify the
script-namesinput of thegithub-action-auto-formatstep as described in the usage section. - (Optional) You may want to change when the scheduled cron trigger is executed. If you'd like a guide, here's a useful resource for help in crafting cron strings - https://crontab.guru/
- (Optional) CloudPosse recommends pinning to specific versions of actions for ease of long-term maintenance. If you care to edit the pin in
auto-format.ymlfrommainto a specific version, feel free to consult https://github.com/cloudposse/github-action-auto-format/releases for a list of available versions.
Examples
Here's a real world example:
github-action-auto-format- Cloud Posse's self-testing Auto-Format GitHub Action
Inputs
| Name | Description | Default | Required |
|---|---|---|---|
| actions-files-checkout-path | The path on the github-runner where the auto-format action scripts are checked out at runtime | github-action-auto-format | false |
| bot-email | Email address associated with the GitHub user for writing new commits | N/A | false |
| bot-name | GitHub username for writing new commits | cloudpossebot | false |
| format-task | Name of formatting task to execute. (Options include: readme, github, terraform, and context.) | N/A | true |
| workflow-token | GitHub Token for use in github\_format.sh and PR creation steps. This token must be granted workflows permissions. | N/A | true |