Skip to content

Commit

Permalink
support ci, beta releases
Browse files Browse the repository at this point in the history
  • Loading branch information
nohaapav committed Sep 16, 2024
1 parent 0a69727 commit 0b5bd1a
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 61 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/snapshot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Create SDK Snapshot

on:
pull_request:
branches: ['master']

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: 🤘 Checkout
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20.x
cache: 'npm'

- name: 🔐 Authenticate with NPM
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc

- name: 🧩 Install dependencies
run: npm ci --ignore-scripts

- name: 🖊️ Bump version
run: npm run changeset:snapshot -- --pr $PR --sha $COMMIT_SHA
env:
PR: ${{ github.event.pull_request.number }}
COMMIT_SHA: ${{ github.event.pull_request.head.sha }}

- name: 🛠️ Build SDK
run: npm run build

- name: 🚀 Publish snapshot
run: npm run changeset -- publish --no-git-tag --snapshot --tag beta
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
"link": "turbo run link",
"changeset": "changeset",
"changeset:version": "node ./scripts/changeset-version.mjs",
"changeset:snapshot": "node ./scripts/changeset-snapshot.mjs",
"prerelease": "npm run build",
"release": "changeset publish",
"release:beta": "npm run release -- --no-git-tag --snapshot --tag beta",
"postrelease": "bash ./scripts/changeset-push.sh"
},
"devDependencies": {
Expand Down
38 changes: 38 additions & 0 deletions scripts/changeset-snapshot.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import applyReleasePlan from '@changesets/apply-release-plan';
import getReleasePlan from '@changesets/get-release-plan';

import { read } from '@changesets/config';
import { getPackages } from '@manypkg/get-packages';

import { parseArgs } from './common.mjs';

const main = async () => {
const cwd = process.cwd();
const args = process.argv.slice(2);
const params = parseArgs(args);

const packages = await getPackages(cwd);
const config = await read(cwd, packages);
const releaseConfig = {
...config,
commit: false,
};

const releasePlan = await getReleasePlan(cwd, undefined);
const pullRequest = params['pr'];
const commitSha = params['sha'];

releasePlan.releases.map((r) => {
r.newVersion = [
r.newVersion,
'pr' + pullRequest,
commitSha.substring(0, 7),
].join('-');
});
await applyReleasePlan(releasePlan, packages, releaseConfig, true);
};

main()
.then(() => console.log('Snapshot version bump ✅'))
.catch(console.error)
.finally(() => process.exit(0));
18 changes: 16 additions & 2 deletions scripts/common.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { exec } from 'child_process';

export async function sh(cmd) {
const PARAM_PREFIX = '--';

export const sh = async (cmd) => {
return new Promise(function (resolve, reject) {
exec(cmd, (err, stdout, stderr) => {
if (err) {
Expand All @@ -10,4 +12,16 @@ export async function sh(cmd) {
}
});
});
}
};

export const parseArgs = (args) => {
const parsedArgs = {};

args.forEach((arg, i) => {
if (arg.startsWith(PARAM_PREFIX)) {
const key = arg.replace(PARAM_PREFIX, '');
parsedArgs[key] = args[++i];
}
});
return parsedArgs;
};
58 changes: 0 additions & 58 deletions scripts/update-dev-version.mjs

This file was deleted.

0 comments on commit 0b5bd1a

Please sign in to comment.