Skip to content

Commit 5519ea8

Browse files
committed
release workflow
1 parent f4542ce commit 5519ea8

16 files changed

Lines changed: 1280 additions & 10 deletions

File tree

.github/workflows/release.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches:
6+
- release
7+
8+
jobs:
9+
release:
10+
name: Release Package
11+
runs-on: ubuntu-latest
12+
environment: release
13+
permissions:
14+
contents: read
15+
id-token: write
16+
steps:
17+
- uses: actions/checkout@v6
18+
- name: Use PNPM
19+
uses: pnpm/action-setup@v6
20+
with:
21+
version: 11
22+
cache: true
23+
- name: Use Node.js ${{ matrix.node-version }}
24+
uses: actions/setup-node@v6
25+
with:
26+
node-version: '24'
27+
cache: 'pnpm'
28+
- name: Install dependencies
29+
run: pnpm install --frozen-lockfile
30+
- name: Code check
31+
run: npm run code-check
32+
- name: Build Package
33+
run: |
34+
npm run package-builder
35+
- name: Release to npm registry
36+
run: |
37+
node ./scripts/release.mjs

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ expo-env.d.ts
3333
# Package
3434
/package/android/build/
3535
/package/lib/
36-
## generated by prepack-package script
36+
37+
# +++++ generated by package-builder script +++++
3738
/package/LICENSE
39+
/package/README.md
40+
# ----- generated by package-builder script -----
3841

3942
tsconfig.tsbuildinfo

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 RakaDoank
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

package-builder/bob.config.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const targetPath = "../package"
2+
3+
module.exports = {
4+
source: `${targetPath}/src`,
5+
output: `${targetPath}/lib`,
6+
targets: [
7+
[
8+
"commonjs",
9+
{
10+
"esm": true,
11+
},
12+
],
13+
[
14+
"module",
15+
{
16+
"esm": true,
17+
},
18+
],
19+
[
20+
"typescript",
21+
{
22+
project: `${targetPath}/tsconfig.json`,
23+
tsc: "../node_modules/typescript/bin/tsc",
24+
},
25+
],
26+
],
27+
}

package-builder/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "package-builder",
3+
"private": true,
4+
"version": "0.0.1",
5+
"bin": "./scripts/bin.mjs",
6+
"devDependencies": {
7+
"react-native-builder-bob": "0.41.0",
8+
"semver": "7.8.0"
9+
}
10+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import node_fs from "node:fs"
2+
import node_path from "node:path"
3+
4+
import SemverValid from "semver/functions/valid.js"
5+
6+
import ReactNativeEchoPackageJson from "../../package/package.json" with { type: "json" }
7+
8+
/**
9+
* @param {string} rootDir
10+
*/
11+
export async function prepack(
12+
rootDir,
13+
) {
14+
15+
{
16+
// Replace placeholder version at the
17+
// /react-native-echo/package/src/_internal/const/version.ts
18+
19+
const libraryVersion = SemverValid(ReactNativeEchoPackageJson.version)
20+
21+
if(!libraryVersion) {
22+
throw new TypeError("Library version is not a valid semver")
23+
}
24+
25+
const filePath = node_path.join(rootDir, "package", "src", "_internal", "const", "echo", "version.ts")
26+
27+
if(!node_fs.existsSync(filePath)) {
28+
throw new Error(`${filePath} doesn't exist`)
29+
}
30+
31+
let fileStr = node_fs.readFileSync(filePath).toString()
32+
fileStr = fileStr.replace(/(export const VERSION = )("X\.X\.X")/, `$1"${libraryVersion}"`)
33+
34+
node_fs.writeFileSync(filePath, fileStr, { encoding: "utf8" })
35+
}
36+
37+
{
38+
// Copy files
39+
40+
const
41+
/**
42+
* @type {{
43+
* src: string,
44+
* dest: string,
45+
* }[]}
46+
*/
47+
filesToCopy =
48+
[
49+
{
50+
src: node_path.join(rootDir, "LICENSE"),
51+
dest: node_path.join(rootDir, "package", "LICENSE"),
52+
},
53+
{
54+
src: node_path.join(rootDir, "README.md"),
55+
dest: node_path.join(rootDir, "package", "README.md"),
56+
},
57+
]
58+
59+
await Promise.all(
60+
filesToCopy.map(file => {
61+
return node_fs.promises.cp(
62+
file.src,
63+
file.dest,
64+
)
65+
}),
66+
)
67+
}
68+
69+
}
70+

package-builder/scripts/bin.mjs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env node
2+
3+
import node_childProcess from "node:child_process"
4+
import node_fs from "node:fs"
5+
import node_path from "node:path"
6+
7+
import {
8+
prepack,
9+
} from "./_prepack.mjs"
10+
11+
const
12+
rootDir =
13+
node_path.join(import.meta.dirname, "..", "..")
14+
15+
try {
16+
await prepack(rootDir)
17+
18+
const libPath = node_path.join(rootDir, "package", "lib")
19+
20+
if(node_fs.existsSync(libPath)) {
21+
node_fs.rmSync(
22+
libPath,
23+
{
24+
recursive: true,
25+
force: true,
26+
},
27+
)
28+
}
29+
30+
node_childProcess.execSync(
31+
"npx bob build",
32+
{
33+
cwd: node_path.join(rootDir, "package-builder"),
34+
stdio: "inherit",
35+
},
36+
)
37+
38+
} catch(err) {
39+
40+
throw new Error(`/package-builder/scripts/bin.mjs :: ${err instanceof Error ? `[${err.name}] :: ${err.message}` : "Unknown error"}`)
41+
42+
}

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
"private": true,
44
"version": "0.0.0",
55
"description": "Embed a HTTP server to your React Native app",
6+
"scripts": {
7+
"code-check": "npm run type-check && npm run lint",
8+
"lint": "eslint .",
9+
"package-builder": "package-builder",
10+
"type-check": "tsc --build"
11+
},
612
"devDependencies": {
713
"@eslint/compat": "2.1.0",
814
"@react-native/eslint-config": "0.83.6",
@@ -19,7 +25,7 @@
1925
"eslint-plugin-react-hooks": "7.1.1",
2026
"eslint-plugin-react-native": "^5.0.0",
2127
"globals": "17.6.0",
22-
"semver": "7.8.0",
28+
"package-builder": "workspace:*",
2329
"typescript": "6.0.3",
2430
"typescript-eslint": "8.59.2"
2531
},

package/package.json

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "react-native-echo",
3-
"version": "0.0.1",
4-
"description": "Please embed a server of HTTP in React Native app",
3+
"version": "0.0.1-beta.1",
4+
"description": "Embed a server of HTTP in React Native app",
55
"files": [
66
"android",
77
"apple",
@@ -16,6 +16,19 @@
1616
"!android/local.properties",
1717
"!ios/build"
1818
],
19+
"exports": {
20+
".": {
21+
"import": {
22+
"types": "./lib/typescript/module/index.d.ts",
23+
"default": "./lib/module/index.js"
24+
},
25+
"require": {
26+
"types": "./lib/typescript/commonjs/index.d.ts",
27+
"default": "./lib/commonjs/index.js"
28+
}
29+
},
30+
"./package.json": "./package.json"
31+
},
1932
"peerDependencies": {
2033
"react-native-worklets": ">=0.7"
2134
},
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const VERSION = "X.X.X" // placeholder. It will be replaced on publishing automatically
1+
export const VERSION = "0.0.1-beta.1" // placeholder. It will be replaced on publishing automatically

0 commit comments

Comments
 (0)