Skip to content

Commit

Permalink
build(root): add alpha release workflow
Browse files Browse the repository at this point in the history
Ticket: BG-60558
  • Loading branch information
byhow committed Oct 31, 2022
1 parent 3d87270 commit dfa3def
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 15 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/alpha-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# @see beta-publish.yml
# The same workflow as the above except some input args. Replicated for separation of concerns
name: Alpha Release for Development
on:
workflow_dispatch:
# push:
# branches:
# - master

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}

jobs:
publish:
name: Publish Alpha Release
runs-on: ubuntu-latest
if: github.ref != 'refs/heads/master' # only publish changes if on feature branches
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 14

- name: Install BitGoJS
run: yarn install --with-frozen-lockfile

- name: Configure Git & NPM
run: |
git config --global user.name 'Git bot'
git config --global user.email '[email protected]'
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
git checkout -b alpha-$(git rev-parse --short HEAD)
echo "email=${{ secrets.BETA_EMAIL }}" > .npmrc
echo "@bitgo-beta:registry=https://registry.npmjs.org" >> .npmrc
echo "//registry.npmjs.org/:_authToken=${{ secrets.BETA_TOKEN }}" >> .npmrc
echo "//registry.npmjs.org/:always-auth=true" >> .npmrc
- name: Prepare Alpha
run: |
rm -rfd ./modules/web-demo
rm -rfd ./modules/express
npx ts-node ./scripts/prepare-release.ts alpha
- name: Rebuild Alpha
run: yarn

- name: Commit Local Changes
run: git commit -am "Auto updated alpha branch" --no-verify || echo "No changes to commit"

- name: Lerna Publish
run: yarn lerna publish from-package --preid alpha --dist-tag alpha --force-publish --yes --loglevel silly

- name: Verify Publish
run: npx ts-node ./scripts/verify-release.ts alpha
9 changes: 7 additions & 2 deletions .github/workflows/beta-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ on:
# push:
# branches:
# - master

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}

jobs:
publish:
name: Publish Beta Release
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master' # only publish changes if on master
steps:
- name: Checkout repository
uses: actions/checkout@v2
Expand Down Expand Up @@ -35,7 +40,7 @@ jobs:
run: |
rm -rfd ./modules/web-demo
rm -rfd ./modules/express
npx ts-node ./scripts/prepare-beta.ts
npx ts-node ./scripts/prepare-release.ts
- name: Rebuild Beta
run: yarn
Expand All @@ -47,4 +52,4 @@ jobs:
run: yarn lerna publish from-package --preid beta --dist-tag beta --force-publish --yes --loglevel silly

- name: Verify Publish
run: npx ts-node ./scripts/verify-beta.ts
run: npx ts-node ./scripts/verify-release.ts
17 changes: 11 additions & 6 deletions scripts/prepare-beta.ts → scripts/prepare-release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,19 @@ const replaceBitGoPackageScope = () => {
);
};

const incrementVersions = async () => {
/**
* increment the version based on the preid. default to `beta`
*
* @param {String | undefined} preid
*/
const incrementVersions = async (preid: string = 'beta') => {
for (let i = 0; i < lernaModuleLocations.length; i++) {
try {
const modulePath = lernaModuleLocations[i];
const json = JSON.parse(readFileSync(path.join(modulePath, 'package.json'), { encoding: 'utf-8' }));
const tags = await getDistTags(json.name);
if (tags.beta) {
const next = inc(tags.beta, 'prerelease', undefined, 'beta');
if (tags[preid]) {
const next = inc(tags[preid], 'prerelease', undefined, preid);
console.log(`Setting next version for ${json.name} to ${next}`);
json.version = next;
writeFileSync(
Expand Down Expand Up @@ -161,12 +166,12 @@ const getArgs = () => {
console.log(`Preparing to re-target to ${TARGET_SCOPE}`);
};

const main = async () => {
const main = async (preid?: string) => {
getArgs();
await getLernaModules();
replacePackageScopes();
replaceBitGoPackageScope();
await incrementVersions();
await incrementVersions(preid);
if (filesChanged) {
console.log(`Successfully re-targeted ${filesChanged} files.`);
process.exit(0);
Expand All @@ -176,4 +181,4 @@ const main = async () => {
}
};

main();
main(process.argv.slice(2)[0]);
15 changes: 8 additions & 7 deletions scripts/verify-beta.ts → scripts/verify-release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ const getDistTags = async (packageName: string): Promise<Record<string, string>>
};


const verifyPackage = async (dir: string): Promise<boolean> => {
const verifyPackage = async (dir: string, preid: string = 'beta'): Promise<boolean> => {
const cwd = dir;
const json = JSON.parse(readFileSync(path.join(cwd, 'package.json'), { encoding: 'utf-8' }));
if (json.private) {
return true;
}
const distTags = await getDistTags(json.name);
if (json.version !== distTags['beta']) {
console.log(`${json.name} missing. Expected ${json.version}, latest is ${distTags['beta']}`);
const { stdout, exitCode } = await execa('npm', ['publish', '--tag', 'beta'], { cwd });
if (json.version !== distTags[preid]) {
console.log(`${json.name} missing. Expected ${json.version}, latest is ${distTags[preid]}`);
const { stdout, exitCode } = await execa('npm', ['publish', '--tag', preid], { cwd });
console.log(stdout);
return exitCode === 0;
} else {
Expand All @@ -67,15 +67,16 @@ const verifyPackage = async (dir: string): Promise<boolean> => {
return true;
};

const verify = async () => {
const verify = async (preid?: string) => {
await getLernaModules();
for (let i = 0; i < lernaModuleLocations.length; i++) {
const dir = lernaModuleLocations[i];
if (!await verifyPackage(dir)) {
if (!await verifyPackage(dir, preid)) {
console.error('Failed to verify outstanding packages.');
return;
}
}
};

verify();
// e.g. for alpha releases: `npx ts-node ./scripts/verify-beta.ts alpha`
verify(process.argv.slice(2)[0]);

0 comments on commit dfa3def

Please sign in to comment.