Skip to content

Commit

Permalink
chore: some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
SgtPooki committed Oct 12, 2023
1 parent 567e1dd commit fc1563d
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 31 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ node_modules
package-lock.json
yarn.lock
.vscode
.envrc
.env
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodejs 18.17.0
88 changes: 87 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,96 @@
"project": true
}
},
"release": {
"branches": [
"main"
],
"plugins": [
[
"@semantic-release/commit-analyzer",
{
"preset": "conventionalcommits",
"releaseRules": [
{
"breaking": true,
"release": "patch"
},
{
"revert": true,
"release": "patch"
},
{
"type": "feat",
"release": "minor"
},
{
"type": "fix",
"release": "patch"
},
{
"type": "docs",
"release": "patch"
},
{
"type": "test",
"release": "patch"
},
{
"type": "deps",
"release": "patch"
},
{
"scope": "no-release",
"release": false
}
]
}
],
[
"@semantic-release/release-notes-generator",
{
"preset": "conventionalcommits",
"presetConfig": {
"types": [
{
"type": "feat",
"section": "Features"
},
{
"type": "fix",
"section": "Bug Fixes"
},
{
"type": "chore",
"section": "Trivial Changes"
},
{
"type": "docs",
"section": "Documentation"
},
{
"type": "deps",
"section": "Dependencies"
},
{
"type": "test",
"section": "Tests"
}
]
}
}
],
"@semantic-release/changelog",
"@semantic-release/npm",
"@semantic-release/github",
"@semantic-release/git"
]
},
"scripts": {
"clean": "aegir clean",
"lint": "aegir lint",
"build": "aegir build"
"build": "aegir build",
"release": "aegir release"
},
"devDependencies": {
"aegir": "^41.0.4",
Expand Down
9 changes: 5 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { registerPlugin, getPluginTypes } from 'release-please'
import { logger } from 'release-please/build/src/util/logger'
import { CustomPlugin } from './plugin'

export function init(...args: unknown[]) {
console.log('@ipfs-shipyard/release-please-ipfs-plugin init called with args: ', args)
export function init (...args: unknown[]): void {
logger.info('@ipfs-shipyard/release-please-ipfs-plugin init called with args: ', args)

registerPlugin('@ipfs-shipyard/release-please-ipfs-plugin', (options: any) => new CustomPlugin(options.github, options.targetBranch, options.repositoryConfig))
console.log('registered @ipfs-shipyard/release-please-ipfs-plugin')
console.log('currently registered plugins: ', getPluginTypes())
logger.info('registered @ipfs-shipyard/release-please-ipfs-plugin')
logger.info('currently registered plugins: ', getPluginTypes())
}

init()
21 changes: 10 additions & 11 deletions src/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
// import { type ConventionalCommit } from 'release-please/build/src/commit';
import { GitHub } from 'release-please/build/src/github';
import { type CandidateReleasePullRequest, type RepositoryConfig } from 'release-please/build/src/manifest';
import {ManifestPlugin} from 'release-please/build/src/plugin';
import { Update } from 'release-please/build/src/update';
import { UpdateVersionsInReadme } from './readme-updater';
import { type GitHub } from 'release-please/build/src/github'
import { type CandidateReleasePullRequest, type RepositoryConfig } from 'release-please/build/src/manifest'
import { ManifestPlugin } from 'release-please/build/src/plugin'
import { type Update } from 'release-please/build/src/update'
import { UpdateVersionsInReadme } from './readme-updater'

export class CustomPlugin extends ManifestPlugin {
constructor(
constructor (
github: GitHub,
targetBranch: string,
repositoryConfig: RepositoryConfig,
options: Record<string, unknown> = {}
) {
super(github, targetBranch, repositoryConfig);
super(github, targetBranch, repositoryConfig)

this.logger.info('ReadMeUpdater initialized with options: ', options);
this.logger.info('ReadMeUpdater initialized with options: ', options)
}

/**
* called by https://github.com/googleapis/release-please/blob/71dcc7b3b2df4bb3d3e0884b3f0bfb96700cb76a/src/manifest.ts#L757
*/
async run(pullRequestCandidates: CandidateReleasePullRequest[]): Promise<CandidateReleasePullRequest[]> {
async run (pullRequestCandidates: CandidateReleasePullRequest[]): Promise<CandidateReleasePullRequest[]> {
const releasePleaseCreatedPr = pullRequestCandidates.find((prCandidate) => {
return prCandidate.pullRequest.body.toString().includes('This PR was generated with [Release Please](https://github.com/googleapis/release-please)')

})
if (releasePleaseCreatedPr == null) {
this.logger.info('no release please created pr found')
Expand All @@ -46,7 +45,7 @@ export class CustomPlugin extends ManifestPlugin {
path: 'README.md',
createIfMissing: false,
updater: new UpdateVersionsInReadme({
version: pullRequest.version,
version: pullRequest.version
})
}
pullRequest.updates.push(updateVersionsInReadme)
Expand Down
23 changes: 10 additions & 13 deletions src/readme-updater.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
import { DefaultUpdater, type UpdateOptions } from 'release-please/build/src/updaters/default'
import { logger as defaultLogger, type Logger } from 'release-please/build/src/util/logger';
import { DefaultUpdater } from 'release-please/build/src/updaters/default'
import { logger as defaultLogger, type Logger } from 'release-please/build/src/util/logger'

export class UpdateVersionsInReadme extends DefaultUpdater {
constructor(options: UpdateOptions) {
super(options)
}
getRegex(oldVersion: string): RegExp {
return new RegExp(`((?:ipfs-desktop|IPFS-Desktop-Setup|ipfs-desktop/releases/tag|ipfs-desktop/releases/download)[-/]v?)${oldVersion}`, 'gm');
getRegex (oldVersion: string): RegExp {
return new RegExp(`((?:ipfs-desktop|IPFS-Desktop-Setup|ipfs-desktop/releases/tag|ipfs-desktop/releases/download)[-/]v?)${oldVersion}`, 'gm')
}

updateContent(content: string, logger: Logger = defaultLogger): string {
const newVersion = this.version.toString();
updateContent (content: string, logger: Logger = defaultLogger): string {
const newVersion = this.version.toString()
/**
* look for a string "like ipfs-desktop-0.31.0-mac.dmg" and get the version(e.g. 0.31.0) from it
* TODO: We need a better way to get the old version
* TODO: We need a way to accept a custom regex from the user.
*/

const match = content.match(/ipfs\/ipfs-desktop\/releases\/tag\/v(?<version>[^)]+)/)
const oldVersion = match?.groups?.version;
if (!oldVersion) {
throw new Error(`could not find old version in provided README.md content`);
const oldVersion = match?.groups?.version
if (oldVersion == null) {
throw new Error('could not find old version in provided README.md content')
}

const result = content.replace(this.getRegex(oldVersion), `$1${newVersion}`)
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"outDir": "dist",
"target": "ES6",
"module": "commonjs",
"verbatimModuleSyntax": false,
"verbatimModuleSyntax": false
},
"include": [
"src",
"src"
]
}

0 comments on commit fc1563d

Please sign in to comment.