Skip to content

Commit 6acef85

Browse files
committed
native build
1 parent 565bf7c commit 6acef85

File tree

3 files changed

+100
-60
lines changed

3 files changed

+100
-60
lines changed

.github/workflows/beta-release.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ on:
55
workflow_dispatch:
66

77
jobs:
8-
get-configs:
9-
uses: ./.github/workflows/configs.yml
10-
118
create-beta-tag:
12-
needs: [get-configs]
139
runs-on: ubuntu-latest
1410
permissions:
1511
contents: write

.github/workflows/release.yml

Lines changed: 94 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,99 @@ jobs:
6969
ref: ${{ needs.version-and-tag.outputs.tag }}
7070
runs-on: ${{ matrix.os }}
7171

72+
bundle-linux:
73+
needs: [ get-configs, version-and-tag, build-and-test ]
74+
strategy:
75+
fail-fast: true
76+
matrix:
77+
include:
78+
- { arch: "x64", docker-platform: "linux/amd64", go-arch: "amd64", use_qemu: false, node-version: "18.x" }
79+
- { arch: "x64", docker-platform: "linux/amd64", go-arch: "amd64", use_qemu: false, node-version: "20.x" }
80+
- { arch: "x64", docker-platform: "linux/amd64", go-arch: "amd64", use_qemu: false, node-version: "22.x" }
81+
- { arch: "arm64", docker-platform: "linux/arm64", go-arch: "arm64", use_qemu: true, node-version: "18.x" }
82+
- { arch: "arm64", docker-platform: "linux/arm64", go-arch: "arm64", use_qemu: true, node-version: "20.x" }
83+
- { arch: "arm64", docker-platform: "linux/arm64", go-arch: "arm64", use_qemu: true, node-version: "22.x" }
84+
runs-on: ubuntu-22.04
85+
steps:
86+
- uses: actions/checkout@v5
87+
with:
88+
ref: ${{ needs.version-and-tag.outputs.tag }}
89+
fetch-tags: true
90+
91+
- name: Set release asset name
92+
id: set-asset-name
93+
shell: bash
94+
run: |
95+
APP_NAME=${{ needs.get-configs.outputs.app-name }}
96+
VERSION=$(node -p "require('./package.json').version")
97+
NODE_VERSION=${{ matrix.node-version }}
98+
NODE_MAJOR=$(echo $NODE_VERSION | cut -d. -f1)
99+
100+
TAG=${{ needs.version-and-tag.outputs.tag }}
101+
if [[ "$TAG" =~ -alpha$ ]]; then
102+
FILE_NAME="${APP_NAME}-${VERSION}-alpha-linux-${{ matrix.arch }}-node${NODE_MAJOR}.zip"
103+
elif [[ "$TAG" =~ -beta$ ]]; then
104+
FILE_NAME="${APP_NAME}-${VERSION}-beta-linux-${{ matrix.arch }}-node${NODE_MAJOR}.zip"
105+
else
106+
FILE_NAME="${APP_NAME}-${VERSION}-linux-${{ matrix.arch }}-node${NODE_MAJOR}.zip"
107+
fi
108+
109+
ASSET_NAME=$(echo "$FILE_NAME" | tr '[:upper:]' '[:lower:]')
110+
echo "ASSET_NAME=${ASSET_NAME}" >> $GITHUB_OUTPUT
111+
112+
- name: Set up QEMU
113+
if: matrix.use_qemu
114+
uses: docker/setup-qemu-action@v3
115+
116+
- name: Build in Container
117+
run: |
118+
docker run --rm -v ${{ github.workspace }}:/work -w /work \
119+
--platform ${{ matrix.docker-platform }} \
120+
amazonlinux:2 \
121+
/bin/bash -c '
122+
set -ex
123+
yum install -y curl make gcc-c++ python3 tar gzip wget
124+
125+
wget -q https://go.dev/dl/go${{ needs.get-configs.outputs.go-version }}.linux-${{ matrix.go-arch }}.tar.gz
126+
tar -C /usr/local -xzf go${{ needs.get-configs.outputs.go-version }}.linux-${{ matrix.go-arch }}.tar.gz
127+
export PATH=$PATH:/usr/local/go/bin
128+
129+
curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
130+
export NVM_DIR="$HOME/.nvm"
131+
. "$NVM_DIR/nvm.sh"
132+
nvm install ${{ matrix.node-version }}
133+
npm install -g npm@latest
134+
135+
npm ci
136+
137+
TAG="${{ needs.version-and-tag.outputs.tag }}"
138+
if [[ "$TAG" =~ -alpha$ ]]; then
139+
npm run bundle:alpha
140+
elif [[ "$TAG" =~ -beta$ ]]; then
141+
npm run bundle:beta
142+
else
143+
npm run bundle:prod
144+
fi
145+
146+
GOARCH=${{ matrix.go-arch }} go build -C ./cfn-init/cmd -v -o ../../bundle/production/bin/cfn-init
147+
cp ./cfn-init/THIRD-PARTY-LICENSES.txt ./bundle/production/bin/
148+
149+
cd ./bundle/production && zip -r ../../${{ steps.set-asset-name.outputs.ASSET_NAME }} .
150+
'
151+
152+
- name: Upload artifact
153+
uses: actions/upload-artifact@v4
154+
with:
155+
name: ${{ steps.set-asset-name.outputs.ASSET_NAME }}
156+
path: ${{ steps.set-asset-name.outputs.ASSET_NAME }}
157+
if-no-files-found: error
158+
72159
bundle:
73160
needs: [ get-configs, version-and-tag, build-and-test ]
74161
strategy:
75162
fail-fast: true
76163
matrix:
77164
include:
78-
- { os: "ubuntu-22.04", arch: "x64", platform: "linux", go-arch: "amd64", node-version: "18.x" }
79-
- { os: "ubuntu-22.04", arch: "x64", platform: "linux", go-arch: "amd64", node-version: "20.x" }
80-
- { os: "ubuntu-22.04", arch: "x64", platform: "linux", go-arch: "amd64", node-version: "22.x" }
81-
- { os: "ubuntu-22.04", arch: "arm64", platform: "linux", go-arch: "arm64", node-version: "18.x" }
82-
- { os: "ubuntu-22.04", arch: "arm64", platform: "linux", go-arch: "arm64", node-version: "20.x" }
83-
- { os: "ubuntu-22.04", arch: "arm64", platform: "linux", go-arch: "arm64", node-version: "22.x" }
84-
- { os: "ubuntu-22.04", arch: "arm", platform: "linux", go-arch: "arm", node-version: "18.x" }
85-
- { os: "ubuntu-22.04", arch: "arm", platform: "linux", go-arch: "arm", node-version: "20.x" }
86-
- { os: "ubuntu-22.04", arch: "arm", platform: "linux", go-arch: "arm", node-version: "22.x" }
87165
- { os: "macos-latest", arch: "x64", platform: "darwin", go-arch: "amd64", node-version: "18.x" }
88166
- { os: "macos-latest", arch: "x64", platform: "darwin", go-arch: "amd64", node-version: "20.x" }
89167
- { os: "macos-latest", arch: "x64", platform: "darwin", go-arch: "amd64", node-version: "22.x" }
@@ -124,11 +202,11 @@ jobs:
124202
run: |
125203
TAG=${{ needs.version-and-tag.outputs.tag }}
126204
if [[ "$TAG" =~ -alpha$ ]]; then
127-
npm run bundle:alpha -- --env platform=${{ matrix.platform }} --env arch=${{ matrix.arch }}
205+
npm run bundle:alpha
128206
elif [[ "$TAG" =~ -beta$ ]]; then
129-
npm run bundle:beta -- --env platform=${{ matrix.platform }} --env arch=${{ matrix.arch }}
207+
npm run bundle:beta
130208
else
131-
npm run bundle:prod -- --env platform=${{ matrix.platform }} --env arch=${{ matrix.arch }}
209+
npm run bundle:prod
132210
fi
133211
134212
- name: Bundle Go
@@ -193,7 +271,7 @@ jobs:
193271
if-no-files-found: error
194272

195273
release:
196-
needs: [ version-and-tag, bundle ]
274+
needs: [ version-and-tag, bundle-linux, bundle ]
197275
runs-on: ubuntu-latest
198276
permissions:
199277
contents: write
@@ -203,6 +281,9 @@ jobs:
203281
with:
204282
path: artifacts
205283

284+
- name: List artifacts
285+
run: ls -R artifacts/
286+
206287
- name: Create GitHub Release
207288
uses: softprops/action-gh-release@v2
208289
with:

webpack.config.js

Lines changed: 6 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function generateExternals() {
5454

5555
const EXTERNALS = generateExternals();
5656

57-
function createPlugins(isDevelopment, outputPath, mode, env, targetPlatform, targetArch) {
57+
function createPlugins(isDevelopment, outputPath, mode, env) {
5858
const plugins = [];
5959

6060
plugins.push(
@@ -90,7 +90,6 @@ function createPlugins(isDevelopment, outputPath, mode, env, targetPlatform, tar
9090
compiler.hooks.beforeRun.tapAsync('InstallDependencies', (compilation, callback) => {
9191
try {
9292
console.log('[InstallDependencies] Starting dependency installation...');
93-
console.log(`[InstallDependencies] Target: ${targetPlatform}-${targetArch}`);
9493

9594
const tmpPkg = {
9695
...Package,
@@ -112,10 +111,11 @@ function createPlugins(isDevelopment, outputPath, mode, env, targetPlatform, tar
112111

113112
console.log('[InstallDependencies] Running npm ci --omit=dev');
114113
execSync('npm ci --omit=dev', { cwd: tmpDir, stdio: 'inherit' });
114+
115+
console.log('[InstallDependencies] Rebuilding tree-sitter-json from source...');
116+
execSync('npm rebuild tree-sitter-json --build-from-source', { cwd: tmpDir, stdio: 'inherit' });
117+
115118
const otherDeps = Object.entries(Package.nativePrebuilds)
116-
.filter(([key, _version]) => {
117-
return key.endsWith(`${targetPlatform}-${targetArch}`);
118-
})
119119
.map(([key, version]) => {
120120
return `${key}@${version}`;
121121
})
@@ -130,43 +130,6 @@ function createPlugins(isDevelopment, outputPath, mode, env, targetPlatform, tar
130130
}
131131
});
132132

133-
compiler.hooks.afterEmit.tap('CleanUnusedNativeModules', () => {
134-
console.log('[CleanUnusedNativeModules] Starting cleanup of unused native modules...');
135-
136-
const nodeModulesPath = path.join(outputPath, 'node_modules');
137-
138-
if (!fs.existsSync(nodeModulesPath)) {
139-
console.log('[CleanUnusedNativeModules] No node_modules found, skipping cleanup');
140-
return;
141-
}
142-
143-
function cleanPlatformDirs(dir) {
144-
if (!fs.existsSync(dir)) return;
145-
146-
const entries = fs.readdirSync(dir, { withFileTypes: true });
147-
for (const entry of entries) {
148-
if (!entry.isDirectory()) continue;
149-
150-
const entryPath = path.join(dir, entry.name);
151-
const isPlatformDir = PLATFORMS.some((p) => entry.name.includes(`${p}-`));
152-
const shouldKeep = entry.name.includes(`${targetPlatform}-${targetArch}`);
153-
154-
if (isPlatformDir && !shouldKeep) {
155-
console.log(`[CleanUnusedNativeModules] Deleted: ${entryPath}`);
156-
fs.rmSync(entryPath, { recursive: true, force: true });
157-
} else if (entry.name === 'prebuilds') {
158-
console.log(`[CleanUnusedNativeModules] Scanning prebuilds: ${entryPath}`);
159-
cleanPlatformDirs(entryPath);
160-
} else {
161-
cleanPlatformDirs(entryPath);
162-
}
163-
}
164-
}
165-
166-
cleanPlatformDirs(nodeModulesPath);
167-
console.log('[CleanUnusedNativeModules] Cleanup complete');
168-
});
169-
170133
compiler.hooks.done.tap('CleanupTemp', () => {
171134
console.log('[CleanupTemp] Cleaning up temporary files...');
172135
if (fs.existsSync(tmpDir)) {
@@ -334,6 +297,6 @@ module.exports = (env = {}) => {
334297
chunks: 'all',
335298
},
336299
},
337-
plugins: createPlugins(isDevelopment, outputPath, mode, awsEnv, targetPlatform, targetArch),
300+
plugins: createPlugins(isDevelopment, outputPath, mode, awsEnv),
338301
};
339302
};

0 commit comments

Comments
 (0)