Skip to content

Commit

Permalink
clean tags script & changeset commit
Browse files Browse the repository at this point in the history
  • Loading branch information
nohaapav committed Feb 18, 2024
1 parent 90b0b02 commit 845f8d4
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 4 deletions.
3 changes: 1 addition & 2 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": ["@changesets/changelog-github", { "repo": "@galacticcouncil/sdk" }],
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"commit": false,
"fixed": [],
"linked": [],
Expand Down
46 changes: 46 additions & 0 deletions .changeset/version.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import getReleasePlan from '@changesets/get-release-plan';
import applyReleasePlan from '@changesets/apply-release-plan';
import { read } from '@changesets/config';
import * as git from '@changesets/git';
import { getPackages } from '@manypkg/get-packages';
import { exec } from 'child_process';
import outdent from 'outdent';

const cwd = process.cwd();
const packages = await getPackages(cwd);
const config = await read(cwd, packages);

const releasePlan = await getReleasePlan(cwd, undefined);
const releases = releasePlan.releases.filter(
(release) => release.type !== 'none'
);
const releasesLines = releases
.map((release) => ` ${release.name}@${release.newVersion}`)
.join('\n');
const releaseMessage = outdent`
RELEASING: Releasing ${releases.length} package(s)
Releases:
${releasesLines}
`;

async function sh(cmd) {
return new Promise(function (resolve, reject) {
exec(cmd, (err, stdout, stderr) => {
if (err) {
reject(err);
} else {
resolve({ stdout, stderr });
}
});
});
}

await applyReleasePlan(releasePlan, packages, config, false);

const { stdout } = await sh('npm i --package-lock-only');
console.log(stdout);

await git.add('.', cwd);
await git.commit(releaseMessage, cwd);
console.log(releaseMessage);
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
"link": "turbo run link",
"test": "turbo run test",
"changeset": "changeset",
"changeset:version": "changeset version && npm i --package-lock-only",
"changeset:version": "node ./.changeset/version.mjs",
"changeset:publish": "npm run build && changeset publish",
"release": "git push --follow-tags"
"changeset:release": "node ./scripts/release-tags.sh"
},
"devDependencies": {
"@changesets/changelog-github": "^0.4.8",
Expand Down
16 changes: 16 additions & 0 deletions scripts/release-tags.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

TAGS=$(git tag --points-at HEAD)

for tag in $TAGS; do
if [[ $tag == *.0 ]]; then
# Keep major & minor versions (publish)
continue;
else
# Delete patch version
git tag -d $tag
fi
done

# Push tags
git push --follow-tags

0 comments on commit 845f8d4

Please sign in to comment.