Skip to content

Commit 7c8ca48

Browse files
authored
Merge pull request #31 from attogram/feature/manual-prettier-workflow
feat: Add manually triggered Prettier workflow
2 parents 291c276 + c133c82 commit 7c8ca48

File tree

4 files changed

+75
-1
lines changed

4 files changed

+75
-1
lines changed

.github/workflows/prettier.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# .github/workflows/prettier.yml
2+
3+
name: Format Code with Prettier
4+
5+
# This workflow is triggered manually from the Actions tab.
6+
on:
7+
workflow_dispatch:
8+
9+
jobs:
10+
format:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
# Checks out the repository code so the workflow can access it.
15+
- name: Checkout Code
16+
uses: actions/checkout@v4
17+
with:
18+
# The GITHUB_TOKEN is required to allow the workflow to push changes
19+
# back to the repository.
20+
token: ${{ secrets.GITHUB_TOKEN }}
21+
22+
# Sets up the Node.js environment, which is needed to run Prettier.
23+
- name: Setup Node.js
24+
uses: actions/setup-node@v4
25+
with:
26+
node-version: "20" # Using a recent Long-Term Support (LTS) version of Node.js
27+
cache: "npm" # Cache npm dependencies for faster runs
28+
29+
# Installs the project's dependencies, including Prettier itself,
30+
# as defined in package.json and package-lock.json.
31+
- name: Install Dependencies
32+
run: npm install
33+
34+
# Runs Prettier to format all files in the repository.
35+
# The --write flag tells Prettier to modify files in-place.
36+
- name: Run Prettier
37+
run: npx prettier --write .
38+
39+
# This action checks if Prettier made any changes. If so, it commits
40+
# them back to the branch that the workflow was run on.
41+
- name: Commit Changes
42+
uses: stefanzweifel/git-auto-commit-action@v5
43+
with:
44+
commit_message: "style: Format code with Prettier"
45+
branch: ${{ github.ref }}
46+
# The file_pattern is set to all files, ensuring any change made by
47+
# Prettier is committed.
48+
file_pattern: "**/*.*"

docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ This directory contains the documentation for the `base` project.
1212
- **[Guiding AI with `AGENTS.md`](./agents-md-guide.md)**: An explanation of how to use the `AGENTS.md` file to provide persistent instructions to AI agents.
1313
- **[The `package.json` files](./package-json-guide.md)**: An explanation of the `package.json` and `package-lock.json` files used for development tooling.
1414
- **[GitHub Workflows](./github-workflows.md)**: An explanation of the CI/CD workflows for linting, testing, and releasing.
15+
- **[Manually Formatting Code with the Prettier Workflow](./prettier-workflow.md)**: A guide to using the manually-triggered workflow to format the codebase.
1516
- **[Licensing Information](./licensing.md)**: Details on the MIT License and how to properly attribute copyright.
1617
- **[Deploying to Render.com](./render.md)**: Instructions for deploying the project to the Render.com platform.
1718
- **[Merging `base` Into an Existing Repository](./merging-base.md)**: A guide on how to incorporate `base` into an existing project.

docs/prettier-workflow.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Prettier Workflow
2+
3+
This repository includes a GitHub Actions workflow that automatically formats all files in the repository using [Prettier](https://prettier.io/), a widely-used code formatter. This ensures a consistent and readable code style across the entire project.
4+
5+
## Workflow Details
6+
7+
- **Workflow File:** [`.github/workflows/prettier.yml`](../.github/workflows/prettier.yml)
8+
- **Trigger:** This workflow is **not** run automatically. It must be triggered manually.
9+
- **Action:** When run, the workflow will:
10+
1. Check out the code from the branch it was run on.
11+
2. Install the necessary dependencies (`npm install`).
12+
3. Run `npx prettier --write .` to format all files.
13+
4. If any files were changed by Prettier, the workflow will automatically commit the changes back to the same branch with the commit message `style: Format code with Prettier`.
14+
15+
## How to Use
16+
17+
To run the formatting workflow:
18+
19+
1. Navigate to the **Actions** tab of the repository on GitHub.
20+
2. In the left sidebar, click on **"Format Code with Prettier"**.
21+
3. Above the list of previous runs, you will see a message: "This workflow has a `workflow_dispatch` event trigger."
22+
4. Click the **"Run workflow"** button.
23+
5. Choose the branch you want to format and click the **"Run workflow"** button again.
24+
25+
The workflow will then execute, and any formatting changes will be pushed to your chosen branch. This is useful for cleaning up a feature branch before creating a pull request.

docs/using-github-discussions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Using GitHub Discussions
22

3-
GitHub Discussions is a feature designed to be the community forum for your project, right alongside your code.
3+
GitHub Discussions is a feature designed to be the community forum for your project, right alongside your code.
44
It provides a dedicated space for conversations, Q&A, and idea sharing, keeping your issue tracker clean and focused on actionable tasks.
55

66
## Issues vs. Discussions: What's the Difference?

0 commit comments

Comments
 (0)