-
Notifications
You must be signed in to change notification settings - Fork 494
Actually continuously integrate #1129
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
base: main
Are you sure you want to change the base?
Changes from all commits
cbfa4b0
094bf39
b2e7f7c
ab23a5b
d54325b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
name: Format YAML files | ||
inputs: | ||
token: | ||
required: true | ||
default: "${{ github.token }}" | ||
runs: | ||
using: node20 | ||
main: index.js |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const core = require("@actions/core") | ||
const fs = require("fs") | ||
const yaml = require("js-yaml") | ||
|
||
try { | ||
const yamlFiles = fs.readdirSync("./").filter(file => file.endsWith(".yaml")) | ||
format(yamlFiles) | ||
} catch (error) { | ||
core.setFailed(error.message) | ||
} | ||
|
||
function format(yamlFiles) { | ||
yamlFiles.forEach(file => { | ||
const content = fs.readFileSync(file) | ||
|
||
let data = yaml.load(content) | ||
data = consistent(data) | ||
data = sort(data) | ||
|
||
const formattedContent = yaml.dump(data, {quotingType: '"', lineWidth: -1}) | ||
fs.writeFileSync(file, formattedContent) | ||
}) | ||
} | ||
|
||
function consistent(data) { // one-record subdomains might not be an array | ||
for (const key in data) { | ||
if (!Array.isArray(data[key])) { | ||
const array = [data[key]] | ||
data[key] = array | ||
} | ||
} | ||
|
||
return data | ||
} | ||
|
||
function sort(subdomains) { | ||
const sortedSubdomains = {} | ||
Object.keys(subdomains).sort().forEach(key => { | ||
sortedSubdomains[key] = subdomains[key] | ||
}) | ||
|
||
for (const subdomain in sortedSubdomains) { | ||
const records = sortedSubdomains[subdomain] | ||
for (const record in records) { | ||
const sortedOptions = {} | ||
Object.keys(records[record]).sort().forEach(option => { | ||
sortedOptions[option] = sortedSubdomains[subdomain][record][option] | ||
}) | ||
sortedSubdomains[subdomain][record] = sortedOptions | ||
} | ||
} | ||
|
||
return sortedSubdomains | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.