-
Notifications
You must be signed in to change notification settings - Fork 477
132 lines (120 loc) · 4.34 KB
/
npm-app-release-build.yml
File metadata and controls
132 lines (120 loc) · 4.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
name: Build Binary
on:
workflow_call:
inputs:
binary-name:
required: true
type: string
description: 'Name of the binary to build (codebuff or codecane)'
new-version:
required: true
type: string
description: 'Version to build'
artifact-name:
required: true
type: string
description: 'Name for the artifact (updated-package or updated-staging-package)'
checkout-ref:
required: false
type: string
description: 'Git ref to checkout'
default: ''
env-overrides:
required: false
type: string
description: 'JSON object of environment variables to override defaults'
default: '{}'
jobs:
build-binaries:
strategy:
matrix:
include:
- os: ubuntu-latest
target: linux-x64
bun_target: bun-linux-x64
platform: linux
arch: x64
- os: ubuntu-latest
target: linux-arm64
bun_target: bun-linux-arm64
platform: linux
arch: arm64
- os: macos-15-intel
target: darwin-x64
bun_target: bun-darwin-x64
platform: darwin
arch: x64
- os: macos-14
target: darwin-arm64
bun_target: bun-darwin-arm64
platform: darwin
arch: arm64
- os: windows-latest
target: win32-x64
bun_target: bun-windows-x64
platform: win32
arch: x64
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v6
with:
ref: ${{ inputs.checkout-ref || github.sha }}
- uses: ./.github/actions/setup-project
- name: Download updated package
uses: actions/download-artifact@v8
with:
name: ${{ inputs.artifact-name }}
path: ${{ inputs.artifact-name == 'updated-staging-package' && 'npm-app/release-staging/' || 'npm-app/release/' }}
- name: Set environment variables
env:
SECRETS_CONTEXT: ${{ toJSON(secrets) }}
ENV_OVERRIDES: ${{ inputs.env-overrides }}
shell: bash
run: |
VAR_NAMES=$(bun scripts/generate-ci-env.ts --scope client)
echo "$SECRETS_CONTEXT" | jq -r --argjson vars "$VAR_NAMES" '
to_entries | .[] | select(.key as $k | $vars | index($k)) | .key + "=" + .value
' >> $GITHUB_ENV
# Set default environment variables
echo "CODEBUFF_GITHUB_ACTIONS=true" >> $GITHUB_ENV
echo "CODEBUFF_GITHUB_TOKEN=${{ secrets.CODEBUFF_GITHUB_TOKEN }}" >> $GITHUB_ENV
# Apply environment variable overrides
if [ "$ENV_OVERRIDES" != "{}" ]; then
echo "$ENV_OVERRIDES" | jq -r 'to_entries | .[] | .key + "=" + .value' >> $GITHUB_ENV
fi
- name: Build binary
run: bun run scripts/build-binary.js ${{ inputs.binary-name }} ${{ inputs.new-version }}
working-directory: npm-app
shell: bash
env:
VERBOSE: true
BUILD_VERSION: ${{ inputs.new-version }}
OVERRIDE_TARGET: ${{ matrix.bun_target }}
OVERRIDE_PLATFORM: ${{ matrix.platform }}
OVERRIDE_ARCH: ${{ matrix.arch }}
- name: Test binary
run: |
cd npm-app/bin
echo "Testing binary..."
# Only test if we're building for the native architecture
if [[ "${{ matrix.platform }}" == "linux" && "${{ matrix.arch }}" == "arm64" && "${{ runner.arch }}" != "ARM64" ]]; then
echo "Skipping test for cross-compiled ARM64 binary"
elif [[ "${{ runner.os }}" == "Windows" ]]; then
./${{ inputs.binary-name }}.exe --version
else
./${{ inputs.binary-name }} --version
fi
shell: bash
- name: Create tarball
shell: bash
run: |
BINARY_FILE="${{ inputs.binary-name }}"
if [[ "${{ runner.os }}" == "Windows" ]]; then
BINARY_FILE="${{ inputs.binary-name }}.exe"
fi
tar -czf ${{ inputs.binary-name }}-${{ matrix.target }}.tar.gz -C npm-app/bin $BINARY_FILE
- name: Upload binary artifact
uses: actions/upload-artifact@v7
with:
name: ${{ inputs.binary-name }}-${{ matrix.target }}
path: ${{ inputs.binary-name }}-${{ matrix.target }}.*