-
Notifications
You must be signed in to change notification settings - Fork 0
155 lines (139 loc) · 5.81 KB
/
off-context-cli-release.yml
File metadata and controls
155 lines (139 loc) · 5.81 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
name: Off Context Cli Release
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
version:
description: 'Release version (e.g., v1.0.1)'
required: true
default: 'v1.0.1'
type: string
release_name:
description: 'Release name (optional)'
required: false
type: string
prerelease:
description: 'Mark as pre-release'
required: false
default: false
type: boolean
build_linux:
description: 'Build Linux version'
required: false
default: true
type: boolean
build_macos:
description: 'Build macOS version'
required: false
default: true
type: boolean
env:
CARGO_TERM_COLOR: always
permissions:
contents: write
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- id: set-matrix
run: |
matrix="{"
builds=()
# Check if Linux build is enabled (default true for tag pushes)
if [[ "${{ github.event.inputs.build_linux }}" == "true" || ("${{ github.event_name }}" == "push" && "${{ github.event.inputs.build_linux }}" != "false") ]]; then
builds+=('{"os":"ubuntu-latest","target":"x86_64-unknown-linux-musl","artifact_name":"off-context","asset_name":"off-context-linux-x86_64.tar.gz"}')
builds+=('{"os":"ubuntu-latest","target":"aarch64-unknown-linux-musl","artifact_name":"off-context","asset_name":"off-context-linux-arm64.tar.gz"}')
fi
# Check if macOS build is enabled (default true for tag pushes)
if [[ "${{ github.event.inputs.build_macos }}" == "true" || ("${{ github.event_name }}" == "push" && "${{ github.event.inputs.build_macos }}" != "false") ]]; then
builds+=('{"os":"macos-latest","target":"x86_64-apple-darwin","artifact_name":"off-context","asset_name":"off-context-macos-x86_64.tar.gz"}')
builds+=('{"os":"macos-latest","target":"aarch64-apple-darwin","artifact_name":"off-context","asset_name":"off-context-macos-arm64.tar.gz"}')
fi
# Join builds with commas
IFS=','
matrix="\"include\":[${builds[*]}]}"
echo "matrix={$matrix}" >> $GITHUB_OUTPUT
echo "Generated matrix: {$matrix}"
build:
name: Build and Release
needs: prepare
runs-on: ${{ matrix.os }}
timeout-minutes: 30
strategy:
matrix: ${{ fromJson(needs.prepare.outputs.matrix) }}
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: |
if [[ "${{ matrix.target }}" == "x86_64-unknown-linux-musl" ]]; then
sudo apt-get update
sudo apt-get install -y musl-tools
elif [[ "${{ matrix.target }}" == "aarch64-unknown-linux-musl" ]]; then
sudo apt-get update
sudo apt-get install -y musl-tools gcc-aarch64-linux-gnu
fi
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Build
run: |
if [[ "${{ matrix.target }}" == "aarch64-unknown-linux-musl" ]]; then
export CC_aarch64_unknown_linux_musl=aarch64-linux-gnu-gcc
export CXX_aarch64_unknown_linux_musl=aarch64-linux-gnu-g++
export AR_aarch64_unknown_linux_musl=aarch64-linux-gnu-ar
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=aarch64-linux-gnu-gcc
fi
cargo build --release --target ${{ matrix.target }}
- name: Debug and create tarball
run: |
echo "=== Debugging binary location ==="
echo "Looking for: ${{ matrix.artifact_name }}"
echo "Target: ${{ matrix.target }}"
echo ""
echo "Directory structure:"
find target -type f -name "*off-context*" || echo "No off-context files found"
echo ""
echo "All files in target/:"
ls -la target/ || echo "No target directory"
echo ""
echo "Checking specific paths:"
echo "1. target/${{ matrix.target }}/release/${{ matrix.artifact_name }}"
ls -la "target/${{ matrix.target }}/release/" || echo "Path 1 not found"
echo "2. target/release/${{ matrix.artifact_name }}"
ls -la "target/release/" || echo "Path 2 not found"
echo ""
mkdir -p dist
# Handle different build output paths
if [ -f "target/${{ matrix.target }}/release/${{ matrix.artifact_name }}" ]; then
echo "Found binary at target/${{ matrix.target }}/release/${{ matrix.artifact_name }}"
cp target/${{ matrix.target }}/release/${{ matrix.artifact_name }} dist/off-context
elif [ -f "target/release/${{ matrix.artifact_name }}" ]; then
echo "Found binary at target/release/${{ matrix.artifact_name }}"
cp target/release/${{ matrix.artifact_name }} dist/off-context
else
echo "Binary not found in expected locations, searching..."
BINARY_PATH=$(find target -name "${{ matrix.artifact_name }}" -type f | head -1)
if [ -n "$BINARY_PATH" ]; then
echo "Found binary at: $BINARY_PATH"
cp "$BINARY_PATH" dist/off-context
else
echo "Binary ${{ matrix.artifact_name }} not found anywhere in target/"
exit 1
fi
fi
cd dist
tar -czf ${{ matrix.asset_name }} off-context
- name: Upload Release Asset
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ github.event.inputs.version || github.ref_name }}
name: ${{ github.event.inputs.release_name || github.event.inputs.version || github.ref_name }}
files: dist/${{ matrix.asset_name }}
prerelease: ${{ github.event.inputs.prerelease || false }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}