Skip to content

Commit 5b6e950

Browse files
committed
feat: support linux compilation
1 parent 88cf9fe commit 5b6e950

File tree

2 files changed

+90
-11
lines changed

2 files changed

+90
-11
lines changed

.github/workflows/go.yml

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,34 +30,72 @@ jobs:
3030
3131
- name: Build
3232
run: |
33-
mkdir bin
3433
GOARCH=arm64 go build -ldflags="-s -w" -o mobilectl-arm64
3534
GOARCH=amd64 go build -ldflags="-s -w" -o mobilectl-amd64
36-
lipo mobilectl-arm64 mobilectl-amd64 -create -output mobilectl
35+
lipo mobilectl-arm64 mobilectl-amd64 -create -output mobilectl-darwin
3736
rm mobilectl-arm64 mobilectl-amd64
3837
3938
- name: Upload macos build artifact
4039
uses: actions/upload-artifact@v4
4140
with:
4241
name: macos-build
4342
path: |
44-
mobilectl
43+
mobilectl-darwin
4544
retention-days: 1
4645
overwrite: true
4746

48-
publish:
47+
build_on_linux:
4948

5049
runs-on: ubuntu-latest
5150
needs: build_on_macos
5251
steps:
5352
- uses: actions/checkout@v4
5453

55-
- name: Download macos build
54+
- name: Set up Go
55+
uses: actions/setup-go@v5
56+
with:
57+
go-version-file: go.mod
58+
59+
- name: Install dependencies
60+
run: |
61+
go get golang.org/x/tools/cmd/goimports@latest
62+
go get github.com/golangci/golangci-lint/cmd/golangci-lint@latest
63+
64+
- name: Build
65+
run: |
66+
GOARCH=arm64 go build -ldflags="-s -w" -o mobilectl-linux-arm64
67+
GOARCH=amd64 go build -ldflags="-s -w" -o mobilectl-linux-amd64
68+
69+
- name: Upload macos build artifact
70+
uses: actions/upload-artifact@v4
71+
with:
72+
name: linux-build
73+
path: |
74+
mobilectl-darwin
75+
mobilectl-linux-arm64
76+
mobilectl-linux-amd64
77+
retention-days: 1
78+
overwrite: true
79+
80+
publish:
81+
82+
runs-on: ubuntu-latest
83+
needs: build_on_linux
84+
steps:
85+
- uses: actions/checkout@v4
86+
87+
- name: Download darwin build
5688
uses: actions/download-artifact@v4
5789
with:
5890
name: macos-build
59-
path: mobilectl-macos
91+
path: mobilectl-darwin
6092

93+
- name: Download linux build
94+
uses: actions/download-artifact@v4
95+
with:
96+
name: linux-build
97+
path: mobilectl-linux
98+
6199
- uses: AButler/upload-release-assets@v2.0
62100
with:
63101
files: "*.zip"
@@ -69,12 +107,13 @@ jobs:
69107
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
70108
run: |
71109
# prepare binaries for distribution
72-
mv ./mobilectl-macos/mobilectl publish/npm/bin/mobilectl
73-
chmod +x publish/npm/bin/mobilectl
110+
find . -ls
111+
mv ./mobilectl-darwin/mobilectl-darwin publish/npm/bin/mobilectl-darwin
112+
chmod +x publish/npm/bin/*
74113
# setup npmrc
75114
echo "//registry.npmjs.org/:_authToken=$NPM_AUTH_TOKEN" >> ~/.npmrc
76115
# sed -i 's/\"local-build\"/\"${{ env.release_tag }}\"/' package.json
77116
# publish to npm
78117
cd publish/npm
79118
npm install
80-
npm publish
119+
#npm publish

publish/npm/index.js

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,45 @@
11
#!/usr/bin/env node
22

3-
const { execSync } = require("node:child_process");
3+
const { join } = require("node:path");
4+
const { spawn } = require("node:child_process");
45

5-
execSync(__dirname + "/bin/mobilectl", {stdio: "inherit"});
6+
let binary;
7+
8+
switch (process.platform) {
9+
case "darwin":
10+
binary = "mobilectl-darwin";
11+
break;
12+
13+
case "linux":
14+
switch (process.arch) {
15+
case "arm64":
16+
binary = "mobilectl-linux-arm64";
17+
break;
18+
case "x64":
19+
binary = "mobilectl-linux-amd64";
20+
break;
21+
}
22+
break;
23+
24+
default:
25+
console.error(`Unsupported platform: ${process.platform}-${process.arch}`);
26+
process.exit(1);
27+
}
28+
29+
const binaryPath = join(__dirname, "bin", binary);
30+
31+
const args = process.argv.slice(2);
32+
const child = spawn(binaryPath, args, {
33+
env: process.env,
34+
cwd: process.cwd(),
35+
stdio: [process.stdin, process.stdout, process.stderr],
36+
});
37+
38+
child.on("error", (error) => {
39+
console.error(error);
40+
process.exit(1);
41+
});
42+
43+
child.on("close", (code) => {
44+
process.exit(code);
45+
});

0 commit comments

Comments
 (0)