-
Notifications
You must be signed in to change notification settings - Fork 0
143 lines (121 loc) · 4.21 KB
/
build_parsers.yml
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
name: Build Tree-Sitter Parsers
on:
push:
branches:
- main
- telkins/objc
paths:
- "parsers.toml"
- ".github/workflows/build_parsers.yml"
workflow_dispatch:
jobs:
build-parsers:
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-latest
platform: linux
- os: macos-latest
platform: macos
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- name: Install tsdl
run: |
cargo install tsdl
- name: Build tree-sitter parsers
run: |
tsdl build --out-dir build_parsers
- name: Determine platform and architecture
id: platform_info
run: |
# Determine architecture
arch=$(uname -m)
# Map architecture names to standard values
if [[ "$arch" == "x86_64" || "$arch" == "amd64" ]]; then
arch="x86_64"
elif [[ "$arch" == "arm64" || "$arch" == "aarch64" ]]; then
arch="arm64"
fi
# For macOS, adjust platform name
if [[ "${{ matrix.platform }}" == "macos" ]]; then
platform_name="darwin"
else
platform_name="${{ matrix.platform }}"
fi
# Set outputs
echo "arch=$arch" >> $GITHUB_OUTPUT
echo "platform_name=$platform_name" >> $GITHUB_OUTPUT
- name: Rename built parsers to include platform and architecture
run: |
# Use outputs from previous step
arch="${{ steps.platform_info.outputs.arch }}"
platform_name="${{ steps.platform_info.outputs.platform_name }}"
platform_arch="${platform_name}-${arch}"
echo "Using platform_arch=${platform_arch}"
# Rename parser files in the temporary directory
for file in build_parsers/libtree-sitter-*; do
if [ -f "$file" ]; then
filename=$(basename "$file")
extension="${filename##*.}"
base="${filename%.*}"
echo "Processing file $filename"
# Append platform_arch before the extension
new_base="${base}-${platform_arch}"
echo "Renaming $file to build_parsers/${new_base}.${extension}"
mv "$file" "build_parsers/${new_base}.${extension}"
fi
done
- name: Move renamed parsers to parsers directory
run: |
# Ensure parsers directory exists
mkdir -p parsers
# Move files and overwrite existing ones
for file in build_parsers/*; do
filename=$(basename "$file")
dest_file="parsers/$filename"
echo "Moving $file to $dest_file"
mv -f "$file" "$dest_file"
done
- name: Configure git
run: |
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
- name: Check for changes
id: changes
run: |
git add -A
if git diff --cached --quiet; then
echo "changes=false" >> $GITHUB_OUTPUT
else
echo "changes=true" >> $GITHUB_OUTPUT
fi
- name: Pull latest changes
if: steps.changes.outputs.changes == 'true'
run: |
git pull --rebase --autostash
- name: Commit changes
if: steps.changes.outputs.changes == 'true'
run: |
git commit -m "Build tree-sitter parsers for ${{ steps.platform_info.outputs.platform_name }}-${{ steps.platform_info.outputs.arch }}"
- name: Push changes
if: steps.changes.outputs.changes == 'true'
run: |
max_retries=5
retry_count=0
until git push || [ $retry_count -eq $max_retries ]; do
echo "Push failed, retrying..."
git pull --rebase --autostash
retry_count=$((retry_count + 1))
sleep 5
done
if [ $retry_count -eq $max_retries ]; then
echo "Push failed after $max_retries attempts."
exit 1
fi