Skip to content

Commit 6e15f07

Browse files
committed
Split beta release into separate script/workflow (#480)
1 parent 353bc2e commit 6e15f07

File tree

3 files changed

+154
-1
lines changed

3 files changed

+154
-1
lines changed

.github/workflows/release-beta.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Release Beta
2+
3+
on:
4+
push:
5+
branches:
6+
- v2.0.0
7+
8+
env:
9+
FORCE_COLOR: true
10+
11+
jobs:
12+
release:
13+
name: Release Beta
14+
runs-on: ubuntu-latest
15+
if: ${{ github.repository == 'PaloAltoNetworks/docusaurus-openapi-docs' }}
16+
steps:
17+
- uses: actions/checkout@v3
18+
with:
19+
fetch-depth: 0
20+
- run: |
21+
git config user.name "github-actions[bot]"
22+
git config user.email "github-actions[bot]@users.noreply.github.com"
23+
- uses: actions/setup-node@v2
24+
with:
25+
node-version: "*"
26+
registry-url: "https://registry.npmjs.org"
27+
- name: Release Beta
28+
run: npx ts-node --transpile-only scripts/publish-beta.ts
29+
env:
30+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31+
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}

.github/workflows/release.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ on:
44
push:
55
branches:
66
- main
7-
- v2.0.0
87

98
env:
109
FORCE_COLOR: true

scripts/publish-beta.ts

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#!/usr/bin/env ts-node
2+
/* ============================================================================
3+
* Copyright (c) Palo Alto Networks
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
* ========================================================================== */
8+
9+
import { execSync } from "child_process";
10+
import fs from "fs";
11+
import path from "path";
12+
13+
import { version } from "../lerna.json";
14+
import { createDryRun } from "./utils/dry-run";
15+
import { getOutput } from "./utils/get-output";
16+
import { printBanner } from "./utils/print-utils";
17+
18+
const ORG = "PaloAltoNetworks";
19+
const REPO = "docusaurus-openapi-docs";
20+
let REPO_ROOT = undefined;
21+
22+
// Makes the script crash on unhandled rejections instead of silently
23+
// ignoring them. In the future, promise rejections that are not handled will
24+
// terminate the Node.js process with a non-zero exit code.
25+
process.on("unhandledRejection", (err) => {
26+
throw err;
27+
});
28+
29+
const safeExec = createDryRun(execSync);
30+
const safeRmdir = createDryRun(fs.rmSync);
31+
const safeMkdir = createDryRun(fs.mkdirSync);
32+
33+
function getGitUserName() {
34+
return getOutput("git config user.name");
35+
}
36+
37+
function getGitUserEmail() {
38+
return getOutput("git config user.email");
39+
}
40+
41+
function ensureCleanDir(path: string) {
42+
if (fs.existsSync(path)) {
43+
safeRmdir(path, { recursive: true });
44+
}
45+
safeMkdir(path, { recursive: true });
46+
}
47+
48+
function checkoutCode() {
49+
printBanner("Retrieving source code");
50+
51+
const BUILD_PATH = "build";
52+
ensureCleanDir(BUILD_PATH);
53+
54+
safeExec(`git clone [email protected]:${ORG}/${REPO}.git ${REPO}`, {
55+
cwd: BUILD_PATH,
56+
});
57+
58+
REPO_ROOT = path.join(BUILD_PATH, REPO);
59+
}
60+
61+
function configureGit() {
62+
const gitUserName = getGitUserName();
63+
const gitUserEmail = getGitUserEmail();
64+
safeExec(`git config user.name ${gitUserName}`, {
65+
cwd: REPO_ROOT,
66+
});
67+
safeExec(`git config user.email ${gitUserEmail}`, {
68+
cwd: REPO_ROOT,
69+
});
70+
}
71+
72+
function buildAndPublish() {
73+
safeExec(`yarn install --frozen-lockfile`, {
74+
cwd: REPO_ROOT,
75+
stdio: "ignore",
76+
});
77+
78+
printBanner("Building Packages");
79+
80+
safeExec(`yarn lerna run build --no-private`, {
81+
cwd: REPO_ROOT,
82+
});
83+
84+
printBanner("Publishing Packages");
85+
86+
// --no-verify-access enables lerna publish to work in ci with access token.
87+
safeExec(
88+
`lerna publish --yes from-package --no-verify-access --dist-tag beta`,
89+
{
90+
cwd: REPO_ROOT,
91+
}
92+
);
93+
}
94+
95+
function tag() {
96+
const tag = `v${version}`;
97+
const message = `Version ${version}`;
98+
safeExec(`git tag -a ${tag} -m "${message}"`, {
99+
cwd: REPO_ROOT,
100+
});
101+
safeExec(`git push origin ${tag}`, {
102+
cwd: REPO_ROOT,
103+
});
104+
}
105+
106+
function versions() {
107+
return getOutput(`git tag --list 'v*'`).split("\n");
108+
}
109+
110+
function main() {
111+
if (versions().includes(`v${version}`)) {
112+
console.log(`\x1b[33mSKIPPING: Version ${version} already exists.\x1b[0m`);
113+
return;
114+
}
115+
if (!process.env.CI) {
116+
checkoutCode();
117+
}
118+
configureGit();
119+
buildAndPublish();
120+
tag();
121+
}
122+
123+
main();

0 commit comments

Comments
 (0)