-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Duncan McClean
committed
Aug 12, 2022
0 parents
commit a440e65
Showing
5 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# ignore all files by default | ||
* | ||
# include required files with an exception | ||
!entrypoint.sh | ||
!README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FROM node:16 | ||
|
||
RUN npm install antlers-formatter -g | ||
|
||
COPY "entrypoint.sh" "/entrypoint.sh" | ||
RUN chmod +x /entrypoint.sh | ||
ENTRYPOINT ["/entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Antlers Formatting Action | ||
|
||
A GitHub Action to automatically format/lint Antlers files. | ||
|
||
## Usage | ||
|
||
If you don't need to change anything (config-wise), add this step into your Actions workflow: | ||
|
||
```yaml | ||
- name: Antlers | ||
uses: duncanmcclean/[email protected] | ||
``` | ||
> Note: this action **won't automatically commit changes** to your repository. You'll need to use another action, like [`git-auto-commit-action`](https://github.com/stefanzweifel/git-auto-commit-action) to handle this. | ||
|
||
The `antlers-formatter` package which this action uses under the hood, allows for various different parameters. All of which are supported by this Action. You can see them all in use below (obviously not all of them will work at once, this is just as an example): | ||
|
||
```yaml | ||
- name: Antlers | ||
uses: duncanmcclean/[email protected] | ||
with: | ||
file: resources/views/layout.antlers.html | ||
directory: resources/views # this action defaults to resources/views | ||
output: formatted-views | ||
dump: true | ||
options: antlers-config.json | ||
``` | ||
|
||
For more information on the available parameters, [review the documentation](https://www.npmjs.com/package/antlers-formatter#installation) of the `antlers-formatter` package. | ||
|
||
### Example | ||
|
||
Just wanna copy this action into your project? Here's the **full workflow** we use internally at [Steadfast Collective](https://steadfastcollective.com): | ||
|
||
```yaml | ||
name: Antlers Toolbox | ||
on: | ||
pull_request: | ||
jobs: | ||
antlers: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ github.head_ref }} | ||
fetch-depth: 2 | ||
- name: Antlers | ||
uses: duncanmcclean/[email protected] | ||
- name: Commit changes | ||
uses: stefanzweifel/git-auto-commit-action@v4 | ||
with: | ||
commit_message: Antlers Code Style | ||
skip_fetch: true | ||
``` | ||
|
||
## Big thanks! | ||
|
||
Under the hood, this action uses the `antlers-format` package, part of the [Antlers Toolbox](https://antlers.dev) by John Koster. | ||
|
||
The structure of thie action was copied from the [`laravel-pint-action`](https://github.com/aglipanci/laravel-pint-action). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: 'Antlers' | ||
description: 'The Antlers action automatically formats Antlers files using the Antlers Toolbox.' | ||
author: 'Steadfast Collective <[email protected]>' | ||
inputs: | ||
file: | ||
description: "The path to the template to format." | ||
required: false | ||
|
||
directory: | ||
description: "A directory path to format all Antlers files, recursively." | ||
required: false | ||
|
||
output: | ||
description: "An optional file path where the formatted results will be saved. When specified, the file (or files in a directory) is not overwritten." | ||
required: false | ||
|
||
dump: | ||
description: "When specified, no results are saved to disk. Formatted results are displayed within the terminal." | ||
required: false | ||
|
||
options: | ||
description: "An optional file path to a JSON file containing Antlers formatting settings." | ||
required: false | ||
runs: | ||
using: 'docker' | ||
image: 'Dockerfile' | ||
args: | ||
- ${{ inputs.file }} | ||
- ${{ inputs.directory }} | ||
- ${{ inputs.output }} | ||
- ${{ inputs.dump }} | ||
- ${{ inputs.options }} | ||
branding: | ||
icon: 'eye' | ||
color: 'gray-dark' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
command_string=("antlersformat format") | ||
|
||
if [[ "${INPUT_FILE}" ]]; then | ||
command_string+=" --f=${INPUT_FILE}" | ||
else | ||
if [[ "${INPUT_DIRECTORY}" ]]; then | ||
command_string+=" --d=${INPUT_DIRECTORY}" | ||
else | ||
command_string+=" --d=resources/views" | ||
fi | ||
fi | ||
|
||
if [[ "${INPUT_OUTPUT}" ]]; then | ||
command_string+=" --out=${INPUT_OUTPUT}" | ||
fi | ||
|
||
if [[ "${INPUT_DUMP}" ]]; then | ||
command_string+=" --dd" | ||
fi | ||
|
||
if [[ "${INPUT_OPTIONS}" ]]; then | ||
command_string+=" --options=${INPUT_OPTIONS}" | ||
fi | ||
|
||
echo "Running Command: " "${command_string[@]}" | ||
|
||
${command_string[@]} |