Skip to content

Commit 624fad1

Browse files
committed
Set up verification of executables on build #627
1 parent f718263 commit 624fad1

File tree

5 files changed

+120
-51
lines changed

5 files changed

+120
-51
lines changed

.github/workflows/build.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Build
2+
3+
on:
4+
push:
5+
6+
jobs:
7+
8+
build:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v5
14+
with:
15+
fetch-depth: 0
16+
17+
- name: Set up Go
18+
uses: actions/setup-go@v6
19+
with:
20+
go-version: 1.24.0
21+
22+
- name: Test
23+
run: go test -v ./...
24+
25+
- name: GoReleaser Action
26+
uses: goreleaser/goreleaser-action@v6
27+
with:
28+
args: --clean --snapshot --skip=snapcraft
29+
30+
- name: Upload the binaries
31+
uses: actions/upload-artifact@v4
32+
with:
33+
name: Enonic CLI binaries
34+
path: dist/enonic_*/
35+
36+
- name: Upload package.json and index.js
37+
uses: actions/upload-artifact@v4
38+
with:
39+
name: Node files
40+
path: |
41+
package.json
42+
index.js
43+
44+
verify:
45+
needs: build
46+
runs-on: ${{ matrix.os }}
47+
strategy:
48+
matrix:
49+
os: [ubuntu-latest, macos-latest, windows-latest]
50+
arch: [x64, arm64]
51+
52+
steps:
53+
- name: Download Enonic CLI binaries
54+
uses: actions/download-artifact@v4
55+
with:
56+
name: Enonic CLI binaries
57+
path: dist/
58+
59+
- name: Download Node files
60+
uses: actions/download-artifact@v4
61+
with:
62+
name: Node files
63+
path: ./
64+
65+
- name: Set up Node.js
66+
uses: actions/setup-node@v6
67+
with:
68+
node-version: 22
69+
70+
- name: Make the binaries executable
71+
run: chmod +x dist/enonic_*/enonic
72+
73+
- name: Run node index.js
74+
run: node index.js
75+
env:
76+
NODE_ARCH: ${{ matrix.arch }}

.github/workflows/go.yml

Lines changed: 0 additions & 27 deletions
This file was deleted.

.github/workflows/release.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ jobs:
4040

4141
- uses: actions/setup-node@v6
4242
with:
43-
node-version: '20.x'
44-
registry-url: 'https://registry.npmjs.org'
43+
node-version: 22
4544

4645
- run: npm publish
4746
env:

.goreleaser.yml

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,13 @@ builds:
4646
- arm64
4747
- arm
4848

49-
goarm:
50-
- 6
51-
# - 7
52-
5349
# windows_arm64 builds fail: exit status 2: # golang.org/x/sys/windows
5450
#../../../.go/pkg/mod/golang.org/x/[email protected]/windows/zsyscall_windows.go:2833:38: undefined: WSAData
5551
#../../../.go/pkg/mod/golang.org/x/[email protected]/windows/zsyscall_windows.go:3106:51: undefined: Servent
5652
#../../../.go/pkg/mod/golang.org/x/[email protected]/windows/zsyscall_windows.go:3120:50: undefined: Servent
5753
ignore:
5854
- goos: windows
59-
goarch: arm64
55+
goarch: arm
6056

6157
hooks:
6258
post: ./script.sh
@@ -160,7 +156,7 @@ scoops:
160156
# - "data"
161157
# - "config.toml"
162158

163-
brews:
159+
homebrew_casks:
164160

165161
- skip_upload: false
166162

@@ -172,8 +168,9 @@ brews:
172168

173169
# Template for the url.
174170
# Default is "https://github.com/<repo_owner>/<repo_name>/releases/download/{{ .Tag }}/{{ .ArtifactName }}"
175-
url_template: https://repo.enonic.com/public/com/enonic/cli/{{ .ProjectName }}/{{ .Version }}/{{ .ArtifactName }}
176-
171+
url:
172+
template: "https://repo.enonic.com/public/com/enonic/cli/{{ .ProjectName }}/{{ .Version }}/{{ .ArtifactName }}"
173+
verified: "https://repo.enonic.com"
177174
# Allows you to set a custom download strategy.
178175
# Default is empty.
179176
# download_strategy: GitHubPrivateRepositoryReleaseDownloadStrategy
@@ -184,10 +181,6 @@ brews:
184181
name: goreleaserbot
185182
186183

187-
# Folder inside the repository to put the formula.
188-
# Default is the root folder.
189-
directory: Formula
190-
191184
# Your app's homepage.
192185
# Default is empty.
193186
homepage: https://enonic.com/

index.js

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
const path = require('path');
66
const fs = require('fs');
7+
const { arch, platform, argv, env } = require('node:process');
78

89
// Mapping from Node's `process.arch` to Golang's `$GOARCH`
910
const ARCH_MAPPING = {
@@ -32,32 +33,53 @@ const validateConfiguration = (packageJson) => {
3233
const parsePackageJson = () => {
3334
const packageJsonPath = path.resolve(__dirname, 'package.json');
3435
if (!fs.existsSync(packageJsonPath)) {
35-
throw new Error('Unable to find package.json. Please run this script at root of the package you want to be installed');
36+
console.error('Unable to find package.json. Please run this script at root of the package you want to be installed');
37+
process.exit(1);
3638
}
3739

3840
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath));
3941
const error = validateConfiguration(packageJson);
4042
if (error && error.length > 0) {
41-
throw new Error(`Invalid package.json: ${error}`);
43+
console.error(`Invalid package.json: ${error}`);
44+
process.exit(1);
4245
}
4346

44-
if (!(process.platform in PLATFORM_MAPPING)) {
45-
throw new Error(`Installation is not supported for platform "${process.platform}"`);
47+
if (!(platform in PLATFORM_MAPPING)) {
48+
console.error(`Installation is not supported for platform "${platform}"`);
49+
process.exit(1);
4650
}
4751

48-
if (!(process.arch in ARCH_MAPPING)) {
49-
throw new Error(`Installation is not supported for architecture "${process.arch}"`);
52+
/*
53+
This part is used for cross-platform verification of binaries during CI/CD.
54+
*/
55+
let thisArch = arch;
56+
if (env['NODE_ARCH']) {
57+
if (platform === 'win32' && env['NODE_ARCH'] === 'arm64') {
58+
console.log(`Skipping verification for ${platform} ${arch}`);
59+
process.exit(0);
60+
}
61+
if (platform === 'linux' && env['NODE_ARCH'] === 'arm64') {
62+
thisArch = 'arm';
63+
} else {
64+
thisArch = env['NODE_ARCH'];
65+
}
66+
}
67+
/**/
68+
69+
if (!(thisArch in ARCH_MAPPING)) {
70+
console.error(`Installation is not supported for architecture "${thisArch}"`);
71+
process.exit(1);
5072
}
5173

5274
const project = packageJson.goBinary;
5375
let binName = project;
5476

5577
// Binary name on Windows has .exe suffix
56-
if (process.platform === 'win32') {
78+
if (platform === 'win32') {
5779
binName += '.exe';
5880
}
5981

60-
const binFolder = `${project}_${PLATFORM_MAPPING[process.platform]}_${ARCH_MAPPING[process.arch]}`;
82+
const binFolder = `${project}_${PLATFORM_MAPPING[platform]}_${ARCH_MAPPING[thisArch]}`;
6183
const binPath = path.resolve(__dirname, 'dist', binFolder, binName);
6284

6385
return {
@@ -66,15 +88,21 @@ const parsePackageJson = () => {
6688
};
6789
}
6890

69-
const argv = process.argv;
7091
if (argv) {
7192
try {
7293
const opts = parsePackageJson();
7394
if (!opts) {
7495
console.error('Invalid package.json');
75-
return;
96+
process.exit(1);
7697
}
7798

99+
if (!fs.existsSync(opts.binPath)) {
100+
console.error(`Binary not found at ${opts.binPath}`);
101+
process.exit(1);
102+
}
103+
104+
console.log(`Executing binary: ${opts.binPath}`);
105+
78106
const {spawn} = require('child_process');
79107
spawn(opts.binPath, argv.slice(2), { stdio: 'inherit' });
80108
}

0 commit comments

Comments
 (0)