From cd8eb6931d351b2e8372ad5738de102987eaefc9 Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Mon, 20 Feb 2023 01:27:19 -0700 Subject: [PATCH] feat: use nunjucks --- .github/actions/deps/action.yml | 3 +- .github/actions/get-workspaces/action.yml | 16 +++ .github/actions/release-manager/action.yml | 16 +++ .github/actions/release-please/action.yml | 16 +++ .github/actions/setup/action.yml | 9 +- .github/actions/test/action.yml | 3 +- .github/matchers/tap.json | 1 - .github/workflows/audit.yml | 2 +- .github/workflows/ci.yml | 4 +- .github/workflows/codeql-analysis.yml | 2 +- .github/workflows/post-dependabot.yml | 1 - .github/workflows/pull-request.yml | 2 +- .github/workflows/release.yml | 3 +- .gitignore | 4 + .release-please-manifest.json | 2 +- lib/config.js | 27 ++-- lib/options.js | 2 +- release-please-config.json | 2 +- test/apply/engines.js | 2 +- workspaces/config/lib/actions/audit.yml | 8 +- .../config/lib/actions/changed-files.yml | 4 +- .../config/lib/actions/changed-workspaces.yml | 8 +- .../config/lib/actions/conclude-check.yml | 6 +- .../config/lib/actions/create-check.yml | 18 +-- workspaces/config/lib/actions/deps.yml | 7 +- workspaces/config/lib/actions/lint.yml | 4 +- workspaces/config/lib/actions/setup.yml | 39 ++--- workspaces/config/lib/actions/test.yml | 7 +- .../config/lib/actions/upsert-comment.yml | 18 +-- workspaces/config/lib/files/CODEOWNERS | 2 +- workspaces/config/lib/files/commitlintrc.js | 2 +- workspaces/config/lib/files/dependabot.yml | 4 +- workspaces/config/lib/files/eslintrc.js | 10 +- workspaces/config/lib/files/gitignore | 6 +- workspaces/config/lib/files/npmrc | 2 +- workspaces/config/lib/files/pkg.json | 58 ++++---- .../lib/files/release-please-config.json | 10 +- .../lib/files/release-please-manifest.json | 2 +- workspaces/config/lib/index.js | 64 +++++---- workspaces/config/lib/partials/branches.yml | 7 - .../config/lib/partials/conclude-check.yml | 7 - .../config/lib/partials/create-check.yml | 8 -- workspaces/config/lib/partials/cron.yml | 3 - workspaces/config/lib/partials/if-org.yml | 2 +- workspaces/config/lib/partials/if-skip-pr.yml | 1 - .../config/lib/partials/job-defaults.yml | 4 - .../config/lib/partials/matrix-strategy.yml | 25 ---- .../lib/partials/workflow-call-inputs.yml | 7 - workspaces/config/lib/partials/workflow.yml | 82 +++++++++++ workspaces/config/lib/workflows/audit.yml | 16 ++- workspaces/config/lib/workflows/ci.yml | 51 +++---- .../config/lib/workflows/codeql-analysis.yml | 20 +-- .../config/lib/workflows/post-dependabot.yml | 41 +++--- .../config/lib/workflows/pull-request.yml | 22 +-- .../lib/workflows/release-integration.yml | 9 +- workspaces/config/lib/workflows/release.yml | 135 +++++++++--------- workspaces/rules/lib/rules/files/files.js | 2 +- workspaces/rules/lib/rules/files/parser.js | 36 +++-- workspaces/rules/lib/rules/files/template.js | 91 +++--------- workspaces/rules/package.json | 3 +- 60 files changed, 511 insertions(+), 457 deletions(-) create mode 100644 .github/actions/get-workspaces/action.yml create mode 100644 .github/actions/release-manager/action.yml create mode 100644 .github/actions/release-please/action.yml delete mode 100644 workspaces/config/lib/partials/branches.yml delete mode 100644 workspaces/config/lib/partials/conclude-check.yml delete mode 100644 workspaces/config/lib/partials/create-check.yml delete mode 100644 workspaces/config/lib/partials/cron.yml delete mode 100644 workspaces/config/lib/partials/if-skip-pr.yml delete mode 100644 workspaces/config/lib/partials/job-defaults.yml delete mode 100644 workspaces/config/lib/partials/matrix-strategy.yml delete mode 100644 workspaces/config/lib/partials/workflow-call-inputs.yml create mode 100644 workspaces/config/lib/partials/workflow.yml diff --git a/.github/actions/deps/action.yml b/.github/actions/deps/action.yml index 9b9e55c8..0bb26328 100644 --- a/.github/actions/deps/action.yml +++ b/.github/actions/deps/action.yml @@ -18,4 +18,5 @@ runs: steps: - name: Install Dependencies shell: ${{ inputs.shell }} - run: npm ${{ inputs.command }} ${{ inputs.flags }} + run: | + npm ${{ inputs.command }} ${{ inputs.flags }} diff --git a/.github/actions/get-workspaces/action.yml b/.github/actions/get-workspaces/action.yml new file mode 100644 index 00000000..806780af --- /dev/null +++ b/.github/actions/get-workspaces/action.yml @@ -0,0 +1,16 @@ +# This file is automatically added by @npmcli/template-oss. Do not edit. + +name: 'Get Workspaces' +description: 'Get workspaces' + +inputs: + files: + description: 'files' + +outputs: + flags: + description: 'workspace flags' + +runs: + using: 'node16' + main: 'index.js' diff --git a/.github/actions/release-manager/action.yml b/.github/actions/release-manager/action.yml new file mode 100644 index 00000000..806780af --- /dev/null +++ b/.github/actions/release-manager/action.yml @@ -0,0 +1,16 @@ +# This file is automatically added by @npmcli/template-oss. Do not edit. + +name: 'Get Workspaces' +description: 'Get workspaces' + +inputs: + files: + description: 'files' + +outputs: + flags: + description: 'workspace flags' + +runs: + using: 'node16' + main: 'index.js' diff --git a/.github/actions/release-please/action.yml b/.github/actions/release-please/action.yml new file mode 100644 index 00000000..806780af --- /dev/null +++ b/.github/actions/release-please/action.yml @@ -0,0 +1,16 @@ +# This file is automatically added by @npmcli/template-oss. Do not edit. + +name: 'Get Workspaces' +description: 'Get workspaces' + +inputs: + files: + description: 'files' + +outputs: + flags: + description: 'workspace flags' + +runs: + using: 'node16' + main: 'index.js' diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml index 1b92aa7a..710ec85f 100644 --- a/.github/actions/setup/action.yml +++ b/.github/actions/setup/action.yml @@ -69,16 +69,19 @@ runs: - name: Install npm@7 if: inputs.npm-version && steps.node-version.outputs.ten-or-lower shell: ${{ inputs.shell }} - run: npm i --prefer-online --no-fund --no-audit -g npm@7 + run: | + npm i --prefer-online --no-fund --no-audit -g npm@7 - name: Install npm@${{ inputs.npm-version }} if: inputs.npm-version && !steps.node-version.outputs.ten-or-lower shell: ${{ inputs.shell }} - run: npm i --prefer-online --no-fund --no-audit -g npm@${{ inputs.npm-version }} + run: | + npm i --prefer-online --no-fund --no-audit -g npm@${{ inputs.npm-version }} - name: npm Version shell: ${{ inputs.shell }} - run: npm -v + run: | + npm -v - name: Setup Dependencies if: inputs.deps == 'true' diff --git a/.github/actions/test/action.yml b/.github/actions/test/action.yml index ea792057..09587f44 100644 --- a/.github/actions/test/action.yml +++ b/.github/actions/test/action.yml @@ -15,4 +15,5 @@ runs: steps: - name: Test shell: ${{ inputs.shell }} - run: npm test --ignore-scripts ${{ inputs.flags }} + run: | + npm test --ignore-scripts ${{ inputs.flags }} diff --git a/.github/matchers/tap.json b/.github/matchers/tap.json index 6be0a85f..f9a7498f 100644 --- a/.github/matchers/tap.json +++ b/.github/matchers/tap.json @@ -1,5 +1,4 @@ { - "@npmcli/template-oss": "This file is automatically added by @npmcli/template-oss. Do not edit.", "problemMatcher": [ { "owner": "tap", diff --git a/.github/workflows/audit.yml b/.github/workflows/audit.yml index e73445c5..ab789bd4 100644 --- a/.github/workflows/audit.yml +++ b/.github/workflows/audit.yml @@ -19,7 +19,7 @@ on: jobs: audit: name: Audit Dependencies - if: github.repository_owner == 'npm' && !(!inputs.force && github.event_name == 'pull_request' && ((startsWith(github.head_ref, 'dependabot/') && contains(github.head_ref, '/npm-cli/template-oss')) || startsWith(github.head_ref, 'release/v*'))) + if: github.repository_owner == 'npm' && !(!inputs.force && github.event_name == 'pull_request' && ((startsWith(github.head_ref, 'dependabot/') && contains(github.head_ref, '/npmcli/template-oss')) || startsWith(github.head_ref, 'release/v*'))) runs-on: ubuntu-latest defaults: run: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4b7bf9e4..14f66b4b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,7 +32,7 @@ on: jobs: lint: name: Lint - if: github.repository_owner == 'npm' && !(!inputs.force && github.event_name == 'pull_request' && ((startsWith(github.head_ref, 'dependabot/') && contains(github.head_ref, '/npm-cli/template-oss')) || startsWith(github.head_ref, 'release/v*'))) + if: github.repository_owner == 'npm' && !(!inputs.force && github.event_name == 'pull_request' && ((startsWith(github.head_ref, 'dependabot/') && contains(github.head_ref, '/npmcli/template-oss')) || startsWith(github.head_ref, 'release/v*'))) runs-on: ubuntu-latest defaults: run: @@ -78,7 +78,7 @@ jobs: test: name: Test - ${{ matrix.platform.name }} - ${{ matrix.node-version }} - if: github.repository_owner == 'npm' && !(!inputs.force && github.event_name == 'pull_request' && ((startsWith(github.head_ref, 'dependabot/') && contains(github.head_ref, '/npm-cli/template-oss')) || startsWith(github.head_ref, 'release/v*'))) + if: github.repository_owner == 'npm' && !(!inputs.force && github.event_name == 'pull_request' && ((startsWith(github.head_ref, 'dependabot/') && contains(github.head_ref, '/npmcli/template-oss')) || startsWith(github.head_ref, 'release/v*'))) runs-on: ${{ matrix.platform.os }} defaults: run: diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index a6d9b046..e1a045ad 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -27,7 +27,7 @@ on: jobs: analyze: name: Analyze - if: github.repository_owner == 'npm' && !(!inputs.force && github.event_name == 'pull_request' && ((startsWith(github.head_ref, 'dependabot/') && contains(github.head_ref, '/npm-cli/template-oss')) || startsWith(github.head_ref, 'release/v*'))) + if: github.repository_owner == 'npm' && !(!inputs.force && github.event_name == 'pull_request' && ((startsWith(github.head_ref, 'dependabot/') && contains(github.head_ref, '/npmcli/template-oss')) || startsWith(github.head_ref, 'release/v*'))) runs-on: ubuntu-latest defaults: run: diff --git a/.github/workflows/post-dependabot.yml b/.github/workflows/post-dependabot.yml index 17780e1c..765c5252 100644 --- a/.github/workflows/post-dependabot.yml +++ b/.github/workflows/post-dependabot.yml @@ -16,7 +16,6 @@ jobs: contents: write outputs: sha: ${{ steps.sha.outputs.sha }} - # TODO: remove head_ref check after testing if: github.repository_owner == 'npm' && github.actor == 'dependabot[bot]' runs-on: ubuntu-latest defaults: diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index b4cbbda3..7446ad01 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -25,7 +25,7 @@ on: jobs: commitlint: name: Lint Commits - if: github.repository_owner == 'npm' && !(!inputs.force && github.event_name == 'pull_request' && ((startsWith(github.head_ref, 'dependabot/') && contains(github.head_ref, '/npm-cli/template-oss')) || startsWith(github.head_ref, 'release/v*'))) + if: github.repository_owner == 'npm' && !(!inputs.force && github.event_name == 'pull_request' && ((startsWith(github.head_ref, 'dependabot/') && contains(github.head_ref, '/npmcli/template-oss')) || startsWith(github.head_ref, 'release/v*'))) runs-on: ubuntu-latest defaults: run: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b95a15a1..13d6d2a9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -126,7 +126,8 @@ jobs: RELEASE_PR_NUMBER: ${{ needs.release.outputs.pr-number }} RELEASE_COMMENT_ID: ${{ needs.release.outputs.comment-id }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: npm run rp-pull-request --ignore-scripts -ws -iwr --if-present + run: | + npm run rp-pull-request --ignore-scripts -ws -iwr --if-present - name: Commit id: commit diff --git a/.gitignore b/.gitignore index 154a6528..0d743a24 100644 --- a/.gitignore +++ b/.gitignore @@ -5,13 +5,16 @@ # keep these !**/.gitignore +!/.commitlintrc.js !/.eslintrc.js !/.eslintrc.local.* !/.github/ !/.gitignore +!/.npmrc !/.release-please-manifest.json !/bin/ !/CHANGELOG* +!/CODE_OF_CONDUCT.md !/docs/ !/lib/ !/LICENSE* @@ -20,6 +23,7 @@ !/README* !/release-please-config.json !/scripts/ +!/SECURITY.md !/tap-snapshots/ !/test/ !/workspaces/ diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 4ffc2e28..df846409 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,5 +1,5 @@ { - "": "4.11.4", + ".": "4.11.4", "workspaces/config": "1.0.0", "workspaces/get-workspaces": "1.0.0", "workspaces/release-manager": "1.0.0", diff --git a/lib/config.js b/lib/config.js index e6087ff6..33a0b2e5 100644 --- a/lib/config.js +++ b/lib/config.js @@ -1,4 +1,4 @@ -const { merge: _merge } = require('lodash') +const { merge: _merge, pick, omit } = require('lodash') const { resolvePath } = require('./resolve-config.js') const merge = (...o) => _merge({}, ...o) @@ -6,12 +6,10 @@ const merge = (...o) => _merge({}, ...o) // Lookup a key in any config. First lookup the toplevel key // and then lookup the same key in either the toplevel `root` // or `workspace` objects -const getConfigs = (config, key, options) => { - const shared = config[key] - return [ - shared, - options.isRoot ? config.root?.[key] : config.workspace?.[key], - ] +const getConfigs = (config, keys, options) => { + const shared = pick(config, keys) + const pkg = options.pkg.isRoot ? config.root : config.workspace + return [shared, pkg].map(c => pick(c, keys)) } // Get the `data` config object and run it through the `postData` @@ -19,11 +17,10 @@ const getConfigs = (config, key, options) => { const getData = (options) => { const dataLayers = options.pkg.config.map(c => { const res = [] - const datas = getConfigs(c.config, 'data', options) - const postDatas = getConfigs(c.config, 'postData', options) - for (const [index, data] of Object.entries(datas)) { - const postData = typeof postDatas[index] === 'function' ? postDatas[index](data, options) : {} - res.push(merge(data, postData)) + const datas = getConfigs(c.config, ['data', 'postData'], options) + for (const { data, postData } of datas) { + const pData = typeof postData === 'function' ? postData(data, options) : {} + res.push(merge(data, pData)) } return merge(...res) }) @@ -59,9 +56,13 @@ const getRules = (command, options) => { if (ruleCommands) { const rule = merge(...ruleLayers.map(ruleLayer => { + const mergeKeys = ['files', 'rootFiles'] const layerRuleConfig = { ...ruleLayer, - options: merge(...getConfigs(ruleLayer, 'options', options)), + options: { + ...omit(ruleLayer.options, mergeKeys), + ...merge(...getConfigs(ruleLayer.options, mergeKeys, options)), + }, baseDir, } return config ? config(layerRuleConfig, options) : layerRuleConfig diff --git a/lib/options.js b/lib/options.js index 74a3261e..b01cdb12 100644 --- a/lib/options.js +++ b/lib/options.js @@ -43,7 +43,7 @@ const getPkgOptions = async ({ pkg, rootPkg }) => { relativeToPkg, workspacePaths: (pkg.json.workspaces || []).map(deglob), workspaceGlobs: (pkg.json.workspaces || []).map(posixGlob), - relPath, + relPath: relPath || '.', relToRoot: relativeToPkg(rootPkg.path), dir: posixDir(relPath), glob: posixGlob(relPath), diff --git a/release-please-config.json b/release-please-config.json index 3e324e4a..d785411e 100644 --- a/release-please-config.json +++ b/release-please-config.json @@ -32,7 +32,7 @@ } ], "packages": { - "": { + ".": { "package-name": "" }, "workspaces/config": {}, diff --git a/test/apply/engines.js b/test/apply/engines.js index c907e66b..49325c29 100644 --- a/test/apply/engines.js +++ b/test/apply/engines.js @@ -55,7 +55,7 @@ t.test('latest ci versions in workspace', async (t) => { 'source.json': '{ "node": {{{ json engines }}} }', 'index.js': `module.exports={ rootRepo:{add:{'target.json':'source.json'}}, - workspaceRepo:{add:{'target-{{ pkgNameFs }}.json':'source.json'}} + workspaceRepo:{add:{'target-{$ pkgNameFs $}.json':'source.json'}} }`, }, }, diff --git a/workspaces/config/lib/actions/audit.yml b/workspaces/config/lib/actions/audit.yml index 8af067e2..925ea3b5 100644 --- a/workspaces/config/lib/actions/audit.yml +++ b/workspaces/config/lib/actions/audit.yml @@ -6,16 +6,16 @@ runs: - name: Run Full Audit shell: bash run: | - if ! {{ rootNpmPath }} audit; then - COUNT=$({{ rootNpmPath }} audit --audit-level=none --json | jq -r '.metadata.vulnerabilities.total') + if ! {$ rootNpmPath $} audit; then + COUNT=$({$ rootNpmPath $} audit --audit-level=none --json | jq -r '.metadata.vulnerabilities.total') echo "::warning title=All Vulnerabilities::Found $COUNT" fi - name: Run Production Audit shell: bash run: | - if ! {{ rootNpmPath }} audit --omit=dev; then - COUNT=$({{ rootNpmPath }} audit --omit=dev --audit-level=none --json | jq -r '.metadata.vulnerabilities.total') + if ! {$ rootNpmPath $} audit --omit=dev; then + COUNT=$({$ rootNpmPath $} audit --omit=dev --audit-level=none --json | jq -r '.metadata.vulnerabilities.total') echo "::error title=Production Vulnerabilities::Found $COUNT" exit 1 fi diff --git a/workspaces/config/lib/actions/changed-files.yml b/workspaces/config/lib/actions/changed-files.yml index ae415a99..14e446fc 100644 --- a/workspaces/config/lib/actions/changed-files.yml +++ b/workspaces/config/lib/actions/changed-files.yml @@ -7,7 +7,7 @@ inputs: outputs: names: - value: $\{{ steps.files.outputs.result }} + value: ${{ steps.files.outputs.result }} runs: using: composite @@ -16,7 +16,7 @@ runs: uses: actions/github-script@v6 id: files with: - github-token: $\{{ inputs.token }} + github-token: ${{ inputs.token }} script: | const { repo: { owner, repo }, eventName, payload, sha } = context let files diff --git a/workspaces/config/lib/actions/changed-workspaces.yml b/workspaces/config/lib/actions/changed-workspaces.yml index 76fc0311..9239c318 100644 --- a/workspaces/config/lib/actions/changed-workspaces.yml +++ b/workspaces/config/lib/actions/changed-workspaces.yml @@ -8,22 +8,22 @@ inputs: outputs: flags: - value: $\{{ steps.workspaces.outputs.flags }} + value: ${{ steps.workspaces.outputs.flags }} runs: using: composite steps: - name: Get Changed Files uses: ./.github/actions/changed-files - if: $\{{ !inputs.files }} + if: ${{ !inputs.files }} id: files with: - token: $\{{ inputs.token }} + token: ${{ inputs.token }} - name: Get Workspaces shell: bash id: workspaces uses: ./.github/actions/get-workspaces with: - files: $\{{ inputs.files || steps.files.outputs.names }} + files: ${{ inputs.files || steps.files.outputs.names }} diff --git a/workspaces/config/lib/actions/conclude-check.yml b/workspaces/config/lib/actions/conclude-check.yml index 781d0070..b293cf59 100644 --- a/workspaces/config/lib/actions/conclude-check.yml +++ b/workspaces/config/lib/actions/conclude-check.yml @@ -18,6 +18,6 @@ runs: - name: Conclude Check uses: LouisBrunner/checks-action@v1.5.0 with: - token: $\{{ inputs.token }} - conclusion: $\{{ inputs.conclusion }} - check_id: $\{{ inputs.check-id }} + token: ${{ inputs.token }} + conclusion: ${{ inputs.conclusion }} + check_id: ${{ inputs.check-id }} diff --git a/workspaces/config/lib/actions/create-check.yml b/workspaces/config/lib/actions/create-check.yml index a5c119a3..69dbfce1 100644 --- a/workspaces/config/lib/actions/create-check.yml +++ b/workspaces/config/lib/actions/create-check.yml @@ -18,7 +18,7 @@ inputs: outputs: check-id: description: The ID of the check that was created - value: $\{{ steps.check.outputs.check_id }} + value: ${{ steps.check.outputs.check_id }} runs: using: composite @@ -27,9 +27,9 @@ runs: uses: actions/github-script@v6 id: workflow-job env: - JOB_NAME: $\{{ inputs.job-name }} + JOB_NAME: ${{ inputs.job-name }} with: - github-token: $\{{ inputs.token }} + github-token: ${{ inputs.token }} script: | const { JOB_NAME } = process.env const { repo: { owner, repo }, runId, serverUrl } = context @@ -46,7 +46,7 @@ runs: console.log(`found job: ${JSON.stringify(job, null, 2)}`) - const shaUrl = `${serverUrl}/${owner}/${repo}/commit/$\{{ inputs.sha }}` + const shaUrl = `${serverUrl}/${owner}/${repo}/commit/${{ inputs.sha }}` const summary = `This check is assosciated with ${shaUrl}\n\n` const message = job?.html_url ? `For run logs, click here: ${job.html_url}` @@ -60,8 +60,8 @@ runs: uses: LouisBrunner/checks-action@v1.5.0 id: check with: - token: $\{{ inputs.token }} - status: $\{{ inputs.job-status }} - name: $\{{ inputs.job-name }} - sha: $\{{ inputs.sha }} - output: $\{{ steps.workflow-job.outputs.result }} + token: ${{ inputs.token }} + status: ${{ inputs.job-status }} + name: ${{ inputs.job-name }} + sha: ${{ inputs.sha }} + output: ${{ steps.workflow-job.outputs.result }} diff --git a/workspaces/config/lib/actions/deps.yml b/workspaces/config/lib/actions/deps.yml index 3b595619..c25489ea 100644 --- a/workspaces/config/lib/actions/deps.yml +++ b/workspaces/config/lib/actions/deps.yml @@ -9,11 +9,12 @@ inputs: default: '' shell: description: shell to run on - default: '{{ shell }}' + default: '{$ shell $}' runs: using: composite steps: - name: Install Dependencies - shell: $\{{ inputs.shell }} - run: {{ rootNpmPath }} $\{{ inputs.command }} $\{{ inputs.flags }} + shell: ${{ inputs.shell }} + run: | + {$ rootNpmPath $} ${{ inputs.command }} ${{ inputs.flags }} diff --git a/workspaces/config/lib/actions/lint.yml b/workspaces/config/lib/actions/lint.yml index 606306d6..0b705d2b 100644 --- a/workspaces/config/lib/actions/lint.yml +++ b/workspaces/config/lib/actions/lint.yml @@ -11,8 +11,8 @@ runs: - name: Lint shell: bash run: | - {{ rootNpmPath }} run lint --ignore-scripts $\{{ inputs.flags }} + {$ rootNpmPath $} run lint --ignore-scripts ${{ inputs.flags }} - name: Post Lint shell: bash run: | - {{ rootNpmPath }} run postlint --ignore-scripts $\{{ inputs.flags }} + {$ rootNpmPath $} run postlint --ignore-scripts ${{ inputs.flags }} diff --git a/workspaces/config/lib/actions/setup.yml b/workspaces/config/lib/actions/setup.yml index 84e6c1b0..a44e33d5 100644 --- a/workspaces/config/lib/actions/setup.yml +++ b/workspaces/config/lib/actions/setup.yml @@ -4,16 +4,16 @@ description: Setup a repo with standard tools inputs: node-version: description: node version to use - default: '{{ last ciVersions }}' + default: '{$ ciVersions | last $}' npm-version: description: npm version to use - default: '{{#if updateNpm}}{{ npmSpec }}{{/if}}' + default: '{$ npmSpec if updateNpm $}' cache: description: whether to cache npm install or not - default: '{{ lockfile }}' + default: '{$ lockfile $}' shell: description: shell to run on - default: '{{ shell }}' + default: '{$ shell $}' deps: description: whether to run the deps step default: 'true' @@ -27,7 +27,7 @@ runs: using: composite steps: - name: Setup Git User - shell: $\{{ inputs.shell }} + shell: ${{ inputs.shell }} run: | git config --global user.email "npm-cli+bot@github.com" git config --global user.name "npm CLI robot" @@ -35,8 +35,8 @@ runs: - name: Setup Node uses: actions/setup-node@v3 with: - node-version: $\{{ inputs.node-version }} - cache: $\{{ (inputs.cache == 'true' && 'npm') || '' }} + node-version: ${{ inputs.node-version }} + cache: ${{ (inputs.cache == 'true' && 'npm') || '' }} - name: Check Node Version if: inputs.npm-version @@ -55,7 +55,7 @@ runs: - name: Update Windows npm # node 12 and 14 ship with npm@6, which is known to fail when updating itself in windows if: inputs.npm-version && runner.os == 'Windows' && steps.node-version.outputs.fourteen-or-lower - shell: $\{{ inputs.shell }} + shell: ${{ inputs.shell }} run: | curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz tar xf npm-7.5.4.tgz @@ -66,25 +66,28 @@ runs: - name: Install npm@7 if: inputs.npm-version && steps.node-version.outputs.ten-or-lower - shell: $\{{ inputs.shell }} - run: npm i --prefer-online --no-fund --no-audit -g npm@7 + shell: ${{ inputs.shell }} + run: | + npm i --prefer-online --no-fund --no-audit -g npm@7 - - name: Install npm@$\{{ inputs.npm-version }} + - name: Install npm@${{ inputs.npm-version }} if: inputs.npm-version && !steps.node-version.outputs.ten-or-lower - shell: $\{{ inputs.shell }} - run: npm i --prefer-online --no-fund --no-audit -g npm@$\{{ inputs.npm-version }} + shell: ${{ inputs.shell }} + run: | + npm i --prefer-online --no-fund --no-audit -g npm@${{ inputs.npm-version }} - name: npm Version - shell: $\{{ inputs.shell }} - run: {{ rootNpmPath }} -v + shell: ${{ inputs.shell }} + run: | + {$ rootNpmPath $} -v - name: Setup Dependencies if: inputs.deps == 'true' uses: ./.github/actions/deps with: - command: $\{{ inputs.deps-command }} - flags: $\{{ inputs.deps-flags }} - shell: $\{{ inputs.shell }} + command: ${{ inputs.deps-command }} + flags: ${{ inputs.deps-flags }} + shell: ${{ inputs.shell }} - name: Add Problem Matcher shell: bash diff --git a/workspaces/config/lib/actions/test.yml b/workspaces/config/lib/actions/test.yml index 50746b22..2bb93c8f 100644 --- a/workspaces/config/lib/actions/test.yml +++ b/workspaces/config/lib/actions/test.yml @@ -6,11 +6,12 @@ inputs: default: '' shell: description: shell to run on - default: '{{ shell }}' + default: '{$ shell $}' runs: using: composite steps: - name: Test - shell: $\{{ inputs.shell }} - run: {{ rootNpmPath }} test --ignore-scripts $\{{ inputs.flags }} + shell: ${{ inputs.shell }} + run: | + {$ rootNpmPath $} test --ignore-scripts ${{ inputs.flags }} diff --git a/workspaces/config/lib/actions/upsert-comment.yml b/workspaces/config/lib/actions/upsert-comment.yml index 03a8002a..f040dc21 100644 --- a/workspaces/config/lib/actions/upsert-comment.yml +++ b/workspaces/config/lib/actions/upsert-comment.yml @@ -27,7 +27,7 @@ inputs: outputs: comment-id: description: The ID of the comment - value: $\{{ steps.comment.outputs.result }} + value: ${{ steps.comment.outputs.result }} runs: using: composite @@ -36,15 +36,15 @@ runs: uses: actions/github-script@v6 id: comment env: - NUMBER: $\{{ inputs.number }} - BODY: $\{{ inputs.body }} - FIND: $\{{ inputs.find }} - REPLACE: $\{{ inputs.replace }} - APPEND: $\{{ inputs.append }} - LOGIN: $\{{ inputs.login }} - INCLUDES: $\{{ inputs.includes }} + NUMBER: ${{ inputs.number }} + BODY: ${{ inputs.body }} + FIND: ${{ inputs.find }} + REPLACE: ${{ inputs.replace }} + APPEND: ${{ inputs.append }} + LOGIN: ${{ inputs.login }} + INCLUDES: ${{ inputs.includes }} with: - github-token: $\{{ inputs.token }} + github-token: ${{ inputs.token }} script: | const { BODY, FIND, REPLACE, APPEND, LOGIN, NUMBER: issue_number, INCLUDES } = process.env const { repo: { owner, repo } } = context diff --git a/workspaces/config/lib/files/CODEOWNERS b/workspaces/config/lib/files/CODEOWNERS index 9ed0a549..3cb9855c 100644 --- a/workspaces/config/lib/files/CODEOWNERS +++ b/workspaces/config/lib/files/CODEOWNERS @@ -1 +1 @@ -* {{ codeowner }} +* {$ codeowner $} diff --git a/workspaces/config/lib/files/commitlintrc.js b/workspaces/config/lib/files/commitlintrc.js index 26966878..84f0d3eb 100644 --- a/workspaces/config/lib/files/commitlintrc.js +++ b/workspaces/config/lib/files/commitlintrc.js @@ -1,7 +1,7 @@ module.exports = { extends: ['@commitlint/config-conventional'], rules: { - 'type-enum': [2, 'always', [{{{ join (quote (pluck changelogTypes "type")) }}}]], + 'type-enum': [2, 'always', [{$ changelogTypes | pluck("type") | wrap('\'') | join(', ') $}]], 'header-max-length': [2, 'always', 80], 'subject-case': [0, 'always', ['lower-case', 'sentence-case', 'start-case']], }, diff --git a/workspaces/config/lib/files/dependabot.yml b/workspaces/config/lib/files/dependabot.yml index 7000bf1c..79e26ecc 100644 --- a/workspaces/config/lib/files/dependabot.yml +++ b/workspaces/config/lib/files/dependabot.yml @@ -2,12 +2,12 @@ version: 2 updates: - package-ecosystem: npm - directory: {{ pkg.dir }} + directory: {$ pkg.dir $} schedule: interval: daily allow: - dependency-type: direct - versioning-strategy: {{ dependabot }} + versioning-strategy: {$ dependabot $} commit-message: prefix: deps prefix-development: chore diff --git a/workspaces/config/lib/files/eslintrc.js b/workspaces/config/lib/files/eslintrc.js index 9b122214..63da2c93 100644 --- a/workspaces/config/lib/files/eslintrc.js +++ b/workspaces/config/lib/files/eslintrc.js @@ -8,13 +8,13 @@ const localConfigs = readdir(__dirname) module.exports = { root: true, - {{#if pkg.workspaceGlobs}} + {#- if pkg.workspaceGlobs.length #} ignorePatterns: [ - {{#each pkg.workspaceGlobs}} - '{{ . }}', - {{/each}} + {# for g in pkg.workspaceGlobs -#} + '{$ g $}', + {#- endfor #} ], - {{/if}} + {#- endif #} extends: [ '@npmcli', ...localConfigs, diff --git a/workspaces/config/lib/files/gitignore b/workspaces/config/lib/files/gitignore index d9d4b23e..8d2d73f2 100644 --- a/workspaces/config/lib/files/gitignore +++ b/workspaces/config/lib/files/gitignore @@ -2,6 +2,6 @@ /* # keep these -{{#each ignorePaths}} -{{ . }} -{{/each}} +{#- for p in ignorePaths #} +{$ p $} +{#- endfor #} diff --git a/workspaces/config/lib/files/npmrc b/workspaces/config/lib/files/npmrc index ebcd656b..c52bba45 100644 --- a/workspaces/config/lib/files/npmrc +++ b/workspaces/config/lib/files/npmrc @@ -1 +1 @@ -package-lock={{ lockfile }} +package-lock={$ lockfile $} diff --git a/workspaces/config/lib/files/pkg.json b/workspaces/config/lib/files/pkg.json index 6abbf27d..31f5847b 100644 --- a/workspaces/config/lib/files/pkg.json +++ b/workspaces/config/lib/files/pkg.json @@ -1,47 +1,45 @@ { "author": "GitHub Inc.", - "files": {{{ json distPaths }}}, + "files": {$ distPaths | dump $}, "scripts": { "lint": "eslint \"**/*.js\"", "postlint": "template-oss-check", "template-oss-apply": "template-oss-apply --force", - "lintfix": "{{ pkgNpmPath }} run lint -- --fix", + "lintfix": "{$ pkgNpmPath $} run lint -- --fix", "snap": "tap", "test": "tap", - "posttest": "{{ pkgNpmPath }} run lint", - {{#if isRootMono}} - "test-all": "{{ pkgNpmPath }} run test -ws -iwr --if-present", - "lint-all": "{{ pkgNpmPath }} run lint -ws -iwr --if-present", - {{/if}} - "template-copy": {{{ del }}}, - "lint:fix": {{{ del }}}, - "preversion": {{{ del }}}, - "postversion": {{{ del }}}, - "prepublishOnly": {{{ del }}}, - "postpublish": {{{ del }}}, - "eslint": {{{ del }}}, - "npmclilint": {{{ del }}}, - "prerelease": {{{ del }}}, - "postrelease": {{{ del }}}, - "postsnap": {{{ del }}} + "posttest": "{$ pkgNpmPath $} run lint", + {# if isRootMono #} + "test-all": "{$ pkgNpmPath $} run test -ws -iwr --if-present", + "lint-all": "{$ pkgNpmPath $} run lint -ws -iwr --if-present", + {# endif #} + "template-copy": {$ del $}, + "lint:fix": {$ del $}, + "preversion": {$ del $}, + "postversion": {$ del $}, + "prepublishOnly": {$ del $}, + "postpublish": {$ del $}, + "eslint": {$ del $}, + "npmclilint": {$ del $}, + "prerelease": {$ del $}, + "postrelease": {$ del $}, + "postsnap": {$ del $} }, - "repository": {{#if pkg.repository}}{{{ json pkg.repository }}}{{else}}{{{ del }}}{{/if}}, + "repository": {$ pkg.repository | dump if pkg.repository else del $}, "engines": { - {{#if engines}} - "node": {{{ json engines }}} - {{/if}} + {# if engines #} + "node": {$ engines | dump $} + {# endif #} }, - "templateVersion": {{{ del }}}, - "standard": {{{ del }}}, + "templateVersion": {$ del $}, + "standard": {$ del $}, "tap": { - {{#if pkg.workspacePaths}} - "test-ignore": "^({{ join pkg.workspacePaths "|" }})/", - {{/if}} + "test-ignore": {# if pkg.workspacePaths.length #}"^({$ pkg.workspacePaths | join $})/"{# else #}{$ del $}{# endif #}, "nyc-arg": [ - {{#each pkg.workspaceGlobs}} + {# for g in pkg.workspaceGlobs #} "--exclude", - "{{ . }}", - {{/each}} + "{$ g $}", + {# endfor #} "--exclude", "tap-snapshots/**" ] diff --git a/workspaces/config/lib/files/release-please-config.json b/workspaces/config/lib/files/release-please-config.json index e5e9a3ac..00719fe2 100644 --- a/workspaces/config/lib/files/release-please-config.json +++ b/workspaces/config/lib/files/release-please-config.json @@ -1,13 +1,13 @@ { - "separate-pull-requests": {{{ del }}}, - "plugins": {{#if repo.isMonoPublic }}["node-workspace"]{{ else }}{{{ del }}}{{/if}}, + "separate-pull-requests": {$ del $}, + "plugins": {$'["node-workspace"]' if repo.isMonoPublic else del $}, "exclude-packages-from-root": true, "group-pull-request-title-pattern": "chore: release ${version}", "pull-request-title-pattern": "chore: release${component} ${version}", - "changelog-sections": {{{ json changelogTypes }}}, + "changelog-sections": {$ changelogTypes | dump $}, "packages": { - "{{ pkg.relPath }}": { - {{#if pkg.isRoot}}"package-name": ""{{/if}} + "{$ pkg.relPath $}": { + {# if pkg.isRoot #}"package-name": ""{# endif #} } } } diff --git a/workspaces/config/lib/files/release-please-manifest.json b/workspaces/config/lib/files/release-please-manifest.json index cca100e6..3fb22ab3 100644 --- a/workspaces/config/lib/files/release-please-manifest.json +++ b/workspaces/config/lib/files/release-please-manifest.json @@ -1,3 +1,3 @@ { - "{{ pkg.relPath }}": "{{ pkg.json.version }}" + "{$ pkg.relPath $}": "{$ pkg.json.version $}" } diff --git a/workspaces/config/lib/index.js b/workspaces/config/lib/index.js index 5f4b19f4..7dc393c9 100644 --- a/workspaces/config/lib/index.js +++ b/workspaces/config/lib/index.js @@ -4,10 +4,24 @@ const isPublic = (o) => o.pkg.isPublic const isDependabotMerge = (o) => o.repo.isMono && !o.rootData.lockfile -const noCommentJson = ({ JsonMerge }) => class extends JsonMerge { - static clean = true - static comment = null -} +const releasePleaseConfig = (file) => ({ + file, + filter: isPublic, + parser: ({ JsonMerge }) => class extends JsonMerge { + static clean = true + static comment = null + }, +}) + +const jsAction = (dir, file) => ({ + [`.github/actions/${dir}/index.js`]: { + file, + parser: ({ Esbuild }) => Esbuild, + }, + [`.github/actions/${dir}/action.yml`]: { + file: `${file}/lib/action.yml`, + }, +}) const filesOptions = { files: { @@ -34,24 +48,15 @@ const filesOptions = { '.github/actions/test/action.yml': 'actions/test.yml', '.github/actions/upsert-comment/action.yml': 'actions/upsert-comment.yml', // js actions - '.github/actions/release-please/index.js': { - file: '@npmcli/actions-release-please', - parser: ({ Esbuild }) => Esbuild, - }, - '.github/actions/release-manager/index.js': { - file: '@npmcli/actions-release-manager', - parser: ({ Esbuild }) => Esbuild, - }, - '.github/actions/get-workspaces/index.js': { - file: '@npmcli/actions-get-workspaces', - parser: ({ Esbuild }) => Esbuild, - }, + ...jsAction('release-please', '@npmcli/actions-release-please'), + ...jsAction('release-manager', '@npmcli/actions-release-manager'), + ...jsAction('get-workspaces', '@npmcli/actions-get-workspaces'), // workflows '.github/workflows/audit.yml': 'workflows/audit.yml', '.github/workflows/ci.yml': 'workflows/ci.yml', '.github/workflows/codeql-analysis.yml': 'workflows/codeql-analysis.yml', '.github/workflows/post-dependabot.yml': 'workflows/post-dependabot.yml', - // this lint commits which is only necessary for releases + // // this lint commits which is only necessary for releases '.github/workflows/pull-request.yml': { file: 'workflows/pull-request.yml', filter: isPublic, @@ -64,19 +69,16 @@ const filesOptions = { file: 'workflows/release-integration.yml', filter: isPublic, }, - // release please config - '.release-please-manifest.json': { - file: 'files/release-please-manifest.json', - filter: isPublic, - parser: noCommentJson, - }, - 'release-please-config.json': { - file: 'files/release-please-config.json', - filter: isPublic, - parser: noCommentJson, - }, + // // release please config + '.release-please-manifest.json': releasePleaseConfig('files/release-please-manifest.json'), + 'release-please-config.json': releasePleaseConfig('files/release-please-config.json'), // ci - '.github/matchers/tap.json': 'files/tap.json', + '.github/matchers/tap.json': { + file: 'files/tap.json', + parser: ({ Json }) => class extends Json { + static comment = null + }, + }, // dependabot // dependabot takes a single top level config file. if we are operating on // a workspace in a repo without a root lockfile, then this parser will @@ -123,8 +125,8 @@ const filesOptions = { rootFiles: { rm: { // These are the old release please and ci files that should be removed now - '.github/workflows/release-please-{{ pkg.nameFs }}.yml': true, - '.github/workflows/ci-{{ pkg.nameFs }}.yml': true, + '.github/workflows/release-please{$ pkg.nameFs $}.yml': true, + '.github/workflows/ci{$ pkg.nameFs $}.yml': true, }, }, files: { diff --git a/workspaces/config/lib/partials/branches.yml b/workspaces/config/lib/partials/branches.yml deleted file mode 100644 index 508fd280..00000000 --- a/workspaces/config/lib/partials/branches.yml +++ /dev/null @@ -1,7 +0,0 @@ -branches: - {{#each branches}} - - {{ . }} - {{/each}} - {{~#if release}} - - {{ releaseBranches }} - {{/if~}} diff --git a/workspaces/config/lib/partials/conclude-check.yml b/workspaces/config/lib/partials/conclude-check.yml deleted file mode 100644 index 078adf96..00000000 --- a/workspaces/config/lib/partials/conclude-check.yml +++ /dev/null @@ -1,7 +0,0 @@ -- name: Conclude Check - uses: ./.github/actions/conclude-check - if: steps.check.outputs.check-id && (success() || failure()) - with: - token: $\{{ secrets.GITHUB_TOKEN }} - conclusion: $\{{ job.status }} - check-id: $\{{ steps.check.outputs.check-id }} diff --git a/workspaces/config/lib/partials/create-check.yml b/workspaces/config/lib/partials/create-check.yml deleted file mode 100644 index 87fc367c..00000000 --- a/workspaces/config/lib/partials/create-check.yml +++ /dev/null @@ -1,8 +0,0 @@ -- name: Create Check - uses: ./.github/actions/create-check - if: inputs.check-sha - id: check - with: - sha: $\{{ inputs.check-sha }} - token: $\{{ secrets.GITHUB_TOKEN }} - job-name: {{ name }} diff --git a/workspaces/config/lib/partials/cron.yml b/workspaces/config/lib/partials/cron.yml deleted file mode 100644 index 85f281c9..00000000 --- a/workspaces/config/lib/partials/cron.yml +++ /dev/null @@ -1,3 +0,0 @@ -{{! All our times are early AM pacific time, so add 8 to get utc }} -# "At {{ padHour (add hour 8) }}:00 UTC ({{ padHour hour }}:00 PT) on Monday" https://crontab.guru/#0_{{ add hour 8 }}_*_*_1 -- cron: "0 {{ add hour 8 }} * * 1" diff --git a/workspaces/config/lib/partials/if-org.yml b/workspaces/config/lib/partials/if-org.yml index 960b96d0..a7341e8d 100644 --- a/workspaces/config/lib/partials/if-org.yml +++ b/workspaces/config/lib/partials/if-org.yml @@ -1 +1 @@ -github.repository_owner == '{{ org }}' \ No newline at end of file +github.repository_owner == '{$ org $}' \ No newline at end of file diff --git a/workspaces/config/lib/partials/if-skip-pr.yml b/workspaces/config/lib/partials/if-skip-pr.yml deleted file mode 100644 index eb8f8f8f..00000000 --- a/workspaces/config/lib/partials/if-skip-pr.yml +++ /dev/null @@ -1 +0,0 @@ -!(!inputs.force && github.event_name == 'pull_request' && ((startsWith(github.head_ref, 'dependabot/') && contains(github.head_ref, '/npm-cli/template-oss')) || startsWith(github.head_ref, 'release/v*'))) \ No newline at end of file diff --git a/workspaces/config/lib/partials/job-defaults.yml b/workspaces/config/lib/partials/job-defaults.yml deleted file mode 100644 index 12743c36..00000000 --- a/workspaces/config/lib/partials/job-defaults.yml +++ /dev/null @@ -1,4 +0,0 @@ -runs-on: {{ runsOn }} -defaults: - run: - shell: {{ shell }} diff --git a/workspaces/config/lib/partials/matrix-strategy.yml b/workspaces/config/lib/partials/matrix-strategy.yml deleted file mode 100644 index 4d2c2469..00000000 --- a/workspaces/config/lib/partials/matrix-strategy.yml +++ /dev/null @@ -1,25 +0,0 @@ -{{> partialsJobDefaults - shell="${{ matrix.platform.shell }}" - runsOn="${{ matrix.platform.os }}" -}} -strategy: - fail-fast: false - matrix: - platform: - - name: Linux - os: ubuntu-latest - shell: bash - {{#if macCI}} - - name: macOS - os: macos-latest - shell: bash - {{/if}} - {{#if windowsCI}} - - name: Windows - os: windows-latest - shell: cmd - {{/if}} - node-version: - {{#each ciVersions}} - - {{ . }} - {{/each}} diff --git a/workspaces/config/lib/partials/workflow-call-inputs.yml b/workspaces/config/lib/partials/workflow-call-inputs.yml deleted file mode 100644 index 0e0dcfec..00000000 --- a/workspaces/config/lib/partials/workflow-call-inputs.yml +++ /dev/null @@ -1,7 +0,0 @@ -inputs: - ref: - type: string - force: - type: boolean - check-sha: - type: string diff --git a/workspaces/config/lib/partials/workflow.yml b/workspaces/config/lib/partials/workflow.yml new file mode 100644 index 00000000..03c96e20 --- /dev/null +++ b/workspaces/config/lib/partials/workflow.yml @@ -0,0 +1,82 @@ +{# macro defaults(_runsOn, _shell) -#} +runs-on: {$ _runsOn if _runsOn else runsOn $} +defaults: + run: + shell: {$ _shell if _shell else shell $} +{#- endmacro #} + +{# macro matrix(_runsOn, _shell) -#} +{$ defaults('${{ matrix.platform.os }}', '${{ matrix.platform.shell }}') $} +strategy: + fail-fast: false + matrix: + platform: + - name: Linux + os: ubuntu-latest + shell: bash + {#- if macCI #} + - name: macOS + os: macos-latest + shell: bash + {#- endif #} + {#- if windowsCI #} + - name: Windows + os: windows-latest + shell: cmd + {#- endif #} + node-version: + {#- for v in ciVersions #} + - {$ v $} + {#- endfor #} +{#- endmacro #} + +{# macro callInputs() -#} +inputs: + ref: + type: string + force: + type: boolean + check-sha: + type: string +{#- endmacro #} + +{# macro skipPr() -#} +!(!inputs.force && github.event_name == 'pull_request' && ((startsWith(github.head_ref, 'dependabot/') && contains(github.head_ref, '{$ options.nameBranch $}')) || startsWith(github.head_ref, 'release/v*'))) +{#- endmacro #} + +{# macro cron(hour) -#} +<#- All our times are early AM pacific time, so add 8 to get utc -#> +# "At {$ (hour + 8) | pad $}:00 UTC ({$ hour | pad $}:00 PT) on Monday" https://crontab.guru/#0_{$ hour + 8 $}_*_*_1 +- cron: "0 {$ hour + 8 $} * * 1" +{#- endmacro #} + +{# macro createCheck(name) -#} +- name: Create Check + uses: ./.github/actions/create-check + if: inputs.check-sha + id: check + with: + sha: ${{ inputs.check-sha }} + token: ${{ secrets.GITHUB_TOKEN }} + job-name: {$ name $} +{#- endmacro #} + +{# macro concludeCheck() -#} +- name: Conclude Check + uses: ./.github/actions/conclude-check + if: steps.check.outputs.check-id && (success() || failure()) + with: + token: ${{ secrets.GITHUB_TOKEN }} + conclusion: ${{ job.status }} + check-id: ${{ steps.check.outputs.check-id }} +{#- endmacro #} + +{# macro branchesList(release) -#} +branches: + {#- for branch in branches #} + - {$ branch $} + {#- endfor #} + {#- if release #} + - {$ releaseBranches $} + {#- endif #} +{#- endmacro #} diff --git a/workspaces/config/lib/workflows/audit.yml b/workspaces/config/lib/workflows/audit.yml index 57fa0a46..14ab8165 100644 --- a/workspaces/config/lib/workflows/audit.yml +++ b/workspaces/config/lib/workflows/audit.yml @@ -1,24 +1,26 @@ +{# import "partials/workflow.yml" as workflow with context #} + name: Audit on: workflow_dispatch: workflow_call: - {{> partialsWorkflowCallInputs }} + {$ workflow.callInputs() | indent(4) $} schedule: - {{> partialsCron hour=1 }} + {$ workflow.cron(1) | indent(4) $} jobs: audit: name: Audit Dependencies - if: {{> partialsIfOrg }} && {{> partialsIfSkipPr }} - {{> partialsJobDefaults }} + if: {# include "partials/if-org.yml" #} && {$ workflow.skipPr() $} + {$ workflow.defaults() | indent(4) $} steps: - name: Checkout uses: actions/checkout@v3 with: - ref: $\{{ inputs.ref }} + ref: ${{ inputs.ref }} - {{> partialsCreateCheck name="Audit Dependencies" }} + {$ workflow.createCheck('Audit Dependencies') | indent(6) $} - name: Setup uses: ./.github/actions/setup @@ -28,4 +30,4 @@ jobs: - name: Audit uses: ./.github/actions/audit - {{> partialsConcludeCheck }} + {$ workflow.concludeCheck() | indent(6) $} diff --git a/workspaces/config/lib/workflows/ci.yml b/workspaces/config/lib/workflows/ci.yml index 13c1d1e6..6ad79e11 100644 --- a/workspaces/config/lib/workflows/ci.yml +++ b/workspaces/config/lib/workflows/ci.yml @@ -1,3 +1,4 @@ +{# import "partials/workflow.yml" as workflow with context #} name: CI @@ -7,28 +8,28 @@ on: all: type: boolean workflow_call: - {{> partialsWorkflowCallInputs }} + {$ workflow.callInputs() | indent(4) $} all: type: boolean pull_request: - {{> partialsBranches }} + {$ workflow.branchesList() | indent(4) $} push: - {{> partialsBranches }} + {$ workflow.branchesList() | indent(4) $} schedule: - {{> partialsCron hour=2 }} + {$ workflow.cron(2) | indent(4) $} jobs: lint: name: Lint - if: {{> partialsIfOrg }} && {{> partialsIfSkipPr }} - {{> partialsJobDefaults }} + if: {# include "partials/if-org.yml" #} && {$ workflow.skipPr() $} + {$ workflow.defaults() | indent(4) $} steps: - name: Checkout uses: actions/checkout@v3 with: - ref: $\{{ inputs.ref }} + ref: ${{ inputs.ref }} - {{> partialsCreateCheck name="Lint" }} + {$ workflow.createCheck('Lint') | indent(6) $} - name: Setup id: setup @@ -38,33 +39,33 @@ jobs: id: workspaces uses: ./.github/actions/changed-workspaces with: - token: $\{{ secrets.GITHUB_TOKEN }} - files: $\{{ (inputs.all && '--all') || '' }} + token: ${{ secrets.GITHUB_TOKEN }} + files: ${{ (inputs.all && '--all') || '' }} - name: Lint uses: ./.github/actions/lint with: - flags: $\{{ steps.workspaces.outputs.flags }} + flags: ${{ steps.workspaces.outputs.flags }} - {{> partialsConcludeCheck }} + {$ workflow.concludeCheck() | indent(6) $} test: - name: Test - $\{{ matrix.platform.name }} - $\{{ matrix.node-version }} - if: {{> partialsIfOrg }} && {{> partialsIfSkipPr }} - {{> partialsMatrixStrategy }} + name: Test - ${{ matrix.platform.name }} - ${{ matrix.node-version }} + if: {# include "partials/if-org.yml" #} && {$ workflow.skipPr() $} + {$ workflow.matrix() | indent(4) $} steps: - name: Checkout uses: actions/checkout@v3 with: - ref: $\{{ inputs.ref }} + ref: ${{ inputs.ref }} - {{> partialsCreateCheck name="Test - ${{ matrix.platform.name }} - ${{ matrix.node-version }}" }} + {$ workflow.createCheck('Test - ${{ matrix.platform.name }} - ${{ matrix.node-version }}') | indent(6) $} - name: Continue Matrix Run id: continue-matrix shell: bash run: | - if [[ "$\{{ matrix.node-version }}" == "{{ first ciVersions }}" || "$\{{ inputs.all }}" == "true" ]]; then + if [[ "${{ matrix.node-version }}" == "{$ ciVersions | first $}" || "${{ inputs.all }}" == "true" ]]; then echo "result=true" >> $GITHUB_OUTPUT fi @@ -73,22 +74,22 @@ jobs: uses: ./.github/actions/setup id: setup with: - node-version: $\{{ matrix.node-version }} - shell: $\{{ matrix.platform.shell }} + node-version: ${{ matrix.node-version }} + shell: ${{ matrix.platform.shell }} - name: Get Changed Workspaces if: steps.continue-matrix.outputs.result id: workspaces uses: ./.github/actions/changed-workspaces with: - token: $\{{ secrets.GITHUB_TOKEN }} - files: $\{{ (inputs.all && '--all') || '' }} + token: ${{ secrets.GITHUB_TOKEN }} + files: ${{ (inputs.all && '--all') || '' }} - name: Test if: steps.continue-matrix.outputs.result uses: ./.github/actions/test with: - flags: $\{{ steps.workspaces.outputs.flags }} - shell: $\{{ matrix.platform.shell }} + flags: ${{ steps.workspaces.outputs.flags }} + shell: ${{ matrix.platform.shell }} - {{> partialsConcludeCheck }} + {$ workflow.concludeCheck() | indent(6) $} diff --git a/workspaces/config/lib/workflows/codeql-analysis.yml b/workspaces/config/lib/workflows/codeql-analysis.yml index 8b1acf6c..905cdb28 100644 --- a/workspaces/config/lib/workflows/codeql-analysis.yml +++ b/workspaces/config/lib/workflows/codeql-analysis.yml @@ -1,21 +1,23 @@ +{# import "partials/workflow.yml" as workflow with context #} + name: CodeQL on: workflow_dispatch: workflow_call: - {{> partialsWorkflowCallInputs }} + {$ workflow.callInputs() | indent(4) $} push: - {{> partialsBranches }} + {$ workflow.branchesList() | indent(4) $} pull_request: - {{> partialsBranches }} + {$ workflow.branchesList() | indent(4) $} schedule: - {{> partialsCron hour=3 }} + {$ workflow.cron(3) | indent(4) $} jobs: analyze: name: Analyze - if: {{> partialsIfOrg }} && {{> partialsIfSkipPr }} - {{> partialsJobDefaults }} + if: {# include "partials/if-org.yml" #} && {$ workflow.skipPr() $} + {$ workflow.defaults() | indent(4) $} permissions: actions: read contents: read @@ -25,9 +27,9 @@ jobs: - name: Checkout uses: actions/checkout@v3 with: - ref: $\{{ inputs.ref }} + ref: ${{ inputs.ref }} - {{> partialsCreateCheck name="Analyze" }} + {$ workflow.createCheck('Analyze') | indent(6) $} - name: Initialize CodeQL uses: github/codeql-action/init@v2 @@ -37,4 +39,4 @@ jobs: - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v2 - {{> partialsConcludeCheck }} + {$ workflow.concludeCheck() | indent(6) $} diff --git a/workspaces/config/lib/workflows/post-dependabot.yml b/workspaces/config/lib/workflows/post-dependabot.yml index 148a30d7..9efdbae7 100644 --- a/workspaces/config/lib/workflows/post-dependabot.yml +++ b/workspaces/config/lib/workflows/post-dependabot.yml @@ -1,29 +1,30 @@ +{# import "partials/workflow.yml" as workflow with context #} + name: Post Dependabot on: pull_request: - {{> partialsBranches release=true }} + {$ workflow.branchesList(true) | indent(4) $} jobs: dependency: - name: "{{ options.name }}" + name: "{$ options.name $}" permissions: contents: write outputs: - sha: $\{{ steps.sha.outputs.sha }} - # TODO: remove head_ref check after testing - if: {{> partialsIfOrg }} && github.actor == 'dependabot[bot]' - {{> partialsJobDefaults }} + sha: ${{ steps.sha.outputs.sha }} + if: {# include "partials/if-org.yml" #} && github.actor == 'dependabot[bot]' + {$ workflow.defaults() | indent(4) $} steps: - name: Fetch Dependabot Metadata id: metadata uses: dependabot/fetch-metadata@v1 continue-on-error: true with: - github-token: $\{{ secrets.GITHUB_TOKEN }} + github-token: ${{ secrets.GITHUB_TOKEN }} - name: Is Dependency - if: contains(steps.metadata.outputs.dependency-names, '{{ options.name }}') + if: contains(steps.metadata.outputs.dependency-names, '{$ options.name $}') id: dependency run: echo "continue=true" >> $GITHUB_OUTPUT @@ -31,7 +32,7 @@ jobs: if: steps.dependency.outputs.continue uses: actions/checkout@v3 with: - ref: $\{{ (github.event_name == 'pull_request' && github.event.pull_request.head.ref) || '' }} + ref: ${{ (github.event_name == 'pull_request' && github.event.pull_request.head.ref) || '' }} - name: Setup if: steps.dependency.outputs.continue @@ -42,7 +43,7 @@ jobs: uses: ./.github/actions/changed-workspaces id: workspaces with: - files: '["$\{{ steps.metadata.outputs.directory }}"]' + files: '["${{ steps.metadata.outputs.directory }}"]' # This only sets the conventional commit prefix. This workflow can't reliably determine # what the breaking change is though. If a BREAKING CHANGE message is required then @@ -51,9 +52,9 @@ jobs: if: steps.workspaces.outputs.flags id: apply run: | - {{ rootNpmPath }} run template-oss-apply $\{{ steps.workspaces.outputs.flags }} + {$ rootNpmPath $} run template-oss-apply ${{ steps.workspaces.outputs.flags }} if [[ `git status --porcelain` ]]; then - if [[ "$\{{ steps.metadata.outputs.update-type }}" == "version-update:semver-major" ]]; then + if [[ "${{ steps.metadata.outputs.update-type }}" == "version-update:semver-major" ]]; then prefix='feat!' else prefix='chore' @@ -69,7 +70,7 @@ jobs: id: push continue-on-error: true run: | - git commit -am "$\{{ steps.apply.outputs.message }}" + git commit -am "${{ steps.apply.outputs.message }}" git push # If the previous step failed, then reset the commit and remove any workflow changes @@ -83,7 +84,7 @@ jobs: git reset HEAD~ git checkout HEAD -- .github/workflows/ git clean -fd .github/workflows/ - git commit -am "$\{{ steps.apply.outputs.message }}" + git commit -am "${{ steps.apply.outputs.message }}" git push # If template-oss is applying breaking changes, then we fail this PR with a message saying what to do. There's no need @@ -110,8 +111,8 @@ jobs: if: needs.dependency.outputs.sha uses: ./.github/workflows/ci.yml with: - ref: $\{{ github.head_ref }} - check-sha: $\{{ needs.dependency.outputs.sha }} + ref: ${{ github.head_ref }} + check-sha: ${{ needs.dependency.outputs.sha }} force: true codeql-analysis: @@ -120,8 +121,8 @@ jobs: if: needs.dependency.outputs.sha uses: ./.github/workflows/codeql-analysis.yml with: - ref: $\{{ github.head_ref }} - check-sha: $\{{ needs.dependency.outputs.sha }} + ref: ${{ github.head_ref }} + check-sha: ${{ needs.dependency.outputs.sha }} force: true pull-request: @@ -130,6 +131,6 @@ jobs: if: needs.dependency.outputs.sha uses: ./.github/workflows/pull-request.yml with: - ref: $\{{ github.head_ref }} - check-sha: $\{{ needs.dependency.outputs.sha }} + ref: ${{ github.head_ref }} + check-sha: ${{ needs.dependency.outputs.sha }} force: true diff --git a/workspaces/config/lib/workflows/pull-request.yml b/workspaces/config/lib/workflows/pull-request.yml index 3ab92774..c8d0e35b 100644 --- a/workspaces/config/lib/workflows/pull-request.yml +++ b/workspaces/config/lib/workflows/pull-request.yml @@ -1,10 +1,12 @@ +{# import "partials/workflow.yml" as workflow with context #} + name: Pull Request on: workflow_call: - {{> partialsWorkflowCallInputs }} + {$ workflow.callInputs() | indent(4) $} pull_request: - {{> partialsBranches release=true }} + {$ workflow.branchesList(true) | indent(4) $} types: - opened - reopened @@ -14,16 +16,16 @@ on: jobs: commitlint: name: Lint Commits - if: {{> partialsIfOrg }} && {{> partialsIfSkipPr }} - {{> partialsJobDefaults }} + if: {# include "partials/if-org.yml" #} && {$ workflow.skipPr() $} + {$ workflow.defaults() | indent(4) $} steps: - name: Checkout uses: actions/checkout@v3 with: fetch-depth: 0 - ref: $\{{ inputs.ref }} + ref: ${{ inputs.ref }} - {{> partialsCreateCheck name="Lint Commits" }} + {$ workflow.createCheck('Lint Commits') | indent(6) $} - name: Setup uses: ./.github/actions/setup @@ -32,13 +34,13 @@ jobs: id: commit continue-on-error: true run: | - {{ rootNpxPath }} --offline commitlint -V --from 'origin/$\{{ github.base_ref }}' --to '$\{{ github.event.pull_request.head.sha }}' + {$ rootNpxPath $} --offline commitlint -V --from 'origin/${{ github.base_ref }}' --to '${{ github.event.pull_request.head.sha }}' - name: Run Commitlint on PR Title if: steps.commit.outcome == 'failure' env: - PR_TITLE: $\{{ github.event.pull_request.title }} + PR_TITLE: ${{ github.event.pull_request.title }} run: | - echo "$PR_TITLE" | {{ rootNpxPath }} --offline commitlint -V + echo "$PR_TITLE" | {$ rootNpxPath $} --offline commitlint -V - {{> partialsConcludeCheck }} + {$ workflow.concludeCheck() | indent(6) $} diff --git a/workspaces/config/lib/workflows/release-integration.yml b/workspaces/config/lib/workflows/release-integration.yml index 305cb562..d48c7533 100644 --- a/workspaces/config/lib/workflows/release-integration.yml +++ b/workspaces/config/lib/workflows/release-integration.yml @@ -1,3 +1,4 @@ +{# import "partials/workflow.yml" as workflow with context #} name: Release Integration @@ -14,8 +15,8 @@ on: jobs: check-registry: name: Check Registry - if: {{> partialsIfOrg }} - {{> partialsJobDefaults }} + if: {# include "partials/if-org.yml" #} + {$ workflow.defaults() | indent(4) $} steps: - name: Checkout uses: actions/checkout@v3 @@ -30,14 +31,14 @@ jobs: EXIT_CODE=0 function is_published { - if {{ rootNpmPath }} view "$@" --loglevel=error > /dev/null; then + if {$ rootNpmPath $} view "$@" --loglevel=error > /dev/null; then echo 0 else echo 1 fi } - for release in $(echo '$\{{ needs.release.outputs.releases }}' | jq -r '.[] | @base64'); do + for release in $(echo '${{ needs.release.outputs.releases }}' | jq -r '.[] | @base64'); do name=$(echo "$release" | base64 --decode | jq -r .pkgName) version=$(echo "$release" | base64 --decode | jq -r .version) spec="$name@$version" diff --git a/workspaces/config/lib/workflows/release.yml b/workspaces/config/lib/workflows/release.yml index 85dc56eb..ca3d31eb 100644 --- a/workspaces/config/lib/workflows/release.yml +++ b/workspaces/config/lib/workflows/release.yml @@ -1,3 +1,5 @@ +{# import "partials/workflow.yml" as workflow with context #} + name: Release on: @@ -7,7 +9,7 @@ on: description: a release PR number to rerun release jobs on type: string push: - {{> partialsBranches release=true }} + {$ workflow.branchesList(true) | indent(4) $} permissions: contents: write @@ -17,16 +19,16 @@ permissions: jobs: release: name: Release - if: {{> partialsIfOrg }} - {{> partialsJobDefaults }} + if: {# include "partials/if-org.yml" #} + {$ workflow.defaults() | indent(4) $} outputs: - pr: $\{{ steps.release.outputs.pr }} - release: $\{{ steps.release.outputs.release }} - releases: $\{{ steps.release.outputs.releases }} - pr-branch: $\{{ steps.release.outputs.pr-branch }} - pr-number: $\{{ steps.release.outputs.pr-number }} - comment-id: $\{{ steps.pr-comment.outputs.comment-id }} - check-id: $\{{ steps.check.outputs.check-id }} + pr: ${{ steps.release.outputs.pr }} + release: ${{ steps.release.outputs.release }} + releases: ${{ steps.release.outputs.releases }} + pr-branch: ${{ steps.release.outputs.pr-branch }} + pr-number: ${{ steps.release.outputs.pr-number }} + comment-id: ${{ steps.pr-comment.outputs.comment-id }} + check-id: ${{ steps.check.outputs.check-id }} steps: - name: Checkout uses: actions/checkout@v3 @@ -38,10 +40,10 @@ jobs: id: release uses: ./.github/actions/release-please env: - GITHUB_TOKEN: $\{{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - branch: $\{{ github.ref_name }} - release-pr: $\{{ inputs.release-pr }} + branch: ${{ github.ref_name }} + release-pr: ${{ inputs.release-pr }} # If we have opened a release PR, then immediately create an "in_progress" # check for it so the GitHub UI doesn't report that its mergeable. @@ -51,8 +53,8 @@ jobs: if: steps.release.outputs.pr-sha id: check with: - sha: $\{{ steps.release.outputs.pr-sha }} - token: $\{{ secrets.GITHUB_TOKEN }} + sha: ${{ steps.release.outputs.pr-sha }} + token: ${{ secrets.GITHUB_TOKEN }} job-name: Release - name: Comment Text @@ -60,8 +62,8 @@ jobs: if: steps.release.outputs.pr-number id: comment-text env: - PR_NUMBER: $\{{ steps.release.outputs.pr-number }} - REF_NAME: $\{{ github.ref_name }} + PR_NUMBER: ${{ steps.release.outputs.pr-number }} + REF_NAME: ${{ github.ref_name }} with: result-encoding: string script: | @@ -69,7 +71,7 @@ jobs: const { data: workflow } = await github.rest.actions.getWorkflowRun({ owner, repo, run_id: runId }) let body = '## Release Manager\n\n' body += `Release workflow run: ${workflow.html_url}\n\n#### Force CI to Update This Release\n\n` - body += `This PR will be updated and CI will run for every non-\`chore:\` commit that is pushed to \`{{ defaultBranch }}\`. ` + body += `This PR will be updated and CI will run for every non-\`chore:\` commit that is pushed to \`{$ defaultBranch $}\`. ` body += `To force CI to update this PR, run this command:\n\n` body += `\`\`\`\ngh workflow run release.yml -r ${process.env.REF_NAME} -R ${owner}/${repo} -f release-pr=${process.env.PR_NUMBER}\n\`\`\`` return body @@ -79,23 +81,23 @@ jobs: uses: ./.github/actions/upsert-comment id: pr-comment with: - token: $\{{ secrets.GITHUB_TOKEN }} - body: $\{{ steps.comment-text.outputs.result }} - number: $\{{ steps.release.outputs.pr-number }} + token: ${{ secrets.GITHUB_TOKEN }} + body: ${{ steps.comment-text.outputs.result }} + number: ${{ steps.release.outputs.pr-number }} update: name: Release PR - Update - {{> partialsJobDefaults }} + {$ workflow.defaults() | indent(4) $} if: needs.release.outputs.pr needs: release outputs: - sha: $\{{ steps.commit.outputs.sha }} - check-id: $\{{ steps.check.outputs.check-id }} + sha: ${{ steps.commit.outputs.sha }} + check-id: ${{ steps.check.outputs.check-id }} steps: - name: Checkout uses: actions/checkout@v3 with: - ref: $\{{ needs.release.outputs.pr-branch }} + ref: ${{ needs.release.outputs.pr-branch }} fetch-depth: 0 - name: Setup @@ -104,23 +106,24 @@ jobs: - name: Release Managers uses: ./.github/actions/release-manager env: - RELEASE_PR_NUMBER: $\{{ needs.release.outputs.pr-number }} - RELEASE_COMMENT_ID: $\{{ needs.release.outputs.comment-id }} - GITHUB_TOKEN: $\{{ secrets.GITHUB_TOKEN }} + RELEASE_PR_NUMBER: ${{ needs.release.outputs.pr-number }} + RELEASE_COMMENT_ID: ${{ needs.release.outputs.comment-id }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - lockfile: {{ lockfile }} + lockfile: {$ lockfile $} - name: Run Post Pull Request Actions env: - RELEASE_PR_NUMBER: $\{{ needs.release.outputs.pr-number }} - RELEASE_COMMENT_ID: $\{{ needs.release.outputs.comment-id }} - GITHUB_TOKEN: $\{{ secrets.GITHUB_TOKEN }} - run: {{ rootNpmPath }} run rp-pull-request --ignore-scripts -ws -iwr --if-present + RELEASE_PR_NUMBER: ${{ needs.release.outputs.pr-number }} + RELEASE_COMMENT_ID: ${{ needs.release.outputs.comment-id }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + {$ rootNpmPath $} run rp-pull-request --ignore-scripts -ws -iwr --if-present - name: Commit id: commit env: - GITHUB_TOKEN: $\{{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | git commit --all --amend --no-edit || true git push --force-with-lease @@ -131,17 +134,17 @@ jobs: if: steps.commit.outputs.sha id: check with: - sha: $\{{ steps.vommit.outputs.sha }} - token: $\{{ secrets.GITHUB_TOKEN }} + sha: ${{ steps.vommit.outputs.sha }} + token: ${{ secrets.GITHUB_TOKEN }} job-name: Release - name: Conclude Check uses: ./.github/actions/conclude-check if: needs.release.outputs.check-id && (success() || failure()) with: - token: $\{{ secrets.GITHUB_TOKEN }} - conclusion: $\{{ job.status }} - check-id: $\{{ needs.release.outputs.check-id }} + token: ${{ secrets.GITHUB_TOKEN }} + conclusion: ${{ job.status }} + check-id: ${{ needs.release.outputs.check-id }} ci: name: Release PR - CI @@ -149,27 +152,27 @@ jobs: if: needs.release.outputs.pr uses: ./.github/workflows/ci.yml with: - ref: $\{{ needs.release.outputs.pr-branch }} - check-sha: $\{{ needs.update.outputs.sha }} + ref: ${{ needs.release.outputs.pr-branch }} + check-sha: ${{ needs.update.outputs.sha }} all: true post-ci: name: Release PR - Post CI - {{> partialsJobDefaults }} + {$ workflow.defaults() | indent(4) $} needs: [release, update, ci] if: needs.update.outputs.check-id && (success() || failure()) steps: - name: Checkout uses: actions/checkout@v3 with: - ref: $\{{ needs.release.outputs.pr-branch }} + ref: ${{ needs.release.outputs.pr-branch }} - name: Get Needs Result id: needs-result run: | - if [[ "$\{{ contains(needs.*.result, 'failure') }}" == "true" ]]; then + if [[ "${{ contains(needs.*.result, 'failure') }}" == "true" ]]; then result="failure" - elif [[ "$\{{ contains(needs.*.result, 'cancelled') }}" == "true" ]]; then + elif [[ "${{ contains(needs.*.result, 'cancelled') }}" == "true" ]]; then result="cancelled" else result="success" @@ -179,13 +182,13 @@ jobs: - name: Conclude Check uses: ./.github/actions/conclude-check with: - token: $\{{ secrets.GITHUB_TOKEN }} - conclusion: $\{{ steps.needs-result.outputs.result }} - check-id: $\{{ needs.update.outputs.check-id }} + token: ${{ secrets.GITHUB_TOKEN }} + conclusion: ${{ steps.needs-result.outputs.result }} + check-id: ${{ needs.update.outputs.check-id }} post-release: name: Post Release - {{> partialsJobDefaults }} + {$ workflow.defaults() | indent(4) $} needs: release if: needs.release.outputs.releases steps: @@ -196,7 +199,7 @@ jobs: uses: actions/github-script@v6 id: comment-text env: - RELEASES: $\{{ needs.release.outputs.releases }} + RELEASES: ${{ needs.release.outputs.releases }} with: result-encoding: string script: | @@ -231,10 +234,10 @@ jobs: if: steps.comment-text.outputs.result uses: ./.github/actions/upsert-comment with: - token: $\{{ secrets.GITHUB_TOKEN }} - body: $\{{ steps.comment-text.outputs.result }} - number: $\{{ fromJson(needs.release.outputs.release).prNumber }} - includes: $\{{ github.run_id }} + token: ${{ secrets.GITHUB_TOKEN }} + body: ${{ steps.comment-text.outputs.result }} + number: ${{ fromJson(needs.release.outputs.release).prNumber }} + includes: ${{ github.run_id }} release-integration: name: Post Release - Integration @@ -247,7 +250,7 @@ jobs: post-release-integration: name: Post Release - Post Integration - {{> partialsJobDefaults }} + {$ workflow.defaults() | indent(4) $} needs: [release, release-integration] if: needs.release.outputs.release && (success() || failure()) steps: @@ -257,9 +260,9 @@ jobs: - name: Get Needs Result id: needs-result run: | - if [[ "$\{{ contains(needs.*.result, 'failure') }}" == "true" ]]; then + if [[ "${{ contains(needs.*.result, 'failure') }}" == "true" ]]; then result="x" - elif [[ "$\{{ contains(needs.*.result, 'cancelled') }}" == "true" ]]; then + elif [[ "${{ contains(needs.*.result, 'cancelled') }}" == "true" ]]; then result="heavy_multiplication_x" else result="white_check_mark" @@ -270,9 +273,9 @@ jobs: uses: actions/github-script@v6 id: comment-text env: - PR_NUMBER: $\{{ fromJSON(needs.release.outputs.release).prNumber }} - REF_NAME: $\{{ github.ref_name }} - RESULT: $\{{ steps.needs-result.outputs.result }} + PR_NUMBER: ${{ fromJSON(needs.release.outputs.release).prNumber }} + REF_NAME: ${{ github.ref_name }} + RESULT: ${{ steps.needs-result.outputs.result }} with: script: | const { RESULT, PR_NUMBER, REF_NAME } = process.env @@ -280,7 +283,7 @@ jobs: if (tagCodeowner) { let body = '' body += `\n\n:rotating_light:` - body += ` {{ codeowner }}: The post-release workflow failed for this release.` + body += ` {$ codeowner $}: The post-release workflow failed for this release.` body += ` Manual steps may need to be taken after examining the workflow output` body += ` from the above workflow run. :rotating_light:` body += `\n\nTo rerun the workflow run the following command:\n\n` @@ -291,10 +294,10 @@ jobs: - name: Update Release PR Comment uses: ./.github/actions/upsert-comment with: - token: $\{{ secrets.GITHUB_TOKEN }} + token: ${{ secrets.GITHUB_TOKEN }} body: "## Release Workflow" find: "Workflow run: :[a-z_]+:" - replace: "Workflow run :$\{{ steps.needs-result.outputs.result }}:" - append: $\{{ steps.comment-text.outputs.result }} - number: $\{{ fromJson(needs.release.outputs.release).prNumber }} - includes: $\{{ github.run_id }} + replace: "Workflow run :${{ steps.needs-result.outputs.result }}:" + append: ${{ steps.comment-text.outputs.result }} + number: ${{ fromJson(needs.release.outputs.release).prNumber }} + includes: ${{ github.run_id }} diff --git a/workspaces/rules/lib/rules/files/files.js b/workspaces/rules/lib/rules/files/files.js index ad0b68a5..4a57c19c 100644 --- a/workspaces/rules/lib/rules/files/files.js +++ b/workspaces/rules/lib/rules/files/files.js @@ -39,7 +39,7 @@ const getParsers = (fileOptions, options) => { } } - return new (Parser(file))(target, file, parserOptions) + return new (Parser(file, options))(target, file, parserOptions) }) return parsers.filter(Boolean) diff --git a/workspaces/rules/lib/rules/files/parser.js b/workspaces/rules/lib/rules/files/parser.js index ae064d94..4c025036 100644 --- a/workspaces/rules/lib/rules/files/parser.js +++ b/workspaces/rules/lib/rules/files/parser.js @@ -1,5 +1,5 @@ const fs = require('fs/promises') -const { basename, extname, dirname, relative, join } = require('path') +const { dirname, relative, join } = require('path') const yaml = require('yaml') const NpmPackageJson = require('@npmcli/package-json') const jsonParse = require('json-parse-even-better-errors') @@ -7,6 +7,7 @@ const Diff = require('diff') const { unset, mergeWith } = require('lodash') const ini = require('ini') const esbuild = require('esbuild') +const minimatch = require('minimatch') const template = require('./template.js') // json diff takes a delete key to find values that should be deleted instead of diffed @@ -50,7 +51,7 @@ const state = new Map() class Base { static types = [] - static header = 'This file is automatically added by {{ options.name }}. Do not edit.' + static header = 'This file is automatically added by {$ options.name $}. Do not edit.' static comment = (v) => v static template = template static diff = strDiff @@ -210,12 +211,12 @@ class Gitignore extends Base { } class Js extends Base { - static types = ['js'] + static types = ['*.js'] static comment = (c) => `/* ${c} */` } class Ini extends Base { - static types = ['ini'] + static types = ['*.ini'] static comment = (c) => `; ${c}` static diff = jsonDiff @@ -246,12 +247,12 @@ class IniMerge extends Ini { } class Markdown extends Base { - static types = ['md'] + static types = ['*.md'] static comment = (c) => `` } class Yml extends Base { - static types = ['yml'] + static types = ['*.yml'] static comment = (c) => ` ${c}` toString (s) { @@ -313,7 +314,7 @@ class YmlMerge extends Yml { } class Json extends Base { - static types = ['json'] + static types = ['*.json'] // its a json comment! not really but we do add a special key // to json objects static comment = (c, o) => ({ [o.options.name]: c }) @@ -341,7 +342,7 @@ class Json extends Base { } class JsonMerge extends Json { - static header = 'This file is partially managed by {{ options.name }}. Edits may be overwritten.' + static header = 'This file is partially managed by {$ options.name $}. Edits may be overwritten.' static merge = merge } @@ -376,7 +377,6 @@ class PackageJson extends JsonMerge { } class Esbuild extends Js { - static types = [] // these diffs are too big to show, so this will only display // that the file needs to be updated or not static diff = null @@ -414,21 +414,27 @@ const Parsers = { Markdown, Yml, YmlMerge, + PackageJson, Json, JsonMerge, - PackageJson, Esbuild, } const parserLookup = Object.values(Parsers) const getParser = (file) => { - const base = basename(file).toLowerCase() - const ext = extname(file).slice(1).toLowerCase() + const parsers = parserLookup + .map(p => { + const type = p.types.find(t => minimatch(file, `**/${t}`, { nocase: true })) + if (type) { + return { parser: p, type } + } + }) + .filter(Boolean) + + const noMagicParser = parsers.find(p => !p.type.includes('*')) - return parserLookup.find((p) => p.types.includes(base)) - || parserLookup.find((p) => p.types.includes(ext)) - || Parsers.Base + return noMagicParser?.parser || parsers[0]?.parser || Parsers.Base } module.exports = getParser diff --git a/workspaces/rules/lib/rules/files/template.js b/workspaces/rules/lib/rules/files/template.js index cab45754..9f29a695 100644 --- a/workspaces/rules/lib/rules/files/template.js +++ b/workspaces/rules/lib/rules/files/template.js @@ -1,77 +1,30 @@ -const Handlebars = require('handlebars') -const { basename, dirname, sep, extname, join, relative } = require('path') -const fs = require('fs') +const nunjucks = require('nunjucks') const DELETE = '__DELETE__' -const partialName = (s) => { - const dir = dirname(s) - return join(dir === '.' ? '' : dir, basename(s, extname(s)))// remove extension - // camelcase with -, /, and \\ as separators - .replace(/(?:[-/]|\\)([a-z])/g, (_, g) => g.toUpperCase()) -} - -const walkDir = (dir, res = [], root = dir) => { - const contents = fs.readdirSync(dir) - for (const c of contents) { - if (c.startsWith('.')) { - continue - } - const itemPath = join(dir, c) - if (fs.statSync(itemPath).isDirectory()) { - walkDir(itemPath, res, root) - } else { - res.push({ - name: relative(root, itemPath), - path: itemPath, - }) - } - } - return res -} - -const getPartials = (dir, isBase) => walkDir(dir).reduce((acc, f) => { - const partial = fs.readFileSync(f.path).toString() - const name = partialName(f.name) - - if (isBase) { - // in the default dir, everything is a partial - // and also gets set with a default prefix for extending - acc[name] = partial - acc[partialName(`default-${name}`)] = partial - } else if (f.name.startsWith('partials' + sep)) { - // otherwise only files in partials dir get set as partials - acc[name] = partial - } - - return acc -}, {}) - -const setupHandlebars = (baseDir, ...otherDirs) => { - Handlebars.registerHelper('join', (arr, s) => arr.join(typeof s === 'string' ? s : ', ')) - Handlebars.registerHelper('pluck', (arr, key) => arr.map(a => a[key])) - Handlebars.registerHelper('quote', (arr) => arr.map(a => `'${a}'`)) - Handlebars.registerHelper('last', (arr) => arr[arr.length - 1]) - Handlebars.registerHelper('first', (arr) => arr[0]) - Handlebars.registerHelper('add', (num, addend) => +num + +addend) - Handlebars.registerHelper('padHour', (num) => num.toString().padStart(2, '0')) - Handlebars.registerHelper('json', (c) => JSON.stringify(c)) - Handlebars.registerHelper('del', () => JSON.stringify(DELETE)) - Handlebars.registerHelper('newline', () => '\n') - - Handlebars.registerPartial(getPartials(baseDir, true)) - for (const dir of otherDirs) { - Handlebars.registerPartial(getPartials(dir)) - } -} - const template = (str, options) => { - if (options.baseDirs) { - setupHandlebars(...options.baseDirs) - } - const t = Handlebars.compile(str, { strict: true }) + const loader = new nunjucks.FileSystemLoader(options.baseDirs, { + noCache: true, + }) + const env = new nunjucks.Environment(loader, { + autoescape: false, + throwOnUndefined: true, + noCache: true, + tags: { + blockStart: '{#', + blockEnd: '#}', + variableStart: '{$', + variableEnd: '$}', + commentStart: '<#', + commentEnd: '#>', + }, + }) + env.addFilter('pad', (s, count, fill) => s.toString().padStart(count ?? 2, fill ?? '0')) + env.addFilter('pluck', (arr, prop) => arr.map(item => item[prop])) + env.addFilter('wrap', (s, c) => Array.isArray(s) ? s.map(i => `${c}${i}${c}`) : `${c}${s}${c}`) // merge in data as top level data in templates - return t({ ...options, ...options.data }) + const data = { ...options, ...options.data, del: JSON.stringify(DELETE) } + return env.renderString(str, data) } module.exports = template diff --git a/workspaces/rules/package.json b/workspaces/rules/package.json index 34dcf959..79834dcf 100644 --- a/workspaces/rules/package.json +++ b/workspaces/rules/package.json @@ -23,13 +23,14 @@ "diff": "^5.1.0", "esbuild": "^0.17.8", "glob": "^8.1.0", - "handlebars": "^4.7.7", "ini": "^3.0.1", "json-parse-even-better-errors": "^3.0.0", "just-deep-map-values": "^1.2.0", "just-diff": "^5.2.0", "lodash": "^4.17.21", + "minimatch": "^7.0.0", "npm-package-arg": "^10.1.0", + "nunjucks": "^3.2.3", "semver": "^7.3.8", "yaml": "^2.2.1" },