UNPKG

@iobroker/create-adapter

Version:

Command line utility to create customized ioBroker adapters

144 lines (131 loc) 5.49 kB
"use strict"; const constants_1 = require("../../../src/lib/constants"); const templateFunction = answers => { const isAdapter = answers.features?.includes("adapter"); const useTypeScript = answers.language === "TypeScript"; const useESLint = answers.tools?.includes("ESLint"); const useReact = answers.adminUi === "react" || answers.tabReact === "yes"; const needsBuild = useTypeScript || useReact; const sourcemapPaths = [...(useTypeScript ? ["build/"] : []), ...(useReact ? ["admin/build/"] : [])]; const useReleaseScript = answers.releaseScript === "yes"; const isGitHub = answers.target === "github"; // Determine the LTS version and test versions based on the minimum Node.js version selected const minNodeVersion = answers.nodeVersion || constants_1.RECOMMENDED_NODE_VERSION_FALLBACK; const ltsNodeVersion = `${minNodeVersion}.x`; // Filter test versions to only include versions >= the minimum version const allTestVersions = ["20.x", "22.x", "24.x"]; const minVersionNumber = parseInt(minNodeVersion, 10); const adapterTestVersions = allTestVersions.filter(version => { const versionNumber = parseInt(version.split(".")[0], 10); return versionNumber >= minVersionNumber; }); const adapterTestOS = ["ubuntu-latest", "windows-latest", "macos-latest"]; const adapterName = answers.adapterName; const deploy = useReleaseScript && isGitHub; const escapeDeploy = deploy ? (input) => input : (input) => input.replace(/^/gm, "#"); const template = ` name: Test and Release # Run this job on all pushes and pull requests # as well as tags with a semantic version on: push: branches: - "${answers.defaultBranch ?? "main"}" tags: # normal versions - "v[0-9]+.[0-9]+.[0-9]+" # pre-releases - "v[0-9]+.[0-9]+.[0-9]+-**" pull_request: {} # Cancel previous PR/branch runs when a new commit is pushed concurrency: group: \${{ github.ref }} cancel-in-progress: true jobs: # Performs quick checks before the expensive test runs check-and-lint: if: contains(github.event.head_commit.message, '[skip ci]') == false runs-on: ubuntu-latest steps: - uses: ioBroker/testing-action-check@v1 with: node-version: '${ltsNodeVersion}' # Uncomment the following line if your adapter cannot be installed using 'npm ci' # install-command: 'npm install'${useTypeScript ? ` type-checking: true` : ""}${useESLint ? ` lint: true` : ""} ${isAdapter ? ` # Runs adapter tests on all supported node versions and OSes adapter-tests: if: contains(github.event.head_commit.message, '[skip ci]') == false runs-on: \${{ matrix.os }} strategy: matrix: node-version: [${adapterTestVersions.join(", ")}] os: [${adapterTestOS.join(", ")}] steps: - uses: ioBroker/testing-action-adapter@v1 with: node-version: \${{ matrix.node-version }} os: \${{ matrix.os }} # Uncomment the following line if your adapter cannot be installed using 'npm ci' # install-command: 'npm install'${needsBuild ? ` build: true` : ""} ` : ""}${deploy ? "" : ` # TODO: To enable automatic npm releases, set up trusted publishing in your npm account # See https://docs.npmjs.com/trusted-publishers for more details # Then uncomment the following block: `} ${escapeDeploy(` # Deploys the final package to NPM deploy: needs: [check-and-lint${isAdapter ? ", adapter-tests" : ""}] # Trigger this step only when a commit on any branch is tagged with a version number if: | contains(github.event.head_commit.message, '[skip ci]') == false && github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') runs-on: ubuntu-latest # Write permissions are required to create Github releases permissions: id-token: write contents: write steps: - uses: ioBroker/testing-action-deploy@v1 with: node-version: '${ltsNodeVersion}' # Uncomment the following line if your adapter cannot be installed using 'npm ci' # install-command: 'npm install'${needsBuild ? ` build: true` : ""} github-token: \${{ secrets.GITHUB_TOKEN }} # When using Sentry for error reporting, Sentry can be informed about new releases # To enable create a API-Token in Sentry (User settings, API keys) # Enter this token as a GitHub secret (with name SENTRY_AUTH_TOKEN) in the repository options # Then uncomment and customize the following block: sentry: true sentry-token: \${{ secrets.SENTRY_AUTH_TOKEN }} sentry-project: "iobroker-${adapterName}" sentry-version-prefix: "iobroker.${adapterName}"${needsBuild ? ` sentry-sourcemap-paths: "${sourcemapPaths.join(" ")}"` : ""} # If your sentry project is linked to a GitHub repository, you can enable the following option # sentry-github-integration: true`)} `; return template.trimLeft(); }; templateFunction.customPath = ".github/workflows/test-and-release.yml"; // Reformatting this would create mixed tabs and spaces templateFunction.noReformat = true; module.exports = templateFunction; //# sourceMappingURL=test-and-release.yml.js.map