-
Notifications
You must be signed in to change notification settings - Fork 0
Add first version of code, docs and tests #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e88adf2
Add first version of code, docs and tests
gabmontes b5f32f8
Fix dependency types
gabmontes 660fb75
Use hemilabs/actions
gabmontes 19457d9
Add .DS_Store to .gitignore
gabmontes 3dda338
Clean up Knip ignore list and cli.js
gabmontes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,3 @@ | ||
| { | ||
| "extends": ["bloq"] | ||
| } |
This file contains hidden or 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,17 @@ | ||
| { | ||
| "extends": ["bloq", "bloq/node", "prettier"], | ||
| "overrides": [ | ||
| { | ||
| "files": ["bin/*"], | ||
| "rules": { | ||
| "no-console": "off", | ||
| "no-process-exit": "off" | ||
| } | ||
| }, | ||
| { | ||
| "extends": ["bloq/mocha", "prettier"], | ||
| "files": ["*.test.js"] | ||
| } | ||
| ], | ||
| "root": true | ||
| } |
This file contains hidden or 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,15 @@ | ||
| name: JS Checks | ||
|
|
||
| on: | ||
| pull_request: | ||
| push: | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| run-checks-and-tests: | ||
| uses: hemilabs/actions/.github/workflows/js-checks.yml@63592c8da7b84d0953f8ed3b7ca89d43142a8605 # PR#22 | ||
| with: | ||
| node-versions: '["20","22","24"]' |
This file contains hidden or 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,15 @@ | ||
| name: NPM Publish | ||
|
|
||
| on: | ||
| release: | ||
| types: | ||
| - published | ||
|
|
||
| jobs: | ||
| publish-to-npm: | ||
| permissions: | ||
| contents: read | ||
| id-token: write | ||
| uses: hemilabs/actions/.github/workflows/npm-publish.yml@63592c8da7b84d0953f8ed3b7ca89d43142a8605 # PR#22 | ||
| secrets: | ||
| NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
This file contains hidden or 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,3 @@ | ||
| .DS_Store | ||
| .eslintcache | ||
| node_modules |
This file contains hidden or 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,3 @@ | ||
| #!/usr/bin/env sh | ||
|
|
||
| commitlint --edit $1 |
This file contains hidden or 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,3 @@ | ||
| #!/usr/bin/env sh | ||
|
|
||
| lint-staged |
This file contains hidden or 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,3 @@ | ||
| #!/usr/bin/env sh | ||
|
|
||
| npm test |
This file contains hidden or 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,3 @@ | ||
| { | ||
| "ignoreDependencies": ["eslint-config-prettier"] | ||
| } |
This file contains hidden or 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,8 @@ | ||
| { | ||
| "!(.github/workflows/*.yml|*.js|package.json)": [ | ||
| "prettier --ignore-unknown --write" | ||
| ], | ||
| ".github/workflows/*.yml": ["npx .", "prettier --write"], | ||
| "*.js": ["eslint --cache --fix --quiet", "prettier --write"], | ||
| "package.json": ["better-sort-package-json", "prettier --write"] | ||
| } | ||
This file contains hidden or 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 @@ | ||
| 20 |
This file contains hidden or 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 @@ | ||
| {} |
This file contains hidden or 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,52 @@ | ||
| # better-sort-github-actions-files | ||
|
|
||
| Sorts GitHub Actions workflow or composite action files following these rules: | ||
|
|
||
| 1. The known properties are sorted following the order in the [Workflow syntax for GitHub Actions](https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions) or [Metadata syntax for GitHub Actions](https://docs.github.com/en/actions/sharing-automations/creating-actions/metadata-syntax-for-github-actions). | ||
| 1. All other properties are sorted in alphabetical order. | ||
|
|
||
| ## Motivation and prior art | ||
|
|
||
| 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](https://github.com/hemilabs/better-sort-package-json) files and now was the turn of these YAML files. | ||
|
|
||
| ## CLI | ||
|
|
||
| This package can be installed globally, then used to sort GitHub Actions files: | ||
|
|
||
| ```sh | ||
| 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: | ||
|
|
||
| ```sh | ||
| npx better-sort-github-actions <path-to-a-github-actions-file-to-sort> | ||
| ``` | ||
|
|
||
| ## API | ||
|
|
||
| Install the package: | ||
|
|
||
| ```sh | ||
| npm install better-sort-github-actions | ||
| ``` | ||
|
|
||
| Then use it to sort the contents of a YAML file: | ||
|
|
||
| ```js | ||
| const fs = require("node:fs"); | ||
| const { sort } = require("better-sort-github-actions"); | ||
|
|
||
| fs.writeFileSync(path, sort(fs.readFileSync(path, "utf8"))); | ||
| ``` | ||
|
|
||
| ## Automatically sort on commit | ||
|
|
||
| To let [`lint-staged`](https://github.com/lint-staged/lint-staged) take care of sorting the GitHub Actions files automatically use: | ||
|
|
||
| ```json | ||
| { | ||
| ".github/workflows/*.yml": ["better-sort-github-actions"] | ||
| } | ||
| ``` |
This file contains hidden or 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,22 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| "use strict"; | ||
|
|
||
| const { readFileSync, writeFileSync } = require("node:fs"); | ||
|
|
||
| const { sort } = require(".."); | ||
|
|
||
| const files = process.argv.slice(2); | ||
| if (!files.length) { | ||
| console.error("Usage: better-sort-github-actions <file> [<file>...]"); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| try { | ||
| files.forEach(function (file) { | ||
| writeFileSync(file, sort(readFileSync(file, "utf8"))); | ||
| }); | ||
| } catch (error) { | ||
| console.error(`Error: ${error.message}`); | ||
| process.exit(1); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.