Skip to content

Commit

Permalink
feat: add pattern option
Browse files Browse the repository at this point in the history
resolves "Provide minimatch patterns support for `src` option as `gh-pages` does" #110
  • Loading branch information
dvirtz authored and antongolub committed Dec 8, 2024
1 parent 102d283 commit 42954db
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 19 deletions.
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# @qiwi/semantic-release-gh-pages-plugin
# @wiki/semantic-release-gh-pages-plugin

[![CI](https://github.com/qiwi/semantic-release-gh-pages-plugin/workflows/CI/badge.svg)](https://github.com/qiwi/semantic-release-gh-pages-plugin/actions)
[![Test Coverage](https://api.codeclimate.com/v1/badges/c149b0666dda28813aa4/test_coverage)](https://codeclimate.com/github/qiwi/semantic-release-gh-pages-plugin/test_coverage)
[![Maintainability](https://api.codeclimate.com/v1/badges/c149b0666dda28813aa4/maintainability)](https://codeclimate.com/github/qiwi/semantic-release-gh-pages-plugin/maintainability)
[![npm (tag)](https://img.shields.io/npm/v/@qiwi/semantic-release-gh-pages-plugin/latest.svg)](https://www.npmjs.com/package/@qiwi/semantic-release-gh-pages-plugin)
[![CI](https://github.com/wiki/semantic-release-gh-pages-plugin/workflows/CI/badge.svg)](https://github.com/wiki/semantic-release-gh-pages-plugin/actions)
[![Test Coverage](https://api.codeclimate.com/v1/badges/c149b0666dda28813aa4/test_coverage)](https://codeclimate.com/github/wiki/semantic-release-gh-pages-plugin/test_coverage)
[![Maintainability](https://api.codeclimate.com/v1/badges/c149b0666dda28813aa4/maintainability)](https://codeclimate.com/github/wiki/semantic-release-gh-pages-plugin/maintainability)
[![npm (tag)](https://img.shields.io/npm/v/@wiki/semantic-release-gh-pages-plugin/latest.svg)](https://www.npmjs.com/package/@wiki/semantic-release-gh-pages-plugin)

gh-pages publishing plugin for [semantic-release](https://github.com/semantic-release/semantic-release)

Expand All @@ -15,9 +15,9 @@ gh-pages publishing plugin for [semantic-release](https://github.com/semantic-re
## Install
```bash
# yarn
yarn add @qiwi/semantic-release-gh-pages-plugin --dev
yarn add @wiki/semantic-release-gh-pages-plugin --dev
# npm
npm i @qiwi/semantic-release-gh-pages-plugin -D
npm i @wiki/semantic-release-gh-pages-plugin -D
```

## Usage
Expand All @@ -30,13 +30,13 @@ Describe plugin configuration in [package.json / .releaserc.js](https://github.c
"@semantic-release/changelog",
"@semantic-release/npm",
"@semantic-release/git",
"@qiwi/semantic-release-gh-pages-plugin"
"@wiki/semantic-release-gh-pages-plugin"
],
"publish": [
"@semantic-release/npm",
"@semantic-release/github",
[
"@qiwi/semantic-release-gh-pages-plugin",
"@wiki/semantic-release-gh-pages-plugin",
{
"msg": "updated",
"branch": "docs"
Expand All @@ -57,7 +57,7 @@ or even shorter if default settings are used:
"@semantic-release/git",
"@semantic-release/github",
"@semantic-release/npm",
"@qiwi/semantic-release-gh-pages-plugin"
"@wiki/semantic-release-gh-pages-plugin"
]
}
}
Expand All @@ -84,6 +84,7 @@ or even shorter if default settings are used:
| `pullTagsBranch` | Target branch for tags fetching hook. If '' empty string, skips this action | `globalConfig.branch` \|\| `master` |
| `dotfiles` | gh-pages [dotfiles](https://github.com/tschaub/gh-pages#optionsdotfiles) option | `false` |
| `add` | gh-pages [add](https://github.com/tschaub/gh-pages#optionsadd) option | `false` |
| `pattern` | gh-pages [src](https://github.com/tschaub/gh-pages#optionssrc) option | `**/*` |

## License
[MIT](./LICENSE)
7 changes: 6 additions & 1 deletion src/main/ts/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
DEFAULT_DST,
DEFAULT_ENTERPRISE,
DEFAULT_MSG,
DEFAULT_PATTERN,
DEFAULT_PULL_TAGS_BRANCH,
DEFAULT_SRC,
PLUGIN_PATH} from './defaults'
Expand All @@ -27,7 +28,8 @@ export {
DEFAULT_DST,
DEFAULT_ENTERPRISE,
PLUGIN_PATH,
DEFAULT_PULL_TAGS_BRANCH
DEFAULT_PULL_TAGS_BRANCH,
DEFAULT_PATTERN,
} from './defaults'

const gitUrlParse = catchToSmth(gitParse, {})
Expand Down Expand Up @@ -132,6 +134,7 @@ export const resolveConfig = async (pluginConfig: TAnyMap, context: TContext, pa
msg = DEFAULT_MSG,
src = DEFAULT_SRC,
dst = DEFAULT_DST,
pattern = DEFAULT_PATTERN,
add,
dotfiles
} = opts
Expand All @@ -149,6 +152,7 @@ export const resolveConfig = async (pluginConfig: TAnyMap, context: TContext, pa
debug('ciBranch= %s', ciBranch)
debug('docsBranch= %s', docsBranch)
debug('pullTagsBranch= %s', pullTagsBranch)
debug('pattern = %s', pattern)

return {
src,
Expand All @@ -162,6 +166,7 @@ export const resolveConfig = async (pluginConfig: TAnyMap, context: TContext, pa
token,
add,
dotfiles,
pattern,
}
}

Expand Down
1 change: 1 addition & 0 deletions src/main/ts/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export const DEFAULT_DST = '.'
export const DEFAULT_MSG = 'docs updated <%= nextRelease.gitTag %>'
export const DEFAULT_ENTERPRISE = false
export const DEFAULT_PULL_TAGS_BRANCH = 'master'
export const DEFAULT_PATTERN = '**/*'
5 changes: 3 additions & 2 deletions src/main/ts/ghpages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ export const pullTags = (opts: IPushOpts): Promise<any> => {
* @private
*/
export const pushPages = (opts: IPushOpts) => new Promise((resolve, reject) => {
const { src, logger , repo, docsBranch, dst, message, add, dotfiles} = opts
const { src, logger , repo, docsBranch, dst, message, add, dotfiles, pattern } = opts
const ghpagesOpts: PublishOptions = {
repo,
branch: docsBranch,
dest: dst,
message,
add,
dotfiles,
src: pattern,
}

ghpagePublish(src, ghpagesOpts, (err?: any) => {
Expand All @@ -56,7 +57,7 @@ export const pushPages = (opts: IPushOpts) => new Promise((resolve, reject) => {
reject(err)

} else {
logger.log(`Docs published successfully, branch=${ghpagesOpts.branch}, src=${src}, dst=${ghpagesOpts.dest}`)
logger.log(`Docs published successfully, branch=${ghpagesOpts.branch}, src=${src}, pattern=${ghpagesOpts.src}, dst=${ghpagesOpts.dest}`)
resolve(OK)
}
})
Expand Down
1 change: 1 addition & 0 deletions src/main/ts/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface IGhpagesPluginConfig {
enterprise?: boolean,
dotfiles?: boolean
add?: boolean
pattern?: string,
}

export interface IPushOpts extends IGhpagesPluginConfig {
Expand Down
13 changes: 9 additions & 4 deletions src/test/ts/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
DEFAULT_MSG,
DEFAULT_PULL_TAGS_BRANCH,
DEFAULT_SRC,
DEFAULT_PATTERN,
// getRepo,
extractRepoDomain,
extractRepoName,
Expand Down Expand Up @@ -141,7 +142,8 @@ describe('config', () => {
msg: 'doc update',
token,
repo: `https://${token}@enterprise.com/org/repo.git`,
pullTagsBranch: 'dev'
pullTagsBranch: 'dev',
pattern: DEFAULT_PATTERN,
})
})

Expand Down Expand Up @@ -188,7 +190,8 @@ describe('config', () => {
msg: 'doc update',
token,
repo: `https://${token}@enterprise.com/org/repo.git`,
pullTagsBranch: 'foo'
pullTagsBranch: 'foo',
pattern: DEFAULT_PATTERN,
})
})

Expand Down Expand Up @@ -227,7 +230,8 @@ describe('config', () => {
src: DEFAULT_SRC,
token,
repo: repositoryUrl,
pullTagsBranch: DEFAULT_PULL_TAGS_BRANCH
pullTagsBranch: DEFAULT_PULL_TAGS_BRANCH,
pattern: DEFAULT_PATTERN,
})
})

Expand Down Expand Up @@ -328,7 +332,8 @@ describe('config', () => {
src: 'dist/web',
token: 'secure',
repo: `https://secure@github-enterprise-repo-url.com/foo/bar.git`,
pullTagsBranch: DEFAULT_PULL_TAGS_BRANCH
pullTagsBranch: DEFAULT_PULL_TAGS_BRANCH,
pattern: DEFAULT_PATTERN,
})
})
})
Expand Down
8 changes: 6 additions & 2 deletions src/test/ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
DEFAULT_MSG,
DEFAULT_PULL_TAGS_BRANCH,
DEFAULT_SRC,
DEFAULT_PATTERN,
PLUGIN_PATH
} from '../../main/ts'
import { getUrlFromPackage } from '../../main/ts/config'
Expand Down Expand Up @@ -84,6 +85,7 @@ describe('index', () => {
msg: DEFAULT_MSG,
dst: DEFAULT_DST,
src: DEFAULT_SRC,
pattern: DEFAULT_PATTERN,
enterprise: DEFAULT_ENTERPRISE,
repo: await getRepoUrl(pluginConfig, context, DEFAULT_ENTERPRISE),
token,
Expand Down Expand Up @@ -203,7 +205,8 @@ describe('index', () => {
repo: await getRepoUrl(pluginConfig, context, false),
branch: 'doc-branch',
message: 'docs updated v{{=it.nextRelease.gitTag}}',
dest: 'root'
dest: 'root',
src: DEFAULT_PATTERN,
}
const execaOpts = {
cwd,
Expand Down Expand Up @@ -275,7 +278,8 @@ describe('index', () => {
repo: await getRepoUrl(pluginConfig, context, false),
branch: DEFAULT_BRANCH,
message: DEFAULT_MSG,
dest: DEFAULT_DST
dest: DEFAULT_DST,
src: DEFAULT_PATTERN,
}
const expected = {
src: DOCS_ERR,
Expand Down

0 comments on commit 42954db

Please sign in to comment.