Skip to content

Commit

Permalink
Add release-it
Browse files Browse the repository at this point in the history
  • Loading branch information
KillianH committed Feb 9, 2025
1 parent 9a60117 commit 5d0abe2
Show file tree
Hide file tree
Showing 10 changed files with 3,434 additions and 3,042 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ module.exports = {
'**/build',
'**/public',
'**/.cache',
'/scripts/',
],
};
31 changes: 18 additions & 13 deletions .github/workflows/CD.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
name: release
run-name: "release [${{ inputs.type }}] by @${{ github.actor }}${{ github.event.inputs.dry == 'true' && ' (dry run)' || '' }}"
run-name: "${{ github.event.inputs.dry == 'true' && '[dry run] ' || '' }}release ${{ inputs.increment }}.${{ inputs.prerelease }} by @${{ github.actor }}"

permissions:
contents: write
id-token: write

on:
workflow_dispatch:
inputs:
type:
increment:
type: choice
description: Choose release
required: true
options:
- auto
- patch
- minor
- major
- bump
prerelease:
type: choice
description: Choose prerelease
required: true
options:
- stable
- alpha
- beta
default: auto
dry:
type: boolean
description: Dry release
Expand All @@ -35,12 +45,6 @@ jobs:
cache: 'yarn'

- run: yarn install --immutable
- name: 'Create env file'
run: |
echo "$ENV_FILE" > .env
cat .env
env:
ENV_FILE: ${{ secrets.ENV_FILE }}
- run: yarn build

- name: NPM config
Expand All @@ -57,6 +61,7 @@ jobs:
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TYPE_ARG: ${{ fromJSON('{"auto":"", "patch":"--patch", "minor":"--minor", "major":"--major", "beta":"--preRelease=beta --npm.tag=next", "alpha":"--preRelease=alpha --npm.tag=next"}')[github.event.inputs.type] }}
DRY_ARG: ${{ github.event.inputs.dry == 'true' && '--dry-run' || '' }}
run: yarn run release --ci --no-git.requireUpstream --verbose "$TYPE_ARG" "$DRY_ARG"
INCREMENT_ARG: ${{ fromJSON('{"bump":"", "patch":"--increment=patch", "minor":"--increment=minor", "major":"--increment=major"}')[github.event.inputs.increment] }}
PRERELEASE_ARG: ${{ fromJSON('{"stable":"", "beta":"--prerelease=beta", "alpha":"--prerelease=alpha"}')[github.event.inputs.prerelease] }}
DRY_ARG: ${{ github.event.inputs.dry == 'true' && '--dry' || '' }}
run: yarn release "$INCREMENT_ARG" "$PRERELEASE_ARG" "$DRY_ARG" --ci --verbose
22 changes: 12 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@
"license": "Apache-2.0",
"author": "",
"workspaces": [
"packages/*"
"packages/snap",
"packages/lib",
"packages/site"
],
"scripts": {
"build": "yarn workspaces foreach --parallel --topological --verbose run build",
"lint": "yarn lint:eslint && yarn lint:misc --check",
"lint:eslint": "eslint . --cache --ext js,jsx,ts,tsx",
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write",
"lint:misc": "prettier '**/*.json' '**/*.md' '!**/CHANGELOG.md' '**/*.yml' --ignore-path .gitignore",
"release": "node scripts/release.js",
"start": "yarn workspaces foreach --parallel --interlaced --verbose run start",
"test": "yarn workspace casper-manager run test"
},
Expand All @@ -32,8 +35,10 @@
"@metamask/eslint-config-jest": "^12.1.0",
"@metamask/eslint-config-nodejs": "^12.1.0",
"@metamask/eslint-config-typescript": "^12.1.0",
"@release-it/bumper": "^7.0.1",
"@typescript-eslint/eslint-plugin": "^5.42.1",
"@typescript-eslint/parser": "^5.42.1",
"ansi-colors": "^4.1.3",
"eslint": "^8.45.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "~2.26.0",
Expand All @@ -42,8 +47,11 @@
"eslint-plugin-n": "^15.7.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-promise": "^6.1.1",
"execa": "^9.5.2",
"minimist": "^1.2.8",
"prettier": "^2.7.1",
"prettier-plugin-packagejson": "^2.2.18",
"release-it": "18.1.2",
"sharp": "^0.32.6",
"typescript": "5.1.6"
},
Expand All @@ -58,22 +66,16 @@
}
},
"release-it": {
"plugins": {
"@release-it-plugins/workspaces": {
"workspaces": [
"packages/snap",
"packages/lib"
]
}
},
"git": {
"requireCleanWorkingDir": false,
"commitMessage": "chore: release v${version}"
},
"hooks": {
"after:bump": "yarn build"
},
"npm": false,
"npm": {
"publish": false
},
"github": {
"release": true
}
Expand Down
1 change: 1 addition & 0 deletions packages/lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"lint:style": "eslint --color 'src/**/*.{js,ts,tsx}'",
"lint:style:fix": "yarn run lint:style --fix",
"lint:types": "tsc --noEmit --pretty",
"release": "release-it",
"test": "exit 0"
},
"dependencies": {
Expand Down
6 changes: 6 additions & 0 deletions packages/site/.release-it.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"git": false,
"npm": {
"publish": false
}
}
5 changes: 3 additions & 2 deletions packages/site/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"name": "site",
"version": "1.0.1",
"version": "1.0.4",
"scripts": {
"lint": "eslint . --fix --ignore-path .gitignore",
"preview": "vite preview",
"release": "release-it",
"start": "vite --port 8080"
},
"dependencies": {
Expand All @@ -27,7 +28,7 @@
"eslint-plugin-vue": "9.32.0",
"globals": "^15.14.0",
"typescript": "5.7.2",
"vite": "6.0.5",
"vite": "6.0.9",
"vite-plugin-vuetify": "2.0.4",
"vue-tsc": "2.1.10"
}
Expand Down
1 change: 1 addition & 0 deletions packages/snap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write",
"lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' --ignore-path .gitignore",
"prepublishOnly": "mm-snap manifest",
"release": "release-it",
"serve": "mm-snap serve",
"start": "mm-snap watch",
"test": "jest"
Expand Down
2 changes: 1 addition & 1 deletion packages/snap/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/casper-ecosystem/casper-manager.git"
},
"source": {
"shasum": "YbnFU8C+L17qUPBGGYovaHVXX2BoS5ii0WJPDwQj1to=",
"shasum": "z19E3DGzYRpdaKMmOrrmMmiXlLtnPNgCRq+YrchW5XE=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
75 changes: 75 additions & 0 deletions scripts/release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { execa } from 'execa';
import minimist from 'minimist';
import process from 'node:process';
import c from 'ansi-colors';

(() => run(process.argv))();

async function run(argv) {
try {
const args = minimist(argv.slice(2));

const options = parseOptions(args);

await releasePackages(options);
await releaseGithub(options);
} catch {
process.exit(1);
}
}

function parseOptions(args) {
const options = [
args.dry ? '--dry-run' : '',
args.interactive ? '' : '--ci',
].filter((o) => o);

const invalidArgumentError = (message) => {
console.error(c.red(
`Invalid option: ${message}`,
));

process.exit(1);
};

if ([undefined, 'alpha', 'beta'].indexOf(args.prerelease) === -1) {
invalidArgumentError('"prerelease" must be set to "alpha" or "beta" when defined.');
}

if ([undefined, 'patch', 'minor', 'major'].indexOf(args.increment) === -1) {
invalidArgumentError('"increment" must be set to "patch", "minor" or "major" when defined.');
}

if (args.increment === undefined && args.prerelease === undefined) {
invalidArgumentError('either "increment" or "prerelease" must be set release a new version.');
}

if (args.prerelease !== undefined) {
return [
`--preRelease=${args.prerelease}`,
'--npm.tag=next',
...(args.increment !== undefined ? [`--increment=${args.increment}`] : []),
...options,
];
}

return [
`--increment=${args.increment}`,
...options,
];
}

async function releasePackages(options) {
await execa({ stdio: 'inherit' })`yarn ${[
'workspaces',
'foreach',
'run',
'release',
'--verbose',
...options,
]}`;
}

async function releaseGithub(options) {
await execa({ stdio: 'inherit' })`release-it ${options}`;
}
Loading

0 comments on commit 5d0abe2

Please sign in to comment.