diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..bb85b6f9 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,11 @@ +version: 2 +updates: + - package-ecosystem: github-actions + directory: / + schedule: + interval: daily + + - package-ecosystem: npm + directory: / + schedule: + interval: daily diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index aa7b67c8..e9d2cfd0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -7,6 +7,10 @@ on: push: branches: - master + - next + - next-major + - alpha + - beta jobs: release: @@ -20,7 +24,6 @@ jobs: uses: cycjimmy/semantic-release-action@v2 id: semantic with: - branch: master extra_plugins: | @semantic-release/git @semantic-release/changelog @@ -29,10 +32,9 @@ jobs: NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - name: Setup Node.js with GitHub Package Registry - uses: actions/setup-node@v1 + uses: actions/setup-node@v2 with: - node-version: 12 - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + node-version: 14 registry-url: 'https://npm.pkg.github.com' scope: 'cycjimmy' @@ -47,4 +49,3 @@ jobs: run: "git push https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git HEAD:refs/heads/v${{steps.semantic.outputs.new_release_major_version}}" env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - diff --git a/.github/workflows/testRelease.yml b/.github/workflows/testRelease.yml index baf7e9c3..dd34b3f7 100644 --- a/.github/workflows/testRelease.yml +++ b/.github/workflows/testRelease.yml @@ -4,27 +4,85 @@ on: push: branches: - master + - next + - next-major + - alpha + - beta + - 'feat/**' + - 'fix/**' + - 'perf/**' + - 'refactor/**' schedule: - cron: 0 2 * * 0 jobs: - test: - name: release + test-semantic-latest: + name: test-semantic-latest runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v2 - name: Semantic Release - uses: cycjimmy/semantic-release-action@v2 + uses: ./ id: semantic with: + dry_run: true + branches: | + [ + '+([0-9])?(.{+([0-9]),x}).x', + 'master', + 'next', + 'next-major', + { + name: 'beta', + prerelease: true + }, + { + name: 'alpha', + prerelease: true + } + ] branch: master extra_plugins: | @semantic-release/git @semantic-release/changelog + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + + - name: Test Outputs + if: steps.semantic.outputs.new_release_published == 'true' + run: | + echo ${{ steps.semantic.outputs.new_release_version }} + echo ${{ steps.semantic.outputs.new_release_major_version }} + echo ${{ steps.semantic.outputs.new_release_minor_version }} + echo ${{ steps.semantic.outputs.new_release_patch_version }} + + test-semantic-v15: + name: test-semantic-v15 + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Semantic Release + uses: ./ + id: semantic + with: + semantic_version: 15 dry_run: true + branches: | + [ + 'master', + {name: 'beta', prerelease: true}, + {name: 'alpha', prerelease: true} + ] + branch: master + extra_plugins: | + @semantic-release/git@7 + @semantic-release/changelog@3 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }} @@ -38,3 +96,4 @@ jobs: echo ${{ steps.semantic.outputs.new_release_patch_version }} echo ${{ steps.semantic.outputs.new_release_notes }} + diff --git a/.gitignore b/.gitignore index db7958e3..0b86e7e2 100644 --- a/.gitignore +++ b/.gitignore @@ -52,9 +52,4 @@ Temporary Items # nodejs node_modules/ npm-debug.log -yarn-error.log - -# project -.publish -dist diff --git a/LICENSE b/LICENSE index d678c9cf..1e5cc8e2 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2019 cycjimmy +Copyright (c) 2019-2020 cycjimmy Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index b33a4748..b4de0945 100644 --- a/README.md +++ b/README.md @@ -1,54 +1,38 @@ # Semantic Release Action +![][version-image] ![][workflows-badge-image] +[![Release date][release-date-image]][release-url] [![semantic-release][semantic-image]][semantic-url] -![npm license][license-image] +[![npm license][license-image]][license-url] -[workflows-badge-image]: https://github.com/cycjimmy/semantic-release-action/workflows/Test%20Release/badge.svg -[semantic-url]: https://github.com/semantic-release/semantic-release -[semantic-image]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg -[license-image]: https://img.shields.io/npm/l/@cycjimmy/semantic-release-action.svg?style=flat-square - -GitHub Action for [Semantic Release](https://github.com/semantic-release/semantic-release). +GitHub Action for [Semantic Release][semantic-url]. ## Usage -#### Step1: Set any [Semantic Release Configuration](https://github.com/semantic-release/semantic-release/blob/master/docs/usage/configuration.md#configuration) in your repository. - -#### Step2: [Add Secrets](https://help.github.com/en/articles/virtual-environments-for-github-actions#creating-and-using-secrets-encrypted-variables) in your repository for the [Semantic Release Authentication](https://github.com/semantic-release/semantic-release/blob/master/docs/usage/ci-configuration.md#authentication) Environment Variables. - -#### Step3: Add a [Workflow File](https://help.github.com/en/articles/workflow-syntax-for-github-actions) to your repository to create custom automated processes. -* inputs: - * `branch`: [Optional] The branch on which releases should happen. It will override the branch attribute in your configuration file. If the attribute is not configured on both sides, the default is master. - * `semantic_version`: [Optional] Specify specifying version range for semantic-release. If no version range is specified, latest version will be used by default. - * `extra_plugins`: [Optional] Extra plugins for pre-install. You can also specify specifying version range for the extra plugins if you prefer. - * `dry_run`: [Optional] Whether to run semantic release in `dry-run` mode. It will override the dryRun attribute in your configuration file. -* outputs: - * `new_release_published`: Whether a new release was published. `true` or `false` - * `new_release_version`: Version of the new release - * `new_release_major_version`: Major version of the new release - * `new_release_minor_version`: Minor version of the new release - * `new_release_patch_version`: Patch version of the new release - * `new_release_notes`: Release notes of the new release - -### Examples - -#### A simple example - ```yaml steps: - name: Checkout uses: actions/checkout@v2 - name: Semantic Release uses: cycjimmy/semantic-release-action@v2 + with: + semantic_version: 15.13.28 + # you can set branch for semantic-release older than v16. + branch: your-branch env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }} ``` -#### Passing Extra Plugins with `extra_plugins` +It will override the `branch` attribute in your configuration file. If the attribute is not configured on both sides, the default is `master`. + +#### extra_plugins +> {Optional Input Parameter} Extra plugins for pre-install. -The action can be used with `extra_plugins` option to specify plugins which are not in the [default list of plugins of semantic release](https://semantic-release.gitbook.io/semantic-release/usage/plugins#default-plugins). When using this option, please make sure that these plugins are also mentioned in your [semantic release config's plugins](https://semantic-release.gitbook.io/semantic-release/usage/configuration#plugins) array. For example, if you want to use `@semantic-release/git` and `@semantic-release/changelog` extra plugins, these must be added to `extra_plugins` in your actions file and `plugins` in your [release config file](https://semantic-release.gitbook.io/semantic-release/usage/configuration#configuration-file) as shown bellow: +The action can be used with `extra_plugins` option to specify plugins which are not in the [default list of plugins of semantic release](https://semantic-release.gitbook.io/semantic-release/usage/plugins#default-plugins). When using this option, please make sure that these plugins are also mentioned in your [semantic release config's plugins](https://semantic-release.gitbook.io/semantic-release/usage/configuration#plugins) array. -_github-action_ +For example, if you want to use `@semantic-release/git` and `@semantic-release/changelog` extra plugins, these must be added to `extra_plugins` in your actions file and `plugins` in your [release config file](https://semantic-release.gitbook.io/semantic-release/usage/configuration#configuration-file) as shown bellow: + +Github Action Workflow: ```yaml steps: - name: Checkout @@ -65,20 +49,19 @@ steps: NPM_TOKEN: ${{ secrets.NPM_TOKEN }} ``` -_release-config_ +Similar to parameter `semantic_version`. *It is recommended to manually specify a version of semantic-release plugins to prevent errors caused.* +Release Config: ```diff plugins: [ . - . + "@semantic-release/changelog" + "@semantic-release/git", ] ``` -#### Manually Specify a Version of Semantic-release and Its Plugins - -It is recommended to manually specify a version of semantic-release and its plugins to prevent errors caused during the official semantic-release upgrade. +#### dry_run +> {Optional Input Parameter} Whether to run semantic release in `dry-run` mode.
It will override the dryRun attribute in your configuration file. ```yaml steps: @@ -87,16 +70,42 @@ steps: - name: Semantic Release uses: cycjimmy/semantic-release-action@v2 with: - semantic_version: 15.14.0 - extra_plugins: | - @semantic-release/git@7.0.18 + dry_run: true env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }} ``` -#### Using Output Variables +#### extends +The action can be used with `extends` option to extend an existing [sharable configuration](https://semantic-release.gitbook.io/semantic-release/usage/shareable-configurations) of semantic-release. Can be used in combination with `extra_plugins`. +```yaml +steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Semantic Release + uses: cycjimmy/semantic-release-action@v2 + with: + # You can extend an existing shareable configuration. + extends: | + @semantic-release/apm-config + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} +``` + +### Outputs +| Output Parameter | Description | +|:-------------------------:|---| +| new_release_published | Whether a new release was published (`true` or `false`) | +| new_release_version | Version of the new release. (e.g. `1.3.0`) | +| new_release_major_version | Major version of the new release. (e.g. `1`) | +| new_release_minor_version | Minor version of the new release. (e.g. `3`) | +| new_release_patch_version | Patch version of the new release. (e.g. `0`) | +| new_release_channel | The distribution channel on which the last release was initially made available (undefined for the default distribution channel). | +| new_release_notes | The release notes for the new release. | + +#### Using Output Variables: ```yaml steps: - name: Checkout @@ -110,8 +119,33 @@ steps: - name: Do something when a new release published if: steps.semantic.outputs.new_release_published == 'true' - run: echo ${{ steps.semantic.outputs.new_release_version }} + run: | + echo ${{ steps.semantic.outputs.new_release_version }} + echo ${{ steps.semantic.outputs.new_release_major_version }} + echo ${{ steps.semantic.outputs.new_release_minor_version }} + echo ${{ steps.semantic.outputs.new_release_patch_version }} ``` -## [CHANGELOG](./docs/CHANGELOG.md) +## Changelog +See [CHANGELOG][changelog-url]. + +## License +This project is released under the [MIT License][license-url]. + + +[version-image]: https://img.shields.io/github/package-json/v/cycjimmy/semantic-release-action + +[workflows-badge-image]: https://github.com/cycjimmy/semantic-release-action/workflows/Test%20Release/badge.svg + +[release-date-image]: https://img.shields.io/github/release-date/cycjimmy/semantic-release-action +[release-url]: https://github.com/cycjimmy/semantic-release-action/releases + +[semantic-image]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg +[semantic-url]: https://github.com/semantic-release/semantic-release + +[license-image]: https://img.shields.io/npm/l/@cycjimmy/semantic-release-action.svg +[license-url]: https://github.com/cycjimmy/semantic-release-action/blob/master/LICENSE + +[changelog-url]: https://github.com/cycjimmy/semantic-release-action/blob/master/docs/CHANGELOG.md +[github-packages-registry]: https://github.com/features/packages diff --git a/action.yml b/action.yml index 01e6abb8..7cc65c43 100644 --- a/action.yml +++ b/action.yml @@ -5,14 +5,24 @@ branding: icon: 'package' color: 'orange' inputs: - branch: - description: 'The branch on which releases should happen. It will override the branch attribute in your configuration file. If the attribute is not configured on both sides, the default is master.' semantic_version: - description: 'Specify specifying version range for semantic-release. If no version range is specified, semantic-release@^15 will be used by default.' + required: false + description: 'Specify specifying version range for semantic-release. If no version range is specified, latest version will be used by default' + branches: + required: false + description: 'The branches on which releases should happen. It will override the branches attribute in your configuration file. Support for semantic-release above v16. See https://semantic-release.gitbook.io/semantic-release/usage/configuration#branches for more information.' + branch: + required: false + description: 'The branch on which releases should happen. It will override the branch attribute in your configuration file. If the attribute is not configured on both sides, the default is master. Support for semantic-release older than v16.' extra_plugins: + required: false description: 'Extra plugins for pre-install. You can also specify specifying version range for the extra plugins if you prefer.' dry_run: + required: false description: 'Whether to run semantic release in `dry-run` mode. It will override the dryRun attribute in your configuration file' + extends: + required: false + description: 'One or several sharable configurations, https://semantic-release.gitbook.io/semantic-release/usage/configuration#extends' outputs: new_release_published: description: 'Whether a new release was published' @@ -24,8 +34,10 @@ outputs: description: 'Minor version of the new release' new_release_patch_version: description: 'Patch version of the new release' + new_release_channel: + description: 'The distribution channel on which the last release was initially made available (undefined for the default distribution channel).' new_release_notes: - description: 'Release notes of the new release' + description: 'The release notes for the new release.' runs: using: 'node12' main: 'index.js' diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index e5418f1b..9ca4655d 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,3 +1,78 @@ +## [2.5.4](https://github.com/cycjimmy/semantic-release-action/compare/v2.5.3...v2.5.4) (2021-04-30) + + +### Bug Fixes + +* use error loglevel for installing dependencies ([ed6729b](https://github.com/cycjimmy/semantic-release-action/commit/ed6729b716d281c2c4058d3553f3229a80203a79)), closes [#57](https://github.com/cycjimmy/semantic-release-action/issues/57) + +## [2.5.3](https://github.com/cycjimmy/semantic-release-action/compare/v2.5.2...v2.5.3) (2020-11-16) + + +### Bug Fixes + +* fix a type error when nextRelease is undefined ([f1ae39a](https://github.com/cycjimmy/semantic-release-action/commit/f1ae39a58a030dccda8bd11b51266b4824871e1f)) + +## [2.5.2](https://github.com/cycjimmy/semantic-release-action/compare/v2.5.1...v2.5.2) (2020-11-12) + + +### Bug Fixes + +* use silent installation to prevent npm WARN ([7ca507d](https://github.com/cycjimmy/semantic-release-action/commit/7ca507d26a166ce426d8326c6d47d2ae94e469ff)), closes [#48](https://github.com/cycjimmy/semantic-release-action/issues/48) + +## [2.5.1](https://github.com/cycjimmy/semantic-release-action/compare/v2.5.0...v2.5.1) (2020-11-12) + + +### Bug Fixes + +* **deps:** upgrade dependencies ([2a98893](https://github.com/cycjimmy/semantic-release-action/commit/2a988931ba18eb8d84d8a7229672ce2fc932afc6)), closes [#44](https://github.com/cycjimmy/semantic-release-action/issues/44) + +# [2.5.0](https://github.com/cycjimmy/semantic-release-action/compare/v2.4.2...v2.5.0) (2020-07-02) + + +### Features + +* **outputs:** add new_release_channel ([ae40dc6](https://github.com/cycjimmy/semantic-release-action/commit/ae40dc665849d2b1a1a68751c65c88c0474395f4)) + +## [2.4.2](https://github.com/cycjimmy/semantic-release-action/compare/v2.4.1...v2.4.2) (2020-07-02) + + +### Bug Fixes + +* **new_release_patch_version:** fix the problem of inaccurate new_release_patch_version ([5da0ac5](https://github.com/cycjimmy/semantic-release-action/commit/5da0ac558eb3a3a8eb75460ff9bd55cb1217da2d)) + +## [2.4.1](https://github.com/cycjimmy/semantic-release-action/compare/v2.4.0...v2.4.1) (2020-05-01) + + +### Bug Fixes + +* **deps:** Update @actions/core to ^1.2.4 ([00f8039](https://github.com/cycjimmy/semantic-release-action/commit/00f8039cb6e50b6a052d33f8bbc76462e49a16ee)) + +# [2.4.0](https://github.com/cycjimmy/semantic-release-action/compare/v2.3.0...v2.4.0) (2020-04-30) + + +### Bug Fixes + +* fixes rebase mistake for import of renamed func ([ddb8d28](https://github.com/cycjimmy/semantic-release-action/commit/ddb8d2814d0253519aec32bec92600fc9fc9a305)) + + +### Features + +* added ability to use the "extends" settings ([32db8a4](https://github.com/cycjimmy/semantic-release-action/commit/32db8a49b25f46b98a901084ada97b6aa7343813)) + +# [2.3.0](https://github.com/cycjimmy/semantic-release-action/compare/v2.2.0...v2.3.0) (2020-03-21) + + +### Features + +* **branches:** support branches of semantic-release v16+ ([706c0ef](https://github.com/cycjimmy/semantic-release-action/commit/706c0ef960497657ddf0655d0a69732323d93238)), closes [#24](https://github.com/cycjimmy/semantic-release-action/issues/24) [#25](https://github.com/cycjimmy/semantic-release-action/issues/25) + +# [2.2.0](https://github.com/cycjimmy/semantic-release-action/compare/v2.1.3...v2.2.0) (2020-03-15) + + +### Features + +* add release notes to output ([a56320d](https://github.com/cycjimmy/semantic-release-action/commit/a56320d643d6a8e0c688a84f18449153865b8bc4)) + ## [2.1.3](https://github.com/cycjimmy/semantic-release-action/compare/v2.1.2...v2.1.3) (2020-01-19) diff --git a/index.js b/index.js index 7b7b8002..f012c734 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,7 @@ const path = require('path'); const run = async () => { // Install Dependencies { - const {stdout, stderr} = await exec('npm ci --only=prod', { + const {stdout, stderr} = await exec('npm --loglevel error ci --only=prod', { cwd: path.resolve(__dirname) }); console.log(stdout); diff --git a/package-lock.json b/package-lock.json index 4affbc89..a539cce3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,18 +1,23 @@ { "name": "@cycjimmy/semantic-release-action", - "version": "2.1.3", + "version": "2.5.4", "lockfileVersion": 1, "requires": true, "dependencies": { "@actions/core": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.0.tgz", - "integrity": "sha512-ZKdyhlSlyz38S6YFfPnyNgCDZuAF2T0Qv5eHflNWytPS8Qjvz39bZFMry9Bb/dpSnqWcNeav5yM2CTYpJeY+Dw==" + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.4.0.tgz", + "integrity": "sha512-CGx2ilGq5i7zSLgiiGUtBCxhRRxibJYU6Fim0Q1Wg2aQL2LTnF27zbqZOrxfvFQ55eSBW0L8uVStgtKMpa0Qlg==" + }, + "@cycjimmy/awesome-js-funcs": { + "version": "2.6.1", + "resolved": "https://registry.npmjs.org/@cycjimmy/awesome-js-funcs/-/awesome-js-funcs-2.6.1.tgz", + "integrity": "sha512-MnAVfczaZfV0/js3WMEeuqnsr95/g9qvT0gajFiImjjwXB9j+42akZhMjHHcxDtaAl5gZeitG4+u055NcJ89fQ==" }, "@types/unist": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/@types/unist/-/unist-2.0.3.tgz", - "integrity": "sha512-FvUupuM3rlRsRtCN+fDudtmytGO6iHJuuRKS1Ss0pG5z8oX0diNEw94UEL7hgDbpN94rgaK5R7sWm6RrSkZuAQ==" + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/@types/unist/-/unist-2.0.6.tgz", + "integrity": "sha512-PBjIUxZHOuj0R15/xuwJYjFi+KZdNFrehocChv4g5hu6aFroHue8m0lBP0POdK2nKzbw0cgV1mws8+V/JAcEkQ==" }, "bail": { "version": "1.0.5", @@ -20,9 +25,9 @@ "integrity": "sha512-xFbRxM1tahm08yHBP16MMjVUAvDaBMD38zsM9EMAUN61omwLmKlOpB/Zku5QkjZ8TZ4vn53pj+t518cH0S03RQ==" }, "ccount": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/ccount/-/ccount-1.0.5.tgz", - "integrity": "sha512-MOli1W+nfbPLlKEhInaxhRdp7KVLFxLN5ykwzHgLsLI3H3gs5jjFAK4Eoj3OzzcxCtumDaI8onoVDeQyWaNTkw==" + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/ccount/-/ccount-1.1.0.tgz", + "integrity": "sha512-vlNK021QdI7PNeiUh/lKkC/mNHHfV0m/Ad5JoI0TYtlBnJAslM/JIkm/tGC88bkLIwO6OQ5uV6ztS6kVAtCDlg==" }, "character-entities": { "version": "1.2.4", @@ -79,9 +84,9 @@ } }, "is-buffer": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.4.tgz", - "integrity": "sha512-Kq1rokWXOPXWuaMAqZiJW4XxsmD9zGx9q4aePabbn3qCRGedtH7Cm+zV8WETitMfu1wdh+Rvd6w5egwSngUX2A==" + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.5.tgz", + "integrity": "sha512-i2R6zNFDwgEHJyQUtJEk0XFi1i0dPFn/oqjK3/vPCcDeJvW5NQ83V8QbicfF1SupOaB0h8ntgBC2YiE7dfyctQ==" }, "is-decimal": { "version": "1.0.4", @@ -192,11 +197,6 @@ "resolved": "https://registry.npmjs.org/repeat-string/-/repeat-string-1.6.1.tgz", "integrity": "sha1-jcrkcOHIirwtYA//Sndihtp15jc=" }, - "replace-ext": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/replace-ext/-/replace-ext-1.0.0.tgz", - "integrity": "sha1-3mMSg3P8v3w8z6TeWkgMRaZ5WOs=" - }, "slackify-markdown": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/slackify-markdown/-/slackify-markdown-2.1.0.tgz", @@ -230,9 +230,9 @@ "integrity": "sha1-WFhUf2spB1fulczMZm+1AITEYN0=" }, "trim-trailing-lines": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/trim-trailing-lines/-/trim-trailing-lines-1.1.3.tgz", - "integrity": "sha512-4ku0mmjXifQcTVfYDfR5lpgV7zVqPg6zV9rdZmwOPqq0+Zq19xDqEgagqVbc4pOOShbncuAOIs59R3+3gcF3ZA==" + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/trim-trailing-lines/-/trim-trailing-lines-1.1.4.tgz", + "integrity": "sha512-rjUWSqnfTNrjbB9NQWfPMH/xRK1deHeGsHoVfpxJ++XeYXE0d6B1En37AHfw3jtfTU7dzMzZL2jjpe8Qb5gLIQ==" }, "trough": { "version": "1.0.5", @@ -274,9 +274,9 @@ } }, "unist-util-stringify-position": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/unist-util-stringify-position/-/unist-util-stringify-position-2.0.2.tgz", - "integrity": "sha512-nK5n8OGhZ7ZgUwoUbL8uiVRwAbZyzBsB/Ddrlbu6jwwubFza4oe15KlyEaLNMXQW1svOQq4xesUeqA85YrIUQA==", + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/unist-util-stringify-position/-/unist-util-stringify-position-2.0.3.tgz", + "integrity": "sha512-3faScn5I+hy9VleOq/qNbAd6pAx7iH5jYBMS9I1HgQVijz/4mv5Bvw5iw1sC/90CODiKo81G/ps8AJrISn687g==", "requires": { "@types/unist": "^2.0.2" } @@ -298,13 +298,12 @@ } }, "vfile": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/vfile/-/vfile-4.0.2.tgz", - "integrity": "sha512-yhoTU5cDMSsaeaMfJ5g0bUKYkYmZhAh9fn9TZicxqn+Cw4Z439il2v3oT9S0yjlpqlI74aFOQCt3nOV+pxzlkw==", + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/vfile/-/vfile-4.2.1.tgz", + "integrity": "sha512-O6AE4OskCG5S1emQ/4gl8zK586RqA3srz3nfK/Viy0UPToBc5Trp9BVFb1u0CjsKrAWwnpr4ifM/KBXPWwJbCA==", "requires": { "@types/unist": "^2.0.0", "is-buffer": "^2.0.0", - "replace-ext": "1.0.0", "unist-util-stringify-position": "^2.0.0", "vfile-message": "^2.0.0" } @@ -315,9 +314,9 @@ "integrity": "sha512-sSFdyCP3G6Ka0CEmN83A2YCMKIieHx0EDaj5IDP4g1pa5ZJ4FJDvpO0WODLxo4LUX4oe52gmSCK7Jw4SBghqxA==" }, "vfile-message": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/vfile-message/-/vfile-message-2.0.2.tgz", - "integrity": "sha512-gNV2Y2fDvDOOqq8bEe7cF3DXU6QgV4uA9zMR2P8tix11l1r7zju3zry3wZ8sx+BEfuO6WQ7z2QzfWTvqHQiwsA==", + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/vfile-message/-/vfile-message-2.0.4.tgz", + "integrity": "sha512-DjssxRGkMvifUOJre00juHoP9DPWuzjxKuMDrhNbk2TdaYYBNMStsNhEOt3idrtI12VQYM/1+iM0KOzXi4pxwQ==", "requires": { "@types/unist": "^2.0.0", "unist-util-stringify-position": "^2.0.0" diff --git a/package.json b/package.json index b4efd552..30fd2b57 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@cycjimmy/semantic-release-action", - "version": "2.1.3", + "version": "2.5.4", "description": "GitHub Action for Semantic Release", "main": "index.js", "scripts": { @@ -21,7 +21,8 @@ }, "homepage": "https://github.com/cycjimmy/semantic-release-action#readme", "dependencies": { - "@actions/core": "^1.2.0", + "@actions/core": "^1.2.6", + "@cycjimmy/awesome-js-funcs": "^2.4.0", "slackify-markdown": "^2.1.0" } } diff --git a/src/handleOptions.js b/src/handleOptions.js index 33307086..4a939e57 100644 --- a/src/handleOptions.js +++ b/src/handleOptions.js @@ -1,29 +1,44 @@ const core = require('@actions/core'); +const stringToJson = require('@cycjimmy/awesome-js-funcs/typeConversion/stringToJson').default; const inputs = require('./inputs.json'); /** - * Handle Branch Option + * Handle Branches Option * @returns {{}|{branch: string}} */ -exports.handleBranchOption = () => { - const branchOption = {}; +exports.handleBranchesOption = () => { + const branchesOption = {}; + const branches = core.getInput(inputs.branches); const branch = core.getInput(inputs.branch); - if (!branch) { - return branchOption; - } + core.debug(`branches input: ${branches}`); + core.debug(`branch input: ${branch}`); const semanticVersion = require('semantic-release/package.json').version; const semanticMajorVersion = Number(semanticVersion.replace(/\..+/g, '')); core.debug(`semanticMajorVersion: ${semanticMajorVersion}`); + // older than v16 if (semanticMajorVersion < 16) { - branchOption.branch = branch; - } else { - branchOption.branches = [branch]; + if (!branch) { + return branchesOption; + } + + branchesOption.branch = branch; + return branchesOption; } - return branchOption; + // above v16 + const strNeedConvertToJson = branches || branch || ''; + + if (!strNeedConvertToJson) { + return branchesOption; + } + + const jsonOrStr = stringToJson('' + strNeedConvertToJson); + core.debug(`Converted branches attribute: ${JSON.stringify(jsonOrStr)}`); + branchesOption.branches = jsonOrStr; + return branchesOption; }; /** @@ -44,3 +59,17 @@ exports.handleDryRunOption = () => { return {}; } }; + +/** + * Handle Extends Option + * @returns {{}|{extends: Array}|{extends: String}} + */ +exports.handleExtends = () => { + const extend = core.getInput(inputs.extends); + + if (extend) { + return { extends: extend }; + } else { + return {}; + } +}; diff --git a/src/index.js b/src/index.js index 90ff1056..e512819f 100644 --- a/src/index.js +++ b/src/index.js @@ -1,10 +1,15 @@ const core = require('@actions/core'); -const {handleBranchOption, handleDryRunOption} = require('./handleOptions'); +const { + handleBranchesOption, + handleDryRunOption, + handleExtends, +} = require('./handleOptions'); const setUpJob = require('./setUpJob.task'); const installSpecifyingVersionSemantic = require('./installSpecifyingVersionSemantic.task'); -const preInstallPlugins = require('./preInstallPlugins.task'); +const preInstall = require('./preInstall.task'); const cleanupNpmrc = require('./cleanupNpmrc.task'); const windUpJob = require('./windUpJob.task'); +const inputs = require('./inputs.json'); /** * Release main task @@ -13,12 +18,14 @@ const windUpJob = require('./windUpJob.task'); const release = async () => { await setUpJob(); await installSpecifyingVersionSemantic(); - await preInstallPlugins(); + await preInstall(core.getInput(inputs.extra_plugins)); + await preInstall(core.getInput(inputs.extends)); const semanticRelease = require('semantic-release'); const result = await semanticRelease({ - ...(handleBranchOption()), - ...(handleDryRunOption()), + ...handleBranchesOption(), + ...handleDryRunOption(), + ...handleExtends(), }); await cleanupNpmrc(); diff --git a/src/inputs.json b/src/inputs.json index 5f322261..536bdace 100644 --- a/src/inputs.json +++ b/src/inputs.json @@ -1,6 +1,8 @@ { - "branch": "branch", "semantic_version": "semantic_version", + "branches": "branches", + "branch": "branch", "extra_plugins": "extra_plugins", - "dry_run": "dry_run" + "dry_run": "dry_run", + "extends": "extends" } diff --git a/src/installSpecifyingVersionSemantic.task.js b/src/installSpecifyingVersionSemantic.task.js index 752961f5..bdb0605c 100644 --- a/src/installSpecifyingVersionSemantic.task.js +++ b/src/installSpecifyingVersionSemantic.task.js @@ -13,7 +13,7 @@ module.exports = async () => { ? `@${semantic_version}` : ''; - const {stdout, stderr} = await exec(`npm install semantic-release${versionSuffix}`, { + const {stdout, stderr} = await exec(`npm install semantic-release${versionSuffix} --silent`, { cwd: path.resolve(__dirname, '..') }); core.debug(stdout); diff --git a/src/outputs.json b/src/outputs.json index ab0e1225..5666d43b 100644 --- a/src/outputs.json +++ b/src/outputs.json @@ -4,5 +4,6 @@ "new_release_major_version": "new_release_major_version", "new_release_minor_version": "new_release_minor_version", "new_release_patch_version": "new_release_patch_version", + "new_release_channel": "new_release_channel", "new_release_notes": "new_release_notes" } diff --git a/src/preInstall.task.js b/src/preInstall.task.js new file mode 100644 index 00000000..e6ed9fc1 --- /dev/null +++ b/src/preInstall.task.js @@ -0,0 +1,21 @@ +const path = require('path'); +const core = require('@actions/core'); +const exec = require('./_exec'); + +/** + * Pre-install extra dependecies + * @returns {Promise} + */ +module.exports = async extras => { + if (!extras) { + return Promise.resolve(); + } + + const _extras = extras.replace(/['"]/g, '').replace(/[\n\r]/g, ' '); + + const { stdout, stderr } = await exec(`npm install ${_extras} --silent`, { + cwd: path.resolve(__dirname, '..') + }); + core.debug(stdout); + core.error(stderr); +}; diff --git a/src/preInstallPlugins.task.js b/src/preInstallPlugins.task.js deleted file mode 100644 index 298a59ce..00000000 --- a/src/preInstallPlugins.task.js +++ /dev/null @@ -1,26 +0,0 @@ -const path = require('path'); -const core = require('@actions/core'); -const exec = require('./_exec'); -const inputs = require('./inputs.json'); - -/** - * Pre-install plugins - * @returns {Promise} - */ -module.exports = async () => { - const extraPlugins = core.getInput(inputs.extra_plugins); - - if (!extraPlugins) { - return Promise.resolve(); - } - - const _extraPlugins = extraPlugins - .replace(/['"]/g, '') - .replace(/[\n\r]/g, ' '); - - const {stdout, stderr} = await exec(`npm install ${_extraPlugins}`, { - cwd: path.resolve(__dirname, '..') - }); - core.debug(stdout); - core.error(stderr); -}; diff --git a/src/windUpJob.task.js b/src/windUpJob.task.js index 928d2307..e76d6c20 100644 --- a/src/windUpJob.task.js +++ b/src/windUpJob.task.js @@ -16,6 +16,11 @@ module.exports = async (result) => { const {lastRelease, commits, nextRelease, releases} = result; + if (!nextRelease) { + core.debug('No release published.'); + return Promise.resolve(); + } + core.debug(`Published ${nextRelease.type} release version ${nextRelease.version} containing ${commits.length} commits.`); if (lastRelease.version) { @@ -26,8 +31,8 @@ module.exports = async (result) => { core.debug(`The release was published with plugin "${release.pluginName}".`); } - const {version, notes} = nextRelease; - const [major, minor, patch] = version.split('.'); + const {version, channel, notes} = nextRelease; + const [major, minor, patch] = version.split(/\.|-|\s/g, 3); const slackNotes = slackifyMarkdown(notes).replace('|', '|v'); @@ -38,4 +43,6 @@ module.exports = async (result) => { core.setOutput(outputs.new_release_minor_version, minor); core.setOutput(outputs.new_release_patch_version, patch); core.setOutput(outputs.new_release_notes, slackNotes); + core.setOutput(outputs.new_release_channel, channel); + // core.setOutput(outputs.new_release_notes, notes); };