Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test release 13 #18

Merged
merged 2 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .autorc
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"plugins": [
".github/auto/crate-plugin.ts",
".github/auto/vscode-plugin.ts",
"all-contributors",
"conventional-commits",
"first-time-contributor",
"released",
"vscode"
"released"
],
"owner": "michaelangeloio",
"repo": "does-it-throw",
Expand Down
118 changes: 118 additions & 0 deletions .github/auto/vscode-plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import { Auto, IPlugin, execPromise, validatePluginConfiguration } from '@auto-it/core'
import { getAuthor, getRepo, loadPackageJson } from '@auto-it/package-json-utils'
import { publish as vscePublish } from '@vscode/vsce'
import * as t from 'io-ts'
import { ReleaseType, inc } from 'semver'

/** Get the current version from the package.json */
const getVersion = async () => {
const { version } = await loadPackageJson()

if (version) {
return version
}

return '0.0.0'
}

const pluginOptions = t.partial({
/** Prepend all relative links in README.md with this url */
baseContentUrl: t.string,
/** Prepend all relative image links in README.md with this url */
baseImagesUrl: t.string,
})

export type IVscodePluginOptions = t.TypeOf<typeof pluginOptions>

/** Publish an vscode extension */
export default class VscodePlugin implements IPlugin {
/** The name of the plugin */
name = 'vscode'

/** The options of the plugin */
readonly options: IVscodePluginOptions

/** Initialize the plugin with it's options */
constructor(options: IVscodePluginOptions = {}) {
this.options = options
}

/** Tap into auto plugin points. */
apply(auto: Auto) {
const isQuiet = auto.logger.logLevel === 'quiet'
const isVerbose = auto.logger.logLevel === 'verbose' || auto.logger.logLevel === 'veryVerbose'
const verboseArgs = isQuiet ? ['--loglevel', 'silent'] : isVerbose ? ['--loglevel', 'silly'] : []

auto.hooks.validateConfig.tapPromise(this.name, async (name, options) => {
// If it's a string thats valid config
if (name === this.name && typeof options !== 'string') {
return validatePluginConfiguration(this.name, pluginOptions, options)
}
})

auto.hooks.getAuthor.tapPromise(this.name, async () => {
auto.logger.verbose.info(`${this.name}: Getting repo information from package.json`)

const author = await getAuthor()

if (author) {
return author
}
})

auto.hooks.getRepository.tapPromise(this.name, async () => {
auto.logger.verbose.info(`${this.name}: getting repo information from package.json`)
const repo = await getRepo()

if (repo) {
return repo
}
})

auto.hooks.getPreviousVersion.tapPromise(this.name, async () => {
return auto.prefixRelease(await getVersion())
})

auto.hooks.version.tapPromise(this.name, async ({ bump, dryRun, quiet }) => {
const newVersion = inc(await getVersion(), bump as ReleaseType) as string

if (dryRun) {
if (quiet) {
console.log(newVersion)
} else {
auto.logger.log.info(`Would have published: ${newVersion}`)
}

return
}

await execPromise('git', ['add', '.'])

await execPromise('git', ['commit', '-m', 'chore: update version [skip ci]'])

await execPromise('npm', [
'version',
newVersion,
'--no-commit-hooks',
'-m',
'"Bump version to: %s [skip ci]"',
...verboseArgs,
])
auto.logger.verbose.info('Successfully versioned repo')
})

auto.hooks.publish.tapPromise(this.name, async () => {
auto.logger.log.info('Pushing new tag to GitHub')
const version = await getVersion()

await execPromise('git', ['push', '--follow-tags', '--set-upstream', auto.remote, auto.baseBranch])

await vscePublish({
version,
pat: process.env.VSCE_TOKEN,
baseContentUrl: this.options.baseContentUrl,
baseImagesUrl: this.options.baseImagesUrl,
})
})
}
}
Loading
Loading