From 4ce3fe4aee1495e384d56ab0714972a334b3fe3f Mon Sep 17 00:00:00 2001 From: Viktor Varland Date: Wed, 11 Mar 2020 10:28:14 +0100 Subject: [PATCH 1/4] feat(release): support distribution tags and custom release user info --- .github/workflows/node-publish.yml | 48 ++++++++++++++++++++++++++++++ .travis.yml | 23 -------------- docs/_sidebar.md | 1 + docs/commands/d2-utils-release.md | 30 +++++++++++++++++++ docs/getting-started.md | 16 +++++++++- packages/utils/src/cmds/release.js | 12 ++++---- 6 files changed, 99 insertions(+), 31 deletions(-) create mode 100644 .github/workflows/node-publish.yml delete mode 100644 .travis.yml create mode 100644 docs/commands/d2-utils-release.md diff --git a/.github/workflows/node-publish.yml b/.github/workflows/node-publish.yml new file mode 100644 index 00000000..9f5fe135 --- /dev/null +++ b/.github/workflows/node-publish.yml @@ -0,0 +1,48 @@ +name: 'dhis2-node publish' + +on: + push: + branches: + # match branches in: + # https://github.com/semantic-release/semantic-release/blob/master/docs/usage/configuration.md#branches + - master + - next + - next-major + - alpha + - beta + - '[0-9]+.x' + - '[0-9]+.x.x' + - '[0-9]+.[0-9]+.x' + +env: + GIT_AUTHOR_NAME: '@dhis2-bot' + GIT_AUTHOR_EMAIL: 'apps@dhis2.org' + GIT_COMMITTER_NAME: '@dhis2-bot' + GIT_COMMITTER_EMAIL: 'apps@dhis2.org' + NPM_TOKEN: ${{secrets.NPM_TOKEN}} + GH_TOKEN: ${{secrets.GH_TOKEN}} + +jobs: + process: + name: Publish + runs-on: ubuntu-latest + if: "!contains(github.event.head_commit.message, '[skip ci]')" + steps: + - uses: actions/checkout@v1 + - uses: actions/setup-node@v1 + with: + node-version: 12.x + + - name: Install + run: yarn install --frozen-lockfile + + - name: Smoke + run: ./packages/main/bin/d2 debug system + + - name: Test + run: yarn test + + - name: Publish to NPM + run: npx @dhis2/cli-utils release --publish npm + env: + CI: true diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index fdc10728..00000000 --- a/.travis.yml +++ /dev/null @@ -1,23 +0,0 @@ -language: node_js -node_js: -- lts/* -script: -- echo "Smoke testing d2 executable" -- "./packages/main/bin/d2 debug system" -- yarn test -deploy: -- provider: script - skip_cleanup: true - script: - - "./packages/utils/bin/d2-utils release --publish npm" - on: - tags: false - branch: master -env: - global: - - GIT_AUTHOR_NAME=@dhis2-bot - - GIT_AUTHOR_EMAIL=apps@dhis2.org - - GIT_COMMITTER_NAME=@dhis2-bot - - GIT_COMMITTER_EMAIL=apps@dhis2.org - - secure: WMu2f5d2AkwYMZEisCtMfc5rSrV8TcMmom2qvaDLk2+2AHcupWUXZWPv8NUJnYYdtqmfoS7pTFz0TmIQ7i+XVK4HDnxE+ksq/byXn0UNj9p8OB6c8RsJJqSL7c8HT1k6yQxseKnPHRE6jTiVXIgq3SkY32bYGgB7ZmxNTcjmmmPhmvXYJzfgIsM2b5hA/FW1sDtnLXFS9F6GLgF9p99eNP810zBrtxcGcXFuRhNpLv9IGJd4QSh4NsKak+4z/w8L+oaWbF0FUAJY5MjelL99lIPG5M6RIdoxAWLDbw2a568lsrGr7CuMzZz/Z0gXWWta5KRoB66YRpDdtZtY3Qh4PWlMKPONy7RcTr3XX7tDykh1EXHwiYyfSNlqBO/TWsK5bC9gbjM+q+jNR6SDudVIqSHGjrev/x9P0eFF/W7hGd6/0zMkz7BJWYfSkiLLNzkk6wtiHBvk3gh9bCgmIhn2c6N8HDFKTd70PJ2lFZBfhu1O2NEVH7W4KFFXNj8JgIUps9KmIjpfSilYBJNHGH0UAZdzQEijG8shtM2y/RBvysnByLJxrSnqSAeJPx7CfTam3Q0QWIwa5TIuIzWJSTwtYv5PY+Y6EzL0LhLaFB4vg+66e+zha6E1oZPfOKFWdJkt7Kl++IQegIsVFRKqei61rkP9Fx7gu82hRKXz1ljLb9o= - - secure: EnTJ5emmdlkHgpv3akmLaWMuILqKlXKi3XxtCsYDuMmb4gfPTP6ubpFzrHi82cF23NDhljgedpvEZ8omdxZolk8mYqX0dPq6FTLr49OIf7GdE9vPeqPbq1YKDesXuI6iuvCBCkDmgWErMdmF0NTmwd24W6M3CmsJ7q38v31c7gNyjWu7sX4qiLO1o5WnxLXZ7DBfljJd79trdAaCebHb2Vfz7u16kpMT+w77BlVueFiCTqLQe8BZ0SnMOB/hKmBbPMx/qZ6czp/EXCWdFj/xzN7yJoF23xiTSMHtnfSjQmQTJVQPCfJKi5VvCQe2r2jyeg2Q6JbyBW27Y7BUMaAs9cE38Sr34xzzQghLSbiQehUxTHn+RbV9t1FKMOezx4jmgxLtLvJ9+gmZOzosgoOt9iZc4Jw1kon3mRhi9G7YD066+hUaObKNDYGfIomWrnZWPDARELunNBLiHhS+eBg+gJT19xuaELciFToG+/GWUP00ww+PhzrvmI5YeYY+tCpnkY08fMIRbn2c51XTpCxDScH7xVDAYL0M3+PkcfUboAmRTBWc7KlUzAJcarPgb/w/78vkLeOQNC64VySJH3X9AjBTwybgf2T8oIezIOuNIToxam4rNqtZmLo8K+IvufHMh6wZyEbj3ZZKewvLlK6e8kxo6IPmQB+NFUe8MLtk1Zo= diff --git a/docs/_sidebar.md b/docs/_sidebar.md index b28437dc..e63848ce 100644 --- a/docs/_sidebar.md +++ b/docs/_sidebar.md @@ -13,6 +13,7 @@ - - - `d2 create app` - - [`d2 style`↗️](https://cli-style.dhis2.nu ':ignore') - - `d2 utils` +- - [`d2 utils release`](commands/d2-utils-release) - - - [`d2 utils docsite`↗️](https://cli-utils-docsite.dhis2.nu ':ignore') -   - [Changelog](CHANGELOG) diff --git a/docs/commands/d2-utils-release.md b/docs/commands/d2-utils-release.md new file mode 100644 index 00000000..40c01197 --- /dev/null +++ b/docs/commands/d2-utils-release.md @@ -0,0 +1,30 @@ +# Introduction + +`d2 utils release` allows you to publish libraries and applications to +various package repositories. + +# Usage + +Internally the `release` command utilizes [semantic +release](https://github.com/semantic-release/semantic-release), so +understanding how that tool operates is helpful. + +Simply put, every time a commit appears on the `master` branch, the +fully automated release process begins, and the commit is released. + +# Advanced usage + +## Distribution channels + +We support the default channels recommended by semantic release, and +there is a [good +walkthrough](https://github.com/semantic-release/semantic-release/blob/master/docs/recipes/distribution-channels.md) +of them available on their docs. + +Our [GH Actions +workflow](https://github.com/dhis2/workflows/blob/master/ci/node-publish.yml#L5) +is kept in sync with those defaults. + +It is possible to e.g. only use the `master` branch for releases by +restricting the `on.push.branches` list in the workflow file in the +local repo. diff --git a/docs/getting-started.md b/docs/getting-started.md index c9c25b71..1d3aea66 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -1 +1,15 @@ -# fo +# Install the CLI + +``` +yarn global add @dhis2/cli + +# or + +npm install --global @dhis2/cli +``` + +# Verify that it is available on PATH + +``` +d2 --version +``` diff --git a/packages/utils/src/cmds/release.js b/packages/utils/src/cmds/release.js index bea6167b..97a457c6 100644 --- a/packages/utils/src/cmds/release.js +++ b/packages/utils/src/cmds/release.js @@ -95,20 +95,18 @@ const handler = async ({ publish }) => { '@semantic-release/github', ] - // `options` and `config` should be made configurable + /* rely on defaults for configuration, except for plugins as they + * need to be custom. + * + * https://github.com/semantic-release/semantic-release/blob/master/docs/usage/configuration.md + */ const options = { - branches: 'master', - version: 'v${version}', plugins: plugins.filter(n => !!n), } const config = { env: { ...process.env, - GIT_AUTHOR_NAME: '@dhis2-bot', - GIT_AUTHOR_EMAIL: 'apps@dhis2.org', - GIT_COMMITTER_NAME: '@dhis2-bot', - GIT_COMMITTER_EMAIL: 'apps@dhis2.org', NPM_CONFIG_ALLOW_SAME_VERSION: 'true', // Ensure we still publish even though we've already updated the package versions }, } From 5af82ecccf2b179a227d9a83301e200dd9bccf2b Mon Sep 17 00:00:00 2001 From: Viktor Varland Date: Wed, 11 Mar 2020 10:47:23 +0100 Subject: [PATCH 2/4] ci(actions): add lint and test --- .github/workflows/node-lint.yml | 24 ++++++++++++++++++++++++ .github/workflows/node-test.yml | 22 ++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 .github/workflows/node-lint.yml create mode 100644 .github/workflows/node-test.yml diff --git a/.github/workflows/node-lint.yml b/.github/workflows/node-lint.yml new file mode 100644 index 00000000..a4316a91 --- /dev/null +++ b/.github/workflows/node-lint.yml @@ -0,0 +1,24 @@ +name: 'dhis2-node lint' + +on: push + +jobs: + pr: + name: Lint + runs-on: ubuntu-latest + if: "!contains(github.event.head_commit.message, '[skip ci]')" + steps: + - uses: actions/checkout@v1 + - uses: actions/setup-node@v1 + with: + node-version: 12.x + + - name: Install + run: yarn install --frozen-lockfile + + - name: Run linters + run: | + npx d2-style js check + npx d2-style text check + env: + CI: true diff --git a/.github/workflows/node-test.yml b/.github/workflows/node-test.yml new file mode 100644 index 00000000..6a7d0aa8 --- /dev/null +++ b/.github/workflows/node-test.yml @@ -0,0 +1,22 @@ +name: 'dhis2-node test' + +on: push + +jobs: + pr: + name: Unit + runs-on: ubuntu-latest + if: "!contains(github.event.head_commit.message, '[skip ci]')" + steps: + - uses: actions/checkout@v1 + - uses: actions/setup-node@v1 + with: + node-version: 12.x + + - name: Install + run: yarn install --frozen-lockfile + + - name: Test + run: yarn test + env: + CI: true From c17e46b821bdce4fe85c0b3f7afdb33f01117259 Mon Sep 17 00:00:00 2001 From: Viktor Varland Date: Wed, 11 Mar 2020 12:17:58 +0100 Subject: [PATCH 3/4] chore(lint): resolve long-standing lint issues --- packages/app/src/commands/i18n/modernize.js | 2 - .../modernize/createNewTranslationFiles.js | 9 +++- .../helpers/modernize/deleteLegacyFiles.js | 3 +- .../cluster/src/commands/db_cmds/restore.js | 2 +- packages/cluster/src/commands/list.js | 20 ++++---- packages/cluster/src/helpers/db/restore.js | 4 +- packages/create/src/builders/app.js | 2 +- packages/create/src/index.js | 15 +----- packages/main/src/commands/debug/config.js | 2 +- packages/utils/src/cmds/schema/README.md | 46 ++++++++++++------- packages/utils/src/cmds/schema/fetch.js | 2 +- packages/utils/src/cmds/schema/index.js | 3 +- .../support/semantic-release-defer-release.js | 4 +- .../support/semantic-release-update-deps.js | 38 +++++++-------- 14 files changed, 74 insertions(+), 78 deletions(-) diff --git a/packages/app/src/commands/i18n/modernize.js b/packages/app/src/commands/i18n/modernize.js index 1be590df..98e728cc 100644 --- a/packages/app/src/commands/i18n/modernize.js +++ b/packages/app/src/commands/i18n/modernize.js @@ -11,8 +11,6 @@ * --log-missing-keys */ const path = require('path') -const fs = require('fs') -const chalk = require('chalk') const { reporter } = require('@dhis2/cli-helpers-engine') diff --git a/packages/app/src/helpers/modernize/createNewTranslationFiles.js b/packages/app/src/helpers/modernize/createNewTranslationFiles.js index 13313b19..d4e0e898 100644 --- a/packages/app/src/helpers/modernize/createNewTranslationFiles.js +++ b/packages/app/src/helpers/modernize/createNewTranslationFiles.js @@ -36,7 +36,7 @@ const createNewTranslationFiles = ({ appendToExistingFiles, }) => { for (const language in translations) { - if (translations.hasOwnProperty(language)) { + if (Object.prototype.hasOwnProperty.call(translations, language)) { if ( languagesToTransform.length && languagesToTransform.indexOf(language) === -1 @@ -88,7 +88,12 @@ const createNewTranslationFiles = ({ } for (const key in languageTranslations) { - if (languageTranslations.hasOwnProperty(key)) { + if ( + Object.prototype.hasOwnProperty.call( + languageTranslations, + key + ) + ) { if (!translations[primaryLanguage][key]) { logMissingKeys && reporter.info( diff --git a/packages/app/src/helpers/modernize/deleteLegacyFiles.js b/packages/app/src/helpers/modernize/deleteLegacyFiles.js index 8ec2ab34..5fb28228 100644 --- a/packages/app/src/helpers/modernize/deleteLegacyFiles.js +++ b/packages/app/src/helpers/modernize/deleteLegacyFiles.js @@ -1,4 +1,5 @@ const fs = require('fs') + const { reporter } = require('@dhis2/cli-helpers-engine') /** @@ -16,7 +17,7 @@ const deleteLegacyFiles = ({ translationFiles, languagesToTransform }) => { languagesToTransform.indexOf(language) !== -1 ) { try { - const filePathToDelete = path.join(inDir, file) + const filePathToDelete = file fs.unlinkSync(filePathToDelete) reporter.debug(`Deleted old file:`) reporter.debug(`"${filePathToDelete}"`) diff --git a/packages/cluster/src/commands/db_cmds/restore.js b/packages/cluster/src/commands/db_cmds/restore.js index 8defe4ad..1f318466 100644 --- a/packages/cluster/src/commands/db_cmds/restore.js +++ b/packages/cluster/src/commands/db_cmds/restore.js @@ -20,7 +20,7 @@ const run = async function(argv) { process.exit(1) } - const rest = await tryCatchAsync( + const res = await tryCatchAsync( 'db::restore', restore({ cacheLocation, diff --git a/packages/cluster/src/commands/list.js b/packages/cluster/src/commands/list.js index 31104a19..dbfa4ccc 100644 --- a/packages/cluster/src/commands/list.js +++ b/packages/cluster/src/commands/list.js @@ -51,21 +51,17 @@ const run = async function(argv) { await Promise.all( clusters.map(async cluster => { const status = await getStatus(cluster) - cluster.status = formatStatus(status) + table.push([ + chalk.blue(cluster.name), + cluster.port, + cluster.channel, + cluster.dhis2Version, + cluster.dbVersion, + formatStatus(status), + ]) }) ) - clusters.forEach(cluster => - table.push([ - chalk.blue(cluster.name), - cluster.port, - cluster.channel, - cluster.dhis2Version, - cluster.dbVersion, - cluster.status, - ]) - ) - reporter.print(table) } diff --git a/packages/cluster/src/helpers/db/restore.js b/packages/cluster/src/helpers/db/restore.js index a81acf19..294621df 100644 --- a/packages/cluster/src/helpers/db/restore.js +++ b/packages/cluster/src/helpers/db/restore.js @@ -30,7 +30,7 @@ const downloadDatabase = async ({ cache, dbVersion, update, url }) => { } } -const restoreFromFile = async ({ cacheLocation, dbFile, dbVersion, name }) => { +const restoreFromFile = async ({ cacheLocation, dbFile, name }) => { reporter.info(`Restoring database (this may take some time)...`) reporter.debug(`Restoring from database dump ${chalk.bold(dbFile)}`) @@ -63,5 +63,5 @@ module.exports = async ({ update, }) - await restoreFromFile({ cacheLocation, dbFile, dbVersion, name }) + await restoreFromFile({ cacheLocation, dbFile, name }) } diff --git a/packages/create/src/builders/app.js b/packages/create/src/builders/app.js index cabdfdc8..1789fd58 100644 --- a/packages/create/src/builders/app.js +++ b/packages/create/src/builders/app.js @@ -1,6 +1,6 @@ const { reporter, chalk } = require('@dhis2/cli-helpers-engine') -const buildApp = async ({ name, ...argv }) => { +const buildApp = async () => { reporter.info( `Hold your horses! DHIS2 application bootstrapping with ${chalk.bold( 'd2 create app' diff --git a/packages/create/src/index.js b/packages/create/src/index.js index bb0ea946..6f305976 100644 --- a/packages/create/src/index.js +++ b/packages/create/src/index.js @@ -12,7 +12,7 @@ const handler = async ({ type, name, ...argv }) => { } type = type.toLowerCase() switch (type) { - case 'cli': + case 'cli': { reporter.info(`Creating CLI module in ${name}...`) const data = await cliBuilder({ name, ...argv }) const dest = path.join(process.cwd(), data.basename) @@ -23,8 +23,8 @@ const handler = async ({ type, name, ...argv }) => { reporter.debug(' dest:', dest) reporter.debug(' data: ', data) await installTemplate(src, dest, data) - break + } case 'app': await require('./builders/app')({ name, ...argv }) break @@ -35,17 +35,6 @@ const handler = async ({ type, name, ...argv }) => { const command = { command: 'create [name]', desc: 'Create various DHIS2 components from templates', - builder: yargs => { - // yargs.positional('type', { - // describe: 'The type of thing to create', - // choices: ['cli', 'app'], - // type: 'string' - // }); - // yargs.positional('name', { - // describe: 'The name of the directory in which to create the thing', - // type: 'string' - // }); - }, handler, } diff --git a/packages/main/src/commands/debug/config.js b/packages/main/src/commands/debug/config.js index a93dfae7..1dc47438 100644 --- a/packages/main/src/commands/debug/config.js +++ b/packages/main/src/commands/debug/config.js @@ -1,4 +1,4 @@ -const run = ({ _, $0, raw, ...argv }) => { +const run = ({ raw, ...argv }) => { const out = JSON.stringify(argv, undefined, raw ? undefined : 2) console.log(out) } diff --git a/packages/utils/src/cmds/schema/README.md b/packages/utils/src/cmds/schema/README.md index 35dddfeb..885f0322 100644 --- a/packages/utils/src/cmds/schema/README.md +++ b/packages/utils/src/cmds/schema/README.md @@ -7,18 +7,22 @@ Utility tools that operate on DHIS2-schemas. ## Diff -Diffs DHIS2-schemas. Can use running DHIS2 instances as input, which will download the schemas and diff these, providing a a variety of [formats](#--format). This is useful to show changes between versions / revisions. Can also use files from the [*fetch*](#fetch)-command. +Diffs DHIS2-schemas. Can use running DHIS2 instances as input, which will download the schemas and diff these, providing a a variety of [formats](#--format). This is useful to show changes between versions / revisions. Can also use files from the [_fetch_](#fetch)-command. ### Usage #### Examples + **Note** that these examples assume that you have setup the [configuration](#configuration)-file with `baseUrl: https://play.dhis2.org` Basic usage; downloads schemas from the [play](https://play.dhis2.org/)-server and outputs a format akin to `git diff` to the terminal. + ```bash d2 utils schema diff /2.31 /2.32dev ``` + Output a html file with the version and revision in the filename to the current working directory. Open the file in the browser, using OSX's [open](https://ss64.com/osx/open.html). See [xdg-open](https://linux.die.net/man/1/xdg-open) for a linux equivalent. + ```bash d2 utils schema diff /2.31 /2.32dev --format html -o | xargs open ``` @@ -26,6 +30,7 @@ d2 utils schema diff /2.31 /2.32dev --format html -o | xargs open **Note** that to use relative urls they must start with `/`. If not, the url will be assumed to be absolute and the request will fail Use absolute URLs. Output html-file to home/Documents directory. + ```bash d2 utils schema diff https://birk.dev/master https://play.dhis2.org/dev/ --format html -o ~/Documents/ ``` @@ -33,35 +38,41 @@ d2 utils schema diff https://birk.dev/master https://play.dhis2.org/dev/ --forma ### Options ##### --auth + If true a prompt will ask for username and password for each server. Note that you can still provide authentication from `config.js`. If the flag is omitted or `--auth=false` credentials from `config.js` will be read. Note that the prompt is shown if no credentials can be resolved from the [configuration](#configuration)-file. -##### --output, -o +##### --output, -o + Specify the location of the output. If used as a flag (no arguments) a file relative to current working directory is generated with the name -"LEFT-version_revision__RIGHT-version_revision.html". +"LEFT-version_revision\_\_RIGHT-version_revision.html". If the location is a directory, the default filename is used and output to location. -The output of the program changes to this path-location, so it can be combined with pipe. Eg +The output of the program changes to this path-location, so it can be combined with pipe. Eg `d2 utils schema diff /2.31 /2.32 --format html -o | xargs open` will pass the path to `xargs open`, and open the html-diff in your browser. ##### --format -Specify the format of the output. Can be one of `["html", "json", "console"]`. + +Specify the format of the output. Can be one of `["html", "json", "console"]`. JSON is the raw output of [jsondiffpatch](https://github.com/benjamine/jsondiffpatch/blob/master/docs/arrays.md), see the [delta format](https://github.com/benjamine/jsondiffpatch/blob/master/docs/deltas.md) for information about this format. Default: console. -##### --base-url, -b +##### --base-url, -b + Base-Url to use for downloading schemas. If this is set leftServer and rightServer should be relative to this url, eg. /dev. Note the leading slash for the relative urls. ##### --ignore-array-order + The server returns non-deterministic ordering of arrays. Enabling this will prevent most internal array moves, which are probably irrelevant anyway. ### Configuration Many of the above options may be provided through the `d2` configuration file, which by default is located at `~/.config/d2/config.js`. This is especially useful for credentials. The file is namespaced by command, an example of such a file: + ``` module.exports = { utils: { @@ -79,15 +90,15 @@ module.exports = { ``` Authorization is handled in the following way: - - Per-server configuration (e.g. leftServer) is read first, if either password or username are non-existant or blank, the `schema`-level are used. - - If `schema`-level configuration is blank, an interactive prompt for username and password will be shown. - In the example configuration file above, `leftServer` will use schema-level credentials (admin, district), while `rightServer` will use `john, district`, +- Per-server configuration (e.g. leftServer) is read first, if either password or username are non-existant or blank, the `schema`-level are used. +- If `schema`-level configuration is blank, an interactive prompt for username and password will be shown. -## Fetch +In the example configuration file above, `leftServer` will use schema-level credentials (admin, district), while `rightServer` will use `john, district`, -Fetches schemas from a _running_ DHIS2 instance. The schemas are compatible with the *diff*-command. +## Fetch +Fetches schemas from a _running_ DHIS2 instance. The schemas are compatible with the _diff_-command. ### Usage @@ -99,12 +110,13 @@ Fetch supports multiple urls at the same time. These can be a combination of rel #### Examples -Downloads schemas relative to working directory with auto-generated name. +Downloads schemas relative to working directory with auto-generated name. + ``` d2 utils schema fetch https://play.dhis2.org/dev -o ``` -Combination of relative and absolute urls. Note that the protocol is not needed. `https` is prepended if the urls does *not* start with `/`. This is the reason why it's important to start relative urls with `/`. +Combination of relative and absolute urls. Note that the protocol is not needed. `https` is prepended if the urls does _not_ start with `/`. This is the reason why it's important to start relative urls with `/`. ``` d2 utils schema fetch https://play.dhis2.org/dev birk.dev/master /2.32 --base-url play.dhis2.org -o @@ -113,23 +125,25 @@ d2 utils schema fetch https://play.dhis2.org/dev birk.dev/master /2.32 --base-ur ##### With Diff command It's possible to use a one-liner to download the schemas and pipe this file location to the [diff](#diff)-command. The following example will download the schemas to the current working directory, while downloading `2.31` schemas and diffing these. Output is an html file in the current directory. + ``` d2 utils schema fetch https://play.dhis2.org/dev -o | xargs d2 utils schema diff /2.31 -o --format html ``` - ### Configuration -Configuration is mostly identical to the Diff command. However, options are only read from the `schema`-object. This is mostly useful for credentials and `base-url`. - +Configuration is mostly identical to the Diff command. However, options are only read from the `schema`-object. This is mostly useful for credentials and `base-url`. ### Options ##### --auth + See [auth](#--auth) ##### --output, -o + See [output](#--output). In addition, if multiple urls are given, the path will be resolved to the [directory-path](https://nodejs.org/api/path.html#path_path_dirname_path). ##### --base-url, -b + Base-Url to use for downloading schemas. If this is set, urls that are relative (starts with `/`) will be appended to this url. eg. /dev. Note the leading slash for the relative urls. diff --git a/packages/utils/src/cmds/schema/fetch.js b/packages/utils/src/cmds/schema/fetch.js index 750849e9..9b13ec82 100644 --- a/packages/utils/src/cmds/schema/fetch.js +++ b/packages/utils/src/cmds/schema/fetch.js @@ -10,7 +10,7 @@ const path = require('path') const handler = async ({ urls, output = false, force, ...rest }) => { const cache = rest.getCache() - ;({ auth, baseUrl } = resolveConfig(rest)) + const { auth, baseUrl } = resolveConfig(rest) for (let url of urls) { let bUrl = baseUrl diff --git a/packages/utils/src/cmds/schema/index.js b/packages/utils/src/cmds/schema/index.js index 194a2cac..083791bb 100644 --- a/packages/utils/src/cmds/schema/index.js +++ b/packages/utils/src/cmds/schema/index.js @@ -1,6 +1,5 @@ const fs = require('fs') const path = require('path') -const { namespace } = require('@dhis2/cli-helpers-engine') const utils = require('../../support/utils') const request = require('request') const inquirer = require('inquirer') @@ -25,7 +24,7 @@ const schemaDiffIdentifier = (info1, info2) => `${schemaIdentifier(info1)}__${schemaIdentifier(info2)}` function asyncRequest(url, opts) { - return new Promise((resolve, reject) => { + return new Promise(resolve => { request.get(url, opts, (err, res, body) => { if (err || res.statusCode > 299) { reporter.error('Request', url, 'failed to fetch') diff --git a/packages/utils/src/support/semantic-release-defer-release.js b/packages/utils/src/support/semantic-release-defer-release.js index 7a65ea6d..c8706c21 100644 --- a/packages/utils/src/support/semantic-release-defer-release.js +++ b/packages/utils/src/support/semantic-release-defer-release.js @@ -1,6 +1,4 @@ -const SemanticReleaseError = require('@semantic-release/error') - -const analyzeCommits = (config = {}, context) => { +const analyzeCommits = (config, context) => { const { logger, commits } = context const { message, commit } = commits[0] diff --git a/packages/utils/src/support/semantic-release-update-deps.js b/packages/utils/src/support/semantic-release-update-deps.js index 137bca21..7152ddc8 100644 --- a/packages/utils/src/support/semantic-release-update-deps.js +++ b/packages/utils/src/support/semantic-release-update-deps.js @@ -21,17 +21,17 @@ const verifyConditions = (config = {}, context) => { throw new AggregateError(errors) } - validPackages.forEach(package => { - package.label = package.json.name || '' + validPackages.forEach(pkg => { + pkg.label = pkg.json.name || '' if (!silent) { - logger.log(`Package ${package.label} found at ${package.path}`) + logger.log(`Package ${pkg.label} found at ${pkg.path}`) } }) context.packages = validPackages } -const replaceDependencies = (pkg, listNames, packageNames, version) => { +const replaceDependencies = ({ pkg, listNames, packageNames, version }) => { const dependencies = [] packageNames.forEach(packageName => { listNames.forEach(listName => { @@ -55,38 +55,34 @@ const prepare = (config, context) => { ? nextRelease.version : `^${nextRelease.version}` - const names = packages.map(package => package.json.name).filter(n => n) - packages.forEach(package => { - const pkgJson = package.json - const relativePath = path.relative(context.cwd, package.path) + const names = packages.map(pkg => pkg.json.name).filter(n => n) + packages.forEach(pkg => { + const pkgJson = pkg.json + const relativePath = path.relative(context.cwd, pkg.path) if (updatePackageVersion) { pkgJson.version = nextRelease.version if (!silent) { logger.log( - `Updated version to ${nextRelease.version} for package ${ - package.label - } at ${relativePath}` + `Updated version to ${nextRelease.version} for package ${pkg.label} at ${relativePath}` ) } } - replaceDependencies( - pkgJson, - ['dependencies', 'devDependencies', 'peerDependencies'], - names, - targetVersion - ).forEach( + replaceDependencies({ + pkg: pkgJson, + listNames: ['dependencies', 'devDependencies', 'peerDependencies'], + packageNames: names, + version: targetVersion, + }).forEach( dep => !silent && logger.log( - `Upgraded dependency ${dep}@${targetVersion} for ${ - package.label - } at ${relativePath}` + `Upgraded dependency ${dep}@${targetVersion} for ${pkg.label} at ${relativePath}` ) ) fs.writeFileSync( - package.path, + pkg.path, JSON.stringify(pkgJson, undefined, tabSpaces) + '\n' ) }) From e930a11ab112c1524e909c962868400050301336 Mon Sep 17 00:00:00 2001 From: Viktor Varland Date: Thu, 12 Mar 2020 14:44:49 +0100 Subject: [PATCH 4/4] ci(actions): update workflow templates --- .github/workflows/node-lint.yml | 3 +-- .github/workflows/node-publish.yml | 3 +-- .github/workflows/node-test.yml | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/node-lint.yml b/.github/workflows/node-lint.yml index a4316a91..e8f9ca5c 100644 --- a/.github/workflows/node-lint.yml +++ b/.github/workflows/node-lint.yml @@ -3,8 +3,7 @@ name: 'dhis2-node lint' on: push jobs: - pr: - name: Lint + check: runs-on: ubuntu-latest if: "!contains(github.event.head_commit.message, '[skip ci]')" steps: diff --git a/.github/workflows/node-publish.yml b/.github/workflows/node-publish.yml index 9f5fe135..67985a27 100644 --- a/.github/workflows/node-publish.yml +++ b/.github/workflows/node-publish.yml @@ -23,8 +23,7 @@ env: GH_TOKEN: ${{secrets.GH_TOKEN}} jobs: - process: - name: Publish + publish: runs-on: ubuntu-latest if: "!contains(github.event.head_commit.message, '[skip ci]')" steps: diff --git a/.github/workflows/node-test.yml b/.github/workflows/node-test.yml index 6a7d0aa8..8a795ffe 100644 --- a/.github/workflows/node-test.yml +++ b/.github/workflows/node-test.yml @@ -3,8 +3,7 @@ name: 'dhis2-node test' on: push jobs: - pr: - name: Unit + unit: runs-on: ubuntu-latest if: "!contains(github.event.head_commit.message, '[skip ci]')" steps: