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

release test 1 #6

Merged
merged 14 commits into from
Nov 7, 2023
27 changes: 27 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"projectName": "does-it-throw",
"projectOwner": "michaelangeloio",
"files": [
"README.md"
],
"imageSize": 100,
"contributors": [
{
"login": "michaelangeloio",
"name": "Michael Angelo Rivera",
"avatar_url": "https://avatars.githubusercontent.com/u/55844504?v=4",
"profile": "https://github.com/michaelangeloio",
"contributions": [
"code",
"infra",
"doc"
]
}
],
"repoType": "github",
"contributorsPerLine": 7,
"repoHost": "https://github.com",
"commitConvention": "angular",
"skipCi": true,
"commitType": "docs"
}
2 changes: 1 addition & 1 deletion .autorc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"plugins": [
"crates",
".github/auto/crate-plugin.ts",
"all-contributors",
"conventional-commits",
"first-time-contributor",
Expand Down
135 changes: 135 additions & 0 deletions .github/auto/crate-plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import { Auto, execPromise, IPlugin, SEMVER } from '@auto-it/core'
import { access, readFile, writeFile } from 'fs/promises'
import isCi from 'is-ci'
import { join } from 'path'
import { inc, ReleaseType } from 'semver'
import { parse as parseToml } from 'toml'
import userHome from 'user-home'

/** Get the parsed cargo.toml for the crate */
export const getCargoConfig = async () => {
const content = (await readFile(join(process.cwd(), 'Cargo.toml'))).toString()
return { toml: parseToml(content), content }
}

/** Get the credentials for publishing to crates.io */
export async function checkForCreds() {
if (isCi) {
return process.env.CARGO_REGISTRY_TOKEN
}

const credsFile = join(userHome, '.cargo', 'credentials')
try {
await access(credsFile)
return true
} catch (error) {
return false
}
}

export async function getWorkspaceMembers(): Promise<
{
packagePath: string
packageToml: any
packageContent: string
}[]
> {
const { toml } = await getCargoConfig()
return toml.workspace.members.map(async (member: string) => {
const packagePath = join(process.cwd(), member, 'Cargo.toml')
const packageContent = (await readFile(packagePath)).toString()
const packageToml = parseToml(packageContent.toString())
return {
packagePath,
packageToml,
packageContent,
}
})
}

/** Bump the version in cargo.toml */
export async function bumpVersions(bumpBy: SEMVER) {
const workspaceMembers = await getWorkspaceMembers()
const promises = workspaceMembers.map(async (member) => {
const { packagePath, packageContent, packageToml } = member
const versionOld = packageToml.package.version
const versionNew = inc(versionOld, bumpBy as ReleaseType)

if (!versionNew) {
throw new Error(`Could not increment previous version: ${versionOld}`)
}

const replaceOld = `version = "${versionOld}"`
const replaceNew = `version = "${versionNew}"`
const contentNew = packageContent.replace(replaceOld, replaceNew)
await writeFile(packagePath, contentNew)
return versionNew
})
return await Promise.all(promises)
}

/** Deploy Rust crates */
export default class CratesPlugin implements IPlugin {
/** The name of the plugin */
name = 'crates-plugin'

/** Tap into auto plugin points. */
apply(auto: Auto) {
auto.hooks.beforeShipIt.tap(this.name, () => {
if (!checkForCreds()) {
throw new Error('Cargo token is needed for the Crates plugin!')
}
})

auto.hooks.getAuthor.tapPromise(this.name, async () => {
const { toml } = await getCargoConfig()
const authors = toml.workspace.authors
auto.logger.log.info(`Crate authors: ${authors}`)
return authors
})

auto.hooks.getPreviousVersion.tapPromise(this.name, async () => {
const { toml } = await getCargoConfig()
const version = auto.prefixRelease(toml.workspace.version)
auto.logger.log.info(`Crate version: ${version}`)
return version
})

auto.hooks.version.tapPromise(this.name, async ({ bump, dryRun, quiet }) => {
const newVersions = await bumpVersions(bump)
newVersions.forEach(async (versionNew) => {
if (dryRun) {
if (quiet) {
console.log(versionNew)
} else {
auto.logger.log.info(`Would have published: ${versionNew}`)
}

return
}

auto.logger.log.info(`Bumped version to: ${versionNew}`)
})
auto.logger.log.info('Building to update Cargo.lock')
await execPromise('cargo', ['build'])
auto.logger.verbose.info('Committing files')
await execPromise('git', ['add', 'Cargo.toml', 'Cargo.lock'])
await execPromise('git', ['commit', '-m', `'Bump version to: ${newVersions[0]} [skip ci]'`, '--no-verify'])
auto.logger.log.info('Create git commit for new version')
})

auto.hooks.publish.tapPromise(this.name, async () => {
const workspaceMembers = await getWorkspaceMembers()
const promises = workspaceMembers.map(async (member) => {
const { packageToml } = member
auto.logger.log.info('Publishing via cargo')
await execPromise('cargo', ['publish', packageToml.name])
auto.logger.log.info('Publish complete')
auto.logger.log.info('Pushing local git changes to origin remote')
await execPromise('git', ['push', '--follow-tags', '--set-upstream', auto.remote, auto.baseBranch])
auto.logger.log.info('Push complete')
})
await Promise.all(promises)
})
}
}
54 changes: 54 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# (Mon Nov 06 2023)

:tada: This release contains work from a new contributor! :tada:

Thank you, Michael Angelo Rivera ([@michaelangeloio](https://github.com/michaelangeloio)), for all your work!

#### 🐛 Bug Fix

- save work ([@michaelangeloio](https://github.com/michaelangeloio))
- add files ([@michaelangeloio](https://github.com/michaelangeloio))
- 0.1.1 ([@michaelangeloio](https://github.com/michaelangeloio))
- release test 1 ([@michaelangeloio](https://github.com/michaelangeloio))
- Release setup 2 [#5](https://github.com/michaelangeloio/does-it-throw/pull/5) ([@michaelangeloio](https://github.com/michaelangeloio))
- release setup [#4](https://github.com/michaelangeloio/does-it-throw/pull/4) ([@michaelangeloio](https://github.com/michaelangeloio))
- more tests [#3](https://github.com/michaelangeloio/does-it-throw/pull/3) ([@michaelangeloio](https://github.com/michaelangeloio))
- add tests [#2](https://github.com/michaelangeloio/does-it-throw/pull/2) ([@michaelangeloio](https://github.com/michaelangeloio))

#### ⚠️ Pushed to `main`

- remove codecov for now ([email protected])
- nit ([email protected])
- code cov ([email protected])
- make ci a little more secure ([email protected])
- wasm pack ([email protected])
- rename job ([email protected])
- more ci ([email protected])
- ci setup ([email protected])
- more tests ([email protected])
- adding tests, minor fix ([email protected])
- move to beta version ([email protected])
- constructor logic ([email protected])
- use hash set in extension ([email protected])
- check in code ([email protected])
- add arrow expression condition ([email protected])
- update build settings ([email protected])
- make it packageable ([email protected])
- save work ([email protected])
- upgrade deps ([email protected])
- add relative imports ([email protected])
- find methods and funcs that call ([email protected])
- save ([email protected])
- save work, figuring out proper wasm ([email protected])
- add sample file ([email protected])
- update development.md ([email protected])
- getting stuff started ([email protected])
- does it throw? ([email protected])
- first commit ([email protected])

#### Authors: 2

- Michael Angelo Rivera ([@michaelangeloio](https://github.com/michaelangeloio))
- michaelangrivera ([email protected])

---
Loading
Loading