diff --git a/files/.github/workflows/ci.yml b/files/.github/workflows/ci.yml index a728a7c..74f1d9f 100644 --- a/files/.github/workflows/ci.yml +++ b/files/.github/workflows/ci.yml @@ -1,99 +1 @@ -name: CI - -on: - push: - branches: - - main - - master - pull_request: {} - -concurrency: - group: ci-${{ github.head_ref || github.ref }} - cancel-in-progress: true - -jobs: - lint: - name: "Lints" - runs-on: ubuntu-latest - timeout-minutes: 10 - - steps: - - uses: actions/checkout@v4<% if (pnpm) { %> - - uses: pnpm/action-setup@v4<% } %> - - uses: actions/setup-node@v4 - with: - node-version: 22 - cache: <%= pnpm ? 'pnpm' : yarn ? 'yarn' : 'npm' %> - - name: Install Dependencies - run: <%= pnpm ? 'pnpm install --frozen-lockfile' : yarn ? 'yarn install --frozen-lockfile' : 'npm ci' %> - - name: Lint - run: <%= pnpm ? 'pnpm' : yarn ? 'yarn' : 'npm run' %> lint - - test: - name: "Tests" - runs-on: ubuntu-latest - timeout-minutes: 10 - outputs: - matrix: ${{ steps.set-matrix.outputs.matrix }} - - steps: - - uses: actions/checkout@v4<% if (pnpm) { %> - - uses: pnpm/action-setup@v4<% } %> - - uses: actions/setup-node@v4 - with: - node-version: 22 - cache: <%= pnpm ? 'pnpm' : yarn ? 'yarn' : 'npm' %> - - name: Install Dependencies - run: <%= pnpm ? 'pnpm install --frozen-lockfile' : yarn ? 'yarn install --frozen-lockfile' : 'npm ci' %> - - name: Run Tests - run: <%= pnpm ? 'pnpm' : yarn ? 'yarn' : 'npm run' %> test - # For the Try Scenarios - - id: set-matrix - run: | - <% if (pnpm) { %> echo "matrix=$(pnpm -s dlx @embroider/try list)" >> $GITHUB_OUTPUT<% } %> - <% if (npm) { %> echo "matrix=$(npx @embroider/try list)" >> $GITHUB_OUTPUT<% } %> - - floating: - name: "Floating Dependencies" - runs-on: ubuntu-latest - timeout-minutes: 10 - - steps: - - uses: actions/checkout@v4<% if (pnpm) { %> - - uses: pnpm/action-setup@v4<% } %> - - uses: actions/setup-node@v4 - with: - node-version: 22 - cache: <%= pnpm ? 'pnpm' : yarn ? 'yarn' : 'npm' %> - - name: Install Dependencies - run: <%= pnpm ? 'pnpm install --no-lockfile' : yarn ? 'yarn install --no-lockfile' : 'npm install --no-package-lock' %> - - name: Run Tests - run: <%= pnpm ? 'pnpm' : yarn ? 'yarn' : 'npm run' %> test - - try-scenarios: - name: ${{ matrix.name }} - runs-on: ubuntu-latest - needs: "test" - timeout-minutes: 10 - strategy: - fail-fast: false - matrix: ${{fromJson(needs.test.outputs.matrix)}} - - steps: - - uses: actions/checkout@v4<% if (pnpm) { %> - - uses: pnpm/action-setup@v4<% } %> - - uses: actions/setup-node@v4 - with: - node-version: 22 - cache: <%= pnpm ? 'pnpm' : yarn ? 'yarn' : 'npm' %> - - name: Apply Scenario - run: | - <% if (pnpm) { %> pnpm dlx @embroider/try apply ${{ matrix.name }}<% } %> - <% if (npm) { %> npx @embroider/try apply ${{ matrix.name }}<% } %> - - name: Install Dependencies - run: <%= pnpm ? 'pnpm install --no-lockfile' : yarn ? 'yarn install --no-lockfile' : 'npm install --no-package-lock' %> - - name: Run Tests - run: | - <% if (pnpm) { %>pnpm test<% } %> - <% if (npm) { %>npm test<% } %> - env: ${{ matrix.env }} +# Replaced from src/.github, based on selected packageManager diff --git a/files/.github/workflows/push-dist.yml b/files/.github/workflows/push-dist.yml index 116054f..74f1d9f 100644 --- a/files/.github/workflows/push-dist.yml +++ b/files/.github/workflows/push-dist.yml @@ -1,34 +1 @@ -# Because this library needs to be built, -# we can't easily point package.json files at the git repo for easy cross-repo testing. -# -# This workflow brings back that capability by placing the compiled assets on a "dist" branch -# (configurable via the "branch" option below) -name: Push dist - -on: - push: - branches: - - main - - master - -jobs: - push-dist: - name: Push dist - permissions: - contents: write - runs-on: ubuntu-latest - timeout-minutes: 10 - - steps: - - uses: actions/checkout@v4<% if (pnpm) { %> - - uses: pnpm/action-setup@v4<% } %> - - uses: actions/setup-node@v4 - with: - node-version: 22 - cache: <%= pnpm ? 'pnpm' : yarn ? 'yarn' : 'npm' %> - - name: Install Dependencies - run: <%= pnpm ? 'pnpm install --frozen-lockfile' : yarn ? 'yarn install --frozen-lockfile' : 'npm ci' %> - - uses: kategengler/put-built-npm-package-contents-on-branch@v2.0.0 - with: - branch: dist - token: ${{ secrets.GITHUB_TOKEN }} +# Replaced from src/.github, based on selected packageManager diff --git a/index.js b/index.js index 8b2b6d1..9a882da 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,7 @@ 'use strict'; +const { readFileSync } = require('fs'); +const { join } = require('path'); const { sortPackageJson } = require('sort-package-json'); let date = new Date(); @@ -10,8 +12,20 @@ function stringifyAndNormalize(contents) { return `${JSON.stringify(contents, null, 2)}\n`; } +const workflows = join(__dirname, 'src/.github/workflows/'); + const replacers = { - 'package.json'(content) { + '.github/workflows/ci.yml'(templateVariables) { + let sourcePath = join(workflows, templateVariables.packageManager, 'ci.yml'); + + return readFileSync(sourcePath); + }, + '.github/workflows/push-dist.yml'(templateVariables) { + let sourcePath = join(workflows, templateVariables.packageManager, 'push-dist.yml'); + + return readFileSync(sourcePath); + }, + 'package.json'(_templateVariables, content) { return this.updatePackageJson(content); }, }; @@ -93,11 +107,11 @@ module.exports = { * _js_eslint.config.mjs is deleted * _ts_eslint.config.mjs is renamed to eslint.config.mjs */ - buildFileInfo(_intoDir, _templateVariables, file, _commandOptions) { + buildFileInfo(_intoDir, templateVariables, file, _commandOptions) { let fileInfo = this._super.buildFileInfo.apply(this, arguments); if (file in replacers) { - fileInfo.replacer = replacers[file].bind(this); + fileInfo.replacer = replacers[file].bind(this, templateVariables); } return fileInfo; diff --git a/src/.github/workflows/npm/ci.yml b/src/.github/workflows/npm/ci.yml new file mode 100644 index 0000000..d7a8979 --- /dev/null +++ b/src/.github/workflows/npm/ci.yml @@ -0,0 +1,92 @@ +name: CI + +on: + push: + branches: + - main + - master + pull_request: {} + +concurrency: + group: ci-${{ github.head_ref || github.ref }} + cancel-in-progress: true + +jobs: + lint: + name: "Lints" + runs-on: ubuntu-latest + timeout-minutes: 10 + + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 22 + cache: npm + - name: Install Dependencies + run: npm ci + - name: Lint + run: npm run lint + + test: + name: "Tests" + runs-on: ubuntu-latest + timeout-minutes: 10 + outputs: + matrix: ${{ steps.set-matrix.outputs.matrix }} + + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 22 + cache: npm + - name: Install Dependencies + run: npm ci + - name: Run Tests + run: npm run test + # For the Try Scenarios + - id: set-matrix + run: | + echo "matrix=$(npx @embroider/try list)" >> $GITHUB_OUTPUT + + floating: + name: "Floating Dependencies" + runs-on: ubuntu-latest + timeout-minutes: 10 + + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 22 + cache: npm + - name: Install Dependencies + run: npm install --no-package-lock + - name: Run Tests + run: npm run test + + try-scenarios: + name: ${{ matrix.name }} + runs-on: ubuntu-latest + needs: "test" + timeout-minutes: 10 + strategy: + fail-fast: false + matrix: ${{fromJson(needs.test.outputs.matrix)}} + + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 22 + cache: npm + - name: Apply Scenario + run: | + npx @embroider/try apply ${{ matrix.name }} + - name: Install Dependencies + run: npm install --no-package-lock + - name: Run Tests + run: | + npm test + env: ${{ matrix.env }} diff --git a/src/.github/workflows/npm/push-dist.yml b/src/.github/workflows/npm/push-dist.yml new file mode 100644 index 0000000..dfd3454 --- /dev/null +++ b/src/.github/workflows/npm/push-dist.yml @@ -0,0 +1,33 @@ +# Because this library needs to be built, +# we can't easily point package.json files at the git repo for easy cross-repo testing. +# +# This workflow brings back that capability by placing the compiled assets on a "dist" branch +# (configurable via the "branch" option below) +name: Push dist + +on: + push: + branches: + - main + - master + +jobs: + push-dist: + name: Push dist + permissions: + contents: write + runs-on: ubuntu-latest + timeout-minutes: 10 + + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 22 + cache: npm + - name: Install Dependencies + run: npm ci + - uses: kategengler/put-built-npm-package-contents-on-branch@v2.0.0 + with: + branch: dist + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/src/.github/workflows/pnpm/ci.yml b/src/.github/workflows/pnpm/ci.yml new file mode 100644 index 0000000..44bdd48 --- /dev/null +++ b/src/.github/workflows/pnpm/ci.yml @@ -0,0 +1,98 @@ +name: CI + +on: + push: + branches: + - main + - master + pull_request: {} + +concurrency: + group: ci-${{ github.head_ref || github.ref }} + cancel-in-progress: true + +jobs: + lint: + name: "Lints" + runs-on: ubuntu-latest + timeout-minutes: 10 + + steps: + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v4 + - uses: actions/setup-node@v4 + with: + node-version: 22 + cache: pnpm + - name: Install Dependencies + run: pnpm install --frozen-lockfile + - name: Lint + run: pnpm lint + + test: + name: "Tests" + runs-on: ubuntu-latest + timeout-minutes: 10 + outputs: + matrix: ${{ steps.set-matrix.outputs.matrix }} + + steps: + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v4 + - uses: actions/setup-node@v4 + with: + node-version: 22 + cache: pnpm + - name: Install Dependencies + run: pnpm install --frozen-lockfile + - name: Run Tests + run: pnpm test + # For the Try Scenarios + - id: set-matrix + run: | + echo "matrix=$(pnpm -s dlx @embroider/try list)" >> $GITHUB_OUTPUT + + floating: + name: "Floating Dependencies" + runs-on: ubuntu-latest + timeout-minutes: 10 + + steps: + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v4 + - uses: actions/setup-node@v4 + with: + node-version: 22 + cache: pnpm + - name: Install Dependencies + run: pnpm install --no-lockfile + - name: Run Tests + run: pnpm test + + try-scenarios: + name: ${{ matrix.name }} + runs-on: ubuntu-latest + needs: "test" + timeout-minutes: 10 + strategy: + fail-fast: false + matrix: ${{fromJson(needs.test.outputs.matrix)}} + + steps: + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v4 + - uses: actions/setup-node@v4 + with: + node-version: 22 + cache: pnpm + - name: Apply Scenario + run: | + pnpm dlx @embroider/try apply ${{ matrix.name }} + + - name: Install Dependencies + run: pnpm install --no-lockfile + - name: Run Tests + run: | + pnpm test + + env: ${{ matrix.env }} diff --git a/src/.github/workflows/pnpm/push-dist.yml b/src/.github/workflows/pnpm/push-dist.yml new file mode 100644 index 0000000..bdfa5b5 --- /dev/null +++ b/src/.github/workflows/pnpm/push-dist.yml @@ -0,0 +1,34 @@ +# Because this library needs to be built, +# we can't easily point package.json files at the git repo for easy cross-repo testing. +# +# This workflow brings back that capability by placing the compiled assets on a "dist" branch +# (configurable via the "branch" option below) +name: Push dist + +on: + push: + branches: + - main + - master + +jobs: + push-dist: + name: Push dist + permissions: + contents: write + runs-on: ubuntu-latest + timeout-minutes: 10 + + steps: + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v4 + - uses: actions/setup-node@v4 + with: + node-version: 22 + cache: pnpm + - name: Install Dependencies + run: pnpm install --frozen-lockfile + - uses: kategengler/put-built-npm-package-contents-on-branch@v2.0.0 + with: + branch: dist + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/tests/fixtures/default/.github/workflows/ci.yml b/tests/fixtures/default/.github/workflows/ci.yml index 32879a6..d7a8979 100644 --- a/tests/fixtures/default/.github/workflows/ci.yml +++ b/tests/fixtures/default/.github/workflows/ci.yml @@ -48,8 +48,7 @@ jobs: # For the Try Scenarios - id: set-matrix run: | - - echo "matrix=$(npx @embroider/try list)" >> $GITHUB_OUTPUT + echo "matrix=$(npx @embroider/try list)" >> $GITHUB_OUTPUT floating: name: "Floating Dependencies" @@ -84,12 +83,10 @@ jobs: cache: npm - name: Apply Scenario run: | - - npx @embroider/try apply ${{ matrix.name }} + npx @embroider/try apply ${{ matrix.name }} - name: Install Dependencies run: npm install --no-package-lock - name: Run Tests run: | - npm test env: ${{ matrix.env }} diff --git a/tests/fixtures/pnpm/.github/workflows/ci.yml b/tests/fixtures/pnpm/.github/workflows/ci.yml index 1961de9..44bdd48 100644 --- a/tests/fixtures/pnpm/.github/workflows/ci.yml +++ b/tests/fixtures/pnpm/.github/workflows/ci.yml @@ -50,8 +50,7 @@ jobs: # For the Try Scenarios - id: set-matrix run: | - echo "matrix=$(pnpm -s dlx @embroider/try list)" >> $GITHUB_OUTPUT - + echo "matrix=$(pnpm -s dlx @embroider/try list)" >> $GITHUB_OUTPUT floating: name: "Floating Dependencies" @@ -88,12 +87,12 @@ jobs: cache: pnpm - name: Apply Scenario run: | - pnpm dlx @embroider/try apply ${{ matrix.name }} - + pnpm dlx @embroider/try apply ${{ matrix.name }} + - name: Install Dependencies run: pnpm install --no-lockfile - name: Run Tests run: | pnpm test - + env: ${{ matrix.env }}