-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
1331 lines (1177 loc) · 50.7 KB
/
Copy pathaction.yml
File metadata and controls
1331 lines (1177 loc) · 50.7 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
name: "Community Package Build Action"
description: "Builds Manjaro/Community Packages"
inputs:
build_env:
description: "Build environment (testing, extra, stable, or aur)"
required: true
default: "testing"
source:
description: "Custom package repo source"
required: false
manjaro_branch:
description: "Manjaro branch to build"
default: stable
required: false
custom_repo:
description: "Custom repo"
required: false
multilib:
description: "Build multilib package"
required: false
default: "false"
repo:
description: "Package repo"
required: true
gpg_key:
description: "GPG signing key"
required: true
gpg_passphrase:
description: "GPG passphrase"
required: true
git_branch:
description: "Extra repository to build package"
required: false
extra_command:
description: "Extra command to run before building"
required: false
extra_package:
description: "Extra package to build"
required: false
default: "false"
tmate:
description: "Run tmate for debugging"
required: false
repo_mirror:
description: "Mirror to use in build"
default: repo
required: false
repo_dev:
description: "Development repository"
required: false
pacman_mirror:
description: "Optional: Specific mirror to override automatic selection"
required: false
default: "https://mirrors.ocf.berkeley.edu/manjaro/stable/$repo/$arch"
publish_github:
description: "Publish package on GitHub"
required: false
default: "true"
push_to_repo:
description: "Push package to repository"
required: false
default: "true"
update_db:
description: "Update repository database"
required: false
default: "true"
repo_host:
description: "Repository host"
required: false
repo_user:
description: "Repository user"
required: false
repo_port:
description: "Repository port"
required: false
repo_dir:
description: "Repository directory"
required: false
github_token:
description: "GitHub token for authentication"
required: true
telegram_token:
description: "Telegram bot token for notifications"
required: false
telegram_chat_id:
description: "Telegram chat ID for notifications"
required: false
branch_type:
description: "Branch type (testing or stable)"
required: true
url:
description: "Repository URL"
required: false
new_branch:
description: "New branch name"
required: false
package_name:
description: "Package name"
required: false
aur_package_dir:
description: "Directory containing the AUR package"
required: false
default: "."
start_time:
description: "Workflow start time"
required: false
start_timestamp:
description: "Workflow start timestamp"
required: false
repo_origem:
description: "Source repository"
required: false
branch_fullname:
description: "Full name of the source branch"
required: false
translate:
description: "Enable translation process"
required: false
default: "false"
openai_key:
description: "OpenAI API key for translation"
required: false
# Action steps definition
runs:
using: "composite"
steps:
- name: Define send_telegram_message function in temporary script
shell: bash
env:
TELEGRAM_TOKEN: "${{ inputs.telegram_token }}"
TELEGRAM_CHAT_ID: "${{ inputs.telegram_chat_id }}"
run: |
# Define send_telegram_message function in temporary script
cat << 'EOF' > /tmp/send_telegram_message.sh
export TERM=${TERM:-xterm}
export TERM=${TERM:-xterm-256color}
# Color definitions for status messages
blueDark="\e[1;38;5;33m" # Bold dark blue
mediumBlue="\e[1;38;5;32m" # Bold medium blue
lightBlue="\e[1;38;5;39m" # Bold light blue
cyan="\e[1;38;5;45m" # Bold cyan
white="\e[1;97m" # Bold white
reset="\e[0m" # Reset text formatting
# Additional colors for warnings/errors
red="\e[1;31m" # Bold red for errors
yellow="\e[1;33m" # Bold yellow for warnings
green="\e[1;32m" # Bold green for success
alias ls='ls -lha --color=auto'
alias dir='ls -lha --color=auto'
die() {
local msg="$1"
msg="$(sed 's/<[^>]*>//g' <<< "$msg")" # Remove HTML tags
echo -e "BP=>${red}error: ${white}${msg}${reset}"
exit 1
}
export -f die
msg_raw() {
local msg="$1"
# Remove HTML tags if they exist
#msg="$(sed 's/<[^>]*>//g' <<< "$msg")"
# Check if message contains ':'
if [[ "$msg" == *:* ]]; then
# Split string before and after first ':'
local before_colon="${msg%%:*}:"
local after_colon="${msg#*: }"
# Apply colors
msg="${mediumBlue}${before_colon} ${white}${after_colon}${reset}"
else
# If no ':', apply default color
msg="${mediumBlue}${msg}${reset}"
fi
echo -e "$msg"
}
export -f msg_raw
msg() {
local msg="$1"
msg="$(sed 's/<[^>]*>//g' <<< "$msg")" # Remove HTML tags
echo -e "BP=>${blueDark}[${lightBlue}RUNNING${blueDark}]${reset} ${cyan}→${reset} ${white}${msg}${reset}"
}
export -f msg
msg_ok() {
local msg="$1"
msg="$(sed 's/<[^>]*>//g' <<< "$msg")" # Remove HTML tags
echo -e "BP=>${blueDark}[${green}SUCCESS${blueDark}]${reset} ${cyan}→${reset} ${white}${msg}${reset}"
}
export -f msg_ok
msg_run() {
local msg="$1"
echo -e "BP=>${blueDark}[${lightBlue}COMMAND${blueDark}]${reset} ${cyan}→${reset} ${white}${msg}${reset}"
eval "$msg"
}
export -f msg_run
msg_info() {
local msg="$1"
msg="$(sed 's/<[^>]*>//g' <<< "$msg")" # Remove HTML tags
echo -e "BP=>${blueDark}[${cyan}INFO${blueDark}]${reset} ${cyan}→${reset} ${white}${msg}${reset}"
}
export -f msg_info
msg_warning() {
local msg="$1"
msg="$(sed 's/<[^>]*>//g' <<< "$msg")" # Remove HTML tags
echo -e "BP=>${blueDark}[${yellow}WARNING${blueDark}]${reset} ${cyan}→${reset} ${white}${msg}${reset}"
}
export -f msg_warning
replicate() {
local char=${1:-'#'}
local nsize=${2:-$(tput cols)}
local line
printf -v line "%*s" "$nsize" && echo -e "${blueDark}${line// /$char}${reset}"
}
export -f replicate
send_telegram_message() {
local message="$1"
local parse_mode="$2"
# Set parse_mode as "HTML" if not specified
[[ -z $parse_mode ]] && parse_mode="HTML"
# Remove HTML tags and display result in terminal
echo -e "${green}$(sed 's/<[^>]*>//g' <<< "$message")${reset}"
# Send original message with HTML to Telegram
curl -s -X POST "https://api.telegram.org/bot${{ inputs.telegram_token }}/sendMessage" \
-d chat_id="${{ inputs.telegram_chat_id }}" \
-d text="$message" \
-d parse_mode="$parse_mode"
}
export -f send_telegram_message
EOF
- name: Get last commit hash from remote repository
shell: bash
run: |
# Get last commit hash from remote repository
source /tmp/send_telegram_message.sh
replicate '='
REPO_URL="${{ inputs.url }}"
echo "REPO_URL=$REPO_URL" >> $GITHUB_ENV
COMMIT_HASH="$(git ls-remote $REPO_URL HEAD | awk '{print $1}')"
msg_raw "Last commit hash: $COMMIT_HASH"
# Fetch remote commit information
git fetch $REPO_URL $COMMIT_HASH
# Get commit message from hash
COMMIT_MESSAGE="$(git log -1 --format=%B $COMMIT_HASH)"
msg_raw "Last commit message: $COMMIT_MESSAGE"
replicate '='
- name: Initialize package creation
shell: bash
run: |
# Initializing package creation
source /tmp/send_telegram_message.sh
replicate '='
# https://docs.github.com/pt/enterprise-server@3.10/actions/writing-workflows/choosing-what-your-workflow-does/accessing-contextual-information-about-workflow-runs
pkgname="${{ inputs.package_name }}"
branch="${{ inputs.branch_type }}"
repo_path="${{ inputs.repo_dir }}"
repo_origem="${{ inputs.url }}"
started_by_user="${{ github.actor }}"
triggered_by_user="${{ github.triggering_actor }}"
pkgname_escaped="$pkgname"
branch_escaped="${branch}"
message="🏁 <b>[step 1/4] build-package - STARTING PACKAGE CREATION</b>
<b>Job:</b> <code>#${GITHUB_RUN_NUMBER}</code>
<b>Workflow:</b> <code>build-package/action.yml</code>
<b>Name:</b> <code>${pkgname_escaped}</code>
<b>Commit:</b> <code>${COMMIT_MESSAGE}</code>
<b>Source:</b> <code>${repo_origem}</code>
<b>Started/Triggered by:</b> <code>${started_by_user}/${triggered_by_user}</code>
<b>Branch:</b> <code>${branch_escaped}</code>"
msg_info "$message"
send_telegram_message "$message"
replicate '='
- name: Debug Inputs
shell: bash
run: |
# Debug Inputs
source /tmp/send_telegram_message.sh
replicate '='
msg_info "DEBUG All inputs"
msg_raw "DEBUG Json inputs : ${{ toJson(inputs) }}"
msg_raw "DEBUG build_env from input: ${{ inputs.build_env }}"
msg_raw "DEBUG build_env from env : $DEBUG_BUILD_ENV"
msg_raw "DEBUG tmate input : ${{ inputs.tmate }}"
msg_info "DEBUG All env variables above"
msg_raw "$(env | sort)"
replicate '='
- name: Setup build environment
shell: bash
run: |
# Configure build environment - Update and install required dependencies
source /tmp/send_telegram_message.sh
replicate '='
msg_run 'sudo pacman -Syu --quiet --needed --noconfirm --overwrite \*'
replicate '='
# Check installed versions
meson --version
ninja --version
- name: Setup TMATE Session
uses: mxschmitt/action-tmate@v3
if: ${{ github.event.client_payload.tmate == true || inputs.tmate == true}}
with:
install-dependencies: false
detached: true
- name: Import GPG key
shell: bash
run: |
# Import GPG key
source /tmp/send_telegram_message.sh
replicate '='
if gpg --batch --import <<< "${{ inputs.gpg_key }}"; then
msg_ok "GPG key import successful"
else
die "Error importing GPG key"
fi
replicate '='
- name: Configure System and Repositories
shell: bash
run: |
# Configure System and Repositories
source /tmp/send_telegram_message.sh
replicate '#'
msg_info "# Set up pacman mirror"
msg_raw "Using specified mirror: ${{ inputs.pacman_mirror }}"
echo 'Server = ${{ inputs.pacman_mirror }}' | sudo tee -a /etc/pacman.d/mirrorlist
echo 'Server = https://linorg.usp.br/manjaro/testing/$repo/$arch' | sudo tee -a /etc/pacman.d/mirrorlist
echo 'Server = https://manjaro.c3sl.ufpr.br/testing/$repo/$arch' | sudo tee -a /etc/pacman.d/mirrorlist
replicate '-'
msg_run 'cat /etc/pacman.d/mirrorlist'
replicate '-'
msg_run 'cat /etc/pacman.conf'
replicate '-'
msg_info "# Remove existing BigLinux repositories"
sudo sed -i '/biglinux/,$d' /etc/pacman.conf
msg_info "# Add repositories to build environment"
declare -A entries=(
[community-stable]='https://repo.communitybig.org/stable/$arch'
[community-testing]='https://repo.communitybig.org/testing/$arch'
[community-extra]='https://repo.communitybig.org/extra/$arch'
[biglinux-stable]='https://repo.biglinux.com.br/stable/$arch'
[biglinux-testing]='https://repo.biglinux.com.br/testing/$arch'
)
for entry in "${!entries[@]}"; do
section='['"$entry"']'
server="${entries[$entry]}"
if ! grep -qF "$section" /etc/pacman.conf; then
echo -e "\n$section\nSigLevel = PackageRequired\nServer = $server" | \
sudo tee -a /etc/pacman.conf /etc/chrootbuild/pacman.conf.x86_64 >/dev/null
msg_info "Added section: $section"
fi
done
if [ "${{ inputs.build_env }}" == "aur" ] || [ "${{ inputs.branch_type }}" == "aur" ]; then
msg_raw "Configuring for AUR package: ${{ inputs.package_name }}"
msg_info '# AUR specific configurations'
sudo sed -i 's/^#MAKEFLAGS="-j2"/MAKEFLAGS="-j$(nproc)"/' /etc/makepkg.conf
sudo sed -i 's/^#BUILDDIR/BUILDDIR/' /etc/makepkg.conf
sudo sed -i 's/^#PKGDEST/PKGDEST/' /etc/makepkg.conf
msg_info '# Enable multilib repository (required for some AUR packages)'
sudo sed -i '/\[multilib\]/,/Include/s/^#//' /etc/pacman.conf
fi
# Configure makepkg
sudo sed -i '/PACKAGER=/s/.*/PACKAGER="Big Community Package Build <talesam@gmail.com>"/' /etc/makepkg.conf
sudo sed -i '/MAKEFLAGS=/s/.*/MAKEFLAGS="-j'$(nproc)'"/' /etc/makepkg.conf
sudo sed -i '/GPGKEY=/s/.*/GPGKEY="AECEEE84E52BBFAA9F1C9DF01EA0CEEEB09B44A3"/; t; $a GPGKEY="AECEEE84E52BBFAA9F1C9DF01EA0CEEEB09B44A3"' /etc/makepkg.conf
# Modify manjaro-chrootbuild
sudo sed -i 's|https://repo.manjaro.org/repo|https://nnenix.mm.fcix.net/manjaro|' /usr/lib/manjaro-chrootbuild/util.sh
sudo sed -i '/-Syy/s/-Syy/-Syy git /' /usr/lib/manjaro-chrootbuild/util-chroot.sh
msg_info '# Install commonly needed build dependencies'
msg_run "sudo pacman -Sy --needed base-devel git --noconfirm"
replicate '#'
msg_run 'cat /etc/pacman.conf'
replicate '#'
msg_run 'cat /etc/makepkg.conf'
replicate '#'
- name: Download Source code
shell: bash
run: |
# Download the source code
source /tmp/send_telegram_message.sh
replicate '#'
export REPO_OWNER=""
export REPO_NAME=""
if [[ "${{ inputs.build_env }}" == "aur" ]]; then
# AUR package handling code - no changes needed
msg_raw "Cloning AUR package from: ${{ inputs.url }}"
msg_run "git clone ${{ inputs.url }} aur_package"
if [[ -d "aur_package" ]]; then
cd aur_package
# Extract package name from AUR URL
REPO_ORIGEM_NAME=$(basename "${{ inputs.url }}" .git)
REPO_ORIGEM_OWNER="aur"
# Export to GitHub Actions environment
echo "REPO_ORIGEM_NAME=$REPO_ORIGEM_NAME" >> $GITHUB_ENV
echo "REPO_ORIGEM_OWNER=$REPO_ORIGEM_OWNER" >> $GITHUB_ENV
if [[ ! -f "PKGBUILD" ]]; then
die "Error: PKGBUILD not found in the AUR package"
fi
else
die "Error: Failed to clone AUR package"
fi
elif [[ -n "${{ inputs.url }}" ]]; then
msg_raw "Cloning repository from: ${{ inputs.url }}"
msg_run "git clone ${{ inputs.url }}.git source_repo"
# Extract information from cloned repository
REPO_ORIGEM_URL="${{ inputs.repo_origem }}"
REPO_ORIGEM_NAME=$(basename -s .git "$REPO_ORIGEM_URL")
REPO_ORIGEM_OWNER=$(echo "$REPO_ORIGEM_URL" | awk -F[/:] '{print $(NF-1)}')
# Export to GitHub Actions environment
echo "REPO_ORIGEM_NAME=$REPO_ORIGEM_NAME" >> $GITHUB_ENV
echo "REPO_ORIGEM_OWNER=$REPO_ORIGEM_OWNER" >> $GITHUB_ENV
cd source_repo
# Determine which branch to use based on package type
if [[ -n "${{ inputs.git_branch }}" ]]; then
# Check if the specified branch exists
if git ls-remote --heads origin ${{ inputs.git_branch }} | grep -q ${{ inputs.git_branch }}; then
# Branch exists, checkout
msg_raw "Checking out branch: ${{ inputs.git_branch }}"
msg_run "git checkout ${{ inputs.git_branch }}"
else
# Branch doesn't exist, fallback to main
msg_raw "Branch ${{ inputs.git_branch }} doesn't exist, using main as fallback"
msg_run "git checkout main || git checkout master"
fi
elif [[ "${{ inputs.branch_type }}" == "testing" && -n "${{ inputs.new_branch }}" ]]; then
# For testing packages, use the new_branch (dev-* branch)
msg_raw "Testing package: using dev branch: ${{ inputs.new_branch }}"
msg_run "git checkout ${{ inputs.new_branch }}"
else
# For stable/extra packages, use main branch
msg_raw "Stable/Extra package: using main branch"
# No checkout needed as main is the default
fi
# IMPORTANT: Only check for locale directory AFTER checking out the correct branch
if [[ -d "locale" ]]; then
msg_info "Locale directory found - translation enabled"
echo "LOCALE_DIR_EXISTS=true" >> $GITHUB_ENV
else
msg_info "No locale directory found - translation will be skipped"
echo "LOCALE_DIR_EXISTS=false" >> $GITHUB_ENV
fi
else
msg_warning "No URL provided, assuming already in the correct repository"
echo "LOCALE_DIR_EXISTS=false" >> $GITHUB_ENV
fi
replicate '#'
- name: Process Translations
if: ${{ inputs.translate == 'true' && env.LOCALE_DIR_EXISTS == 'true' }}
shell: bash
env:
OPENAI_KEY: ${{ inputs.openai_key }}
run: |
# Process translations
source /tmp/send_telegram_message.sh
replicate '#'
msg_info "Starting translation process"
# Get repository name to match the original workflow behavior
REPO_NAME="${{ env.REPO_ORIGEM_NAME }}"
msg_info "Repository name (package) to translate: $REPO_NAME"
# Go to source repo root
cd $GITHUB_WORKSPACE/source_repo
msg_info "Current directory: $(pwd)"
msg_info "Contents of current directory:"
ls -la
# Make sure we have locale directory with proper permissions
mkdir -p locale
chmod -R 755 locale
msg_info "Created locale directory with proper permissions"
# Execute the translation script - pass "." as DIR but override DIRNAME with REPO_NAME
# This is the key fix - we explicitly set DIRNAME to be different from DIR
msg_info "Executing translation script for package: $REPO_NAME"
DIRNAME="$REPO_NAME" OPENAI_KEY=${{ inputs.openai_key }} gettext_po_generator_github.sh "."
# Return to the original directory
cd $GITHUB_WORKSPACE
msg_ok "Translation process completed"
replicate '#'
- name: Commit Translation Changes
if: ${{ inputs.translate == 'true' && env.LOCALE_DIR_EXISTS == 'true' }}
shell: bash
run: |
# Commit translation changes
source /tmp/send_telegram_message.sh
replicate '#'
msg_info "Committing translation changes"
cd source_repo
# Configure Git
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
# Add all changes
git add --all
# Check if there are changes to commit
if git commit -m "translate $(date +%y-%m-%d_%H:%M)" -a; then
msg_ok "Translation changes committed"
# Configure remote with token for authentication
remote_url=$(git config --get remote.origin.url)
authenticated_url="https://x-access-token:${{ inputs.github_token }}@github.com/${remote_url#https://github.com/}"
git remote set-url origin "$authenticated_url"
# Push changes with authentication
if git push origin HEAD; then
msg_ok "Translation changes pushed to repository"
else
msg_warning "Failed to push translation changes"
fi
else
msg_info "No translation changes to commit"
fi
# Go back to original directory
cd ..
replicate '#'
- name: Build package
shell: bash
run: |
# Build package
source /tmp/send_telegram_message.sh
replicate '#'
msg_raw "Build environment: ${{ inputs.build_env }}"
msg_raw "Package name : ${{ inputs.package_name }}"
msg_info '# Create and set permissions for $PKGDEST and $SRCDEST'
msg_run 'sudo mkdir -p /home/packages /home/sources /tmp/makepkg'
msg_run 'sudo chown builduser:builduser /home/packages /home/sources /tmp/makepkg'
msg_info '# Ensure we are in the correct directory from previous step'
if [ "${{ inputs.build_env }}" == "aur" ]; then
# For AUR packages
cd ${{ inputs.aur_package_dir }}
msg_raw "Building AUR package: ${{ inputs.package_name }}"
msg_raw "Current AUR package directory: $(pwd)"
msg_raw "AUR package directory contents:"
msg_run "ls -la $PWD"
# Give permissions to builduser for the current directory
sudo chown -R builduser:builduser .
# Create temporary directory for makepkg
sudo mkdir -p /tmp/makepkg
sudo chown builduser:builduser /tmp/makepkg
# Verify build environment
echo "Verifying build environment..."
gcc --version
meson --version
ninja --version
pkg-config --version
# Detect and import GPG keys if present in PKGBUILD
if [ -f "PKGBUILD" ]; then
msg_info "Checking for required PGP keys..."
if grep -q "validpgpkeys" PKGBUILD; then
# Extract GPG key from PKGBUILD
key=$(grep "validpgpkeys" PKGBUILD | sed 's/.*(\"\(.*\)\")/\1/')
if [ ! -z "$key" ]; then
msg_raw "Importing GPG key: $key"
# Try multiple keyservers to ensure key import succeeds
gpg --keyserver keyserver.ubuntu.com --recv-keys "$key" || \
gpg --keyserver keys.gnupg.net --recv-keys "$key" || \
gpg --keyserver hkp://pgp.mit.edu --recv-keys "$key" || \
msg_warning "Warning: Failed to import key $key"
fi
else
msg_info "No PGP keys defined in PKGBUILD"
fi
fi
# Extract dependencies from PKGBUILD
source PKGBUILD
TAG_NAME="$pkgver-$pkgrel"
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV
msg_info "TAG_NAME : ${TAG_NAME}"
msg_info "depends : ${depends[@]}"
msg_info "makedepends: ${makedepends[@]}"
msg_info "checkdepends: ${checkdepends[@]}"
# Install all dependencies using yay
install_dependencies() {
local all_deps=()
# Add depends if exists
if [ -n "${depends[*]}" ]; then
all_deps+=("${depends[@]}")
fi
# Add makedepends if exists
if [ -n "${makedepends[*]}" ]; then
all_deps+=("${makedepends[@]}")
fi
# Add checkdepends if exists
if [ -n "${checkdepends[*]}" ]; then
all_deps+=("${checkdepends[@]}")
msg_info "Including checkdepends for testing support"
fi
if [ ${#all_deps[@]} -gt 0 ]; then
msg_info "Installing all dependencies (${#all_deps[@]} packages)..."
yay -Sy --asdeps --needed --noanswerdiff --noconfirm "${all_deps[@]}" || {
msg_warning "Error installing dependencies"
return 1
}
else
msg_info "No dependencies to install"
fi
return 0
}
# Call the installation function
if ! install_dependencies; then
die "Failed to install dependencies"
fi
# Build the package without installing
msg_raw "Building AUR package: ${{ inputs.package_name }}"
makepkg -s --noconfirm --noprogressbar --nodeps
else
# For non-AUR packages
gitfolder=$(find -type f -name PKGBUILD | sed 's/PKGBUILD//')
cd $gitfolder
source PKGBUILD
TAG_NAME="$pkgver-$pkgrel"
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV
msg_info "TAG_NAME : ${TAG_NAME}"
msg_info "depends : ${depends[@]}"
msg_info "makedepends: ${makedepends[@]}"
# Ensure architecture is set to x86_64
sed -i "/^arch=/c\arch=('x86_64')" PKGBUILD
msg_info "Build arch=x86_64"
# Configure correct branch in PKGBUILD based on build type
msg_info "# Configuring correct branch in PKGBUILD"
if [ "${{ inputs.branch_type }}" == "testing" ]; then
# Check if this is our repository (biglinux or big-comm)
if grep -q 'github.com/biglinux\|github.com/big-comm\|\${url}\|\$url' PKGBUILD; then
msg_info "Detected our repository - modifying to use branch: ${{ inputs.new_branch }}"
# Expand variables in PKGBUILD before processing
# Support both $url and ${url} formats (and same for $pkgname)
msg_info "Expanding PKGBUILD variables before modification..."
source PKGBUILD
sed -i "s|\${url}|$url|g; s|\\\$url|$url|g" PKGBUILD
sed -i "s|\${pkgname}|$pkgname|g; s|\\\$pkgname|$pkgname|g" PKGBUILD
msg_info "Variables expanded successfully"
# Function to modify git URLs in our repositories only (supports single and multi-line source arrays)
awk -v branch="${{ inputs.new_branch }}" '
BEGIN {
in_source = 0
source_level = 0
}
# Detect start of source array (single line or multi-line)
/^[[:space:]]*source[[:space:]]*=/ {
in_source = 1
# If it is a complete single line source=("..."), process immediately
if ($0 ~ /^[[:space:]]*source[[:space:]]*=.*\).*$/) {
if ($0 ~ /git\+.*github\.com\/.*\.git/) {
if ($0 ~ /#branch=/ || $0 ~ /#tag=/) {
gsub(/#[^"]*/, "#branch=" branch, $0)
} else {
gsub(/\.git"/, ".git#branch=" branch "\"", $0)
}
}
print $0
in_source = 0
next
}
# If not a complete line, it is a multi-line array
print $0
if ($0 ~ /\($/) source_level = 1
next
}
# Handle content inside source array (multi-line)
in_source == 1 {
# Count parentheses to detect end of array
temp = $0
gsub(/[^(]/, "", temp); open_parens = length(temp)
temp2 = $0
gsub(/[^)]/, "", temp2); close_parens = length(temp2)
source_level += open_parens - close_parens
# Check if this line contains our git URL
if ($0 ~ /git\+.*github\.com\/.*\.git/) {
# Modify our repository URLs
if ($0 ~ /#branch=/ || $0 ~ /#tag=/) {
# Already has branch/tag, replace it
gsub(/#[^"]*/, "#branch=" branch, $0)
} else {
# Add branch to git URL
gsub(/\.git"/, ".git#branch=" branch "\"", $0)
}
}
print $0
# End of source array
if (source_level <= 0) {
in_source = 0
}
next
}
# Print all other lines unchanged
{ print $0 }
' PKGBUILD > /tmp/pkgbuild_temp && mv /tmp/pkgbuild_temp PKGBUILD
msg_info "PKGBUILD configured to use branch: ${{ inputs.new_branch }}"
else
msg_info "External repository detected - keeping original source configuration for testing"
fi
else
# For stable/extra, keep original configuration
msg_info "Using original source configuration for stable/extra build"
fi
# Determine build branch
if [ "${{ inputs.build_env }}" == "extra" ]; then
build_branch="testing"
msg_info "Build environment is 'extra', using 'testing' branch for chrootbuild"
else
build_branch="stable"
fi
# Execute makepkg instead of chrootbuild
if makepkg -s --noconfirm --noprogressbar; then
pkgname="${{ inputs.package_name }}"
full_pkgname="$(find . -type f -iname "$pkgname*.pkg.tar.zst" -print)"
msg_raw "full_pkgname : $full_pkgname"
echo "full_pkgname=$full_pkgname" >> $GITHUB_ENV
msg_run "cp -f $full_pkgname /home/packages/ 2>/dev/null" || msg_warning 'No package found to move'
msg_ok "Build completed. Checking /home/packages:"
msg_run 'ls -la /home/packages'
else
die "Build with makepkg failed."
fi
fi
msg_info '# Execute extra command, if provided'
if [[ -n "${{ inputs.extra_command }}" ]]; then
msg_raw "Executing extra command: ${{ inputs.extra_command }}"
${{ inputs.extra_command }}
fi
# Move the compiled package to /home/packages
cp -f *.pkg.tar.zst /home/packages/ 2>/dev/null || msg_warning 'No package found to move'
msg_info '# Debug: Show directory contents after build'
msg_run "ls -la $PWD"
msg_run 'ls -la /home/sources'
msg_run 'ls -la /home/packages'
replicate '#'
- name: Sign Package
shell: bash
run: |
# Sign Package
source /tmp/send_telegram_message.sh
replicate '#'
msg_run 'cd /home/packages'
msg_run "ls -lah $PWD"
# Sign all packages found
# Import GPG key
if gpg --batch --import <<< "${{ inputs.gpg_key }}"; then
msg_ok "GPG key import successful."
for p in /home/packages/*pkg.tar.zst; do
[ -e "$p" ] || { msg_info "No packages found to sign."; break; }
msg_info "Signing package: $p"
if ! gpg --pinentry-mode loopback --passphrase "${{ inputs.gpg_passphrase }}" --detach-sign "${p}"; then
msg_warning "Error signing package: $p"
fi
done
msg_run 'ls -lah $PWD *.sig*' || msg_warning "No .sig files found"
else
die "Error importing GPG key."
fi
replicate '#'
- name: Generate checksums
shell: bash
run: |
# Generate checksums
source /tmp/send_telegram_message.sh
replicate '#'
msg_run 'cd /home/packages'
msg_run "ls -lah $PWD"
for p in *pkg.tar.zst; do
[ -e "$p" ] || continue # Skip if file doesn't exist
msg_info "Generating MD5 for: $p and $p.sig"
{
md5sum "$p"
[ -f "$p.sig" ] && md5sum "$p.sig"
} > "$p.md5"
done
msg_run 'ls -lah $PWD *.md5' || msg_warning 'No MD5 files found'
replicate '#'
- name: Push the package to the repository
if: inputs.push_to_repo == 'true'
shell: bash
env:
LANG: en_US.UTF-8
LC_ALL: en_US.UTF-8
run: |
# Push the package to the repository
source /tmp/send_telegram_message.sh
replicate '#'
# Setup SSH
msg_run 'mkdir -p /home/builduser/.ssh'
msg_run "ssh-keyscan -t rsa -p ${{ inputs.repo_port }} ${{ inputs.repo_host }} >> /home/builduser/.ssh/known_hosts"
ip="${{ inputs.repo_host }}"
if [[ "${{ inputs.build_env }}" == "aur" ]]; then
msg_info "=== Starting AUR package processing ==="
msg_raw "Current directory before cd: $(pwd)"
msg_run 'cd /home/packages'
msg_raw "Current directory after cd: $(pwd)"
branch="EXTRA"
msg_raw "Branch set to: $branch"
msg_raw "Contents of /home/packages directory:"
msg_run "ls -la /home/packages"
else
msg_run 'cd /home/packages'
msg_info '# Set the branch based on BRANCH_TYPE'
case "${{ inputs.branch_type }}" in
"stable")
branch="STABLE"
;;
"extra")
branch="EXTRA"
;;
*)
branch="TESTING"
;;
esac
fi
# Environment configuration logs
msg_info "=== Environment Configuration ==="
msg_raw "Build Environment: ${{ inputs.build_env }}"
msg_raw "Branch Type: ${{ inputs.branch_type }}"
msg_raw "Branch: $branch"
msg_raw "Repository Path: ${{ inputs.repo_dir }}"
msg_raw "IP: $ip"
msg_run "ls -lha $PWD"
# # First, rename files with : to .
# for i in *.pkg.tar.zst; do
# new_name=${i//:/.}
# if [ "$i" != "$new_name" ]; then
# mv "$i" "$new_name"
# [ -f "$i.sig" ] && mv "$i.sig" "$new_name.sig"
# [ -f "$i.md5" ] && mv "$i.md5" "$new_name.md5"
# fi
# done
for i in *.pkg.tar.zst; do
msg_info "=== Processing file: $i ==="
msg_raw "File exists? $([ -f "$i" ] && echo "Yes" || echo "No")"
msg_raw "Full path: $(readlink -f "$i")"
pkgname=$(basename "$i")
pkgname_escaped=$(echo "$pkgname" | sed 's/&/\&/g; s/</\</g; s/>/\>/g')
branch_escaped=$(echo "$branch" | sed 's/&/\&/g; s/</\</g; s/>/\>/g')
echo "PKGNAME_BASENAME=$pkgname_escaped" >> $GITHUB_ENV
echo "PKGNAME_BRANCH=${branch_escaped,,}" >> $GITHUB_ENV
repo_path="${{ inputs.repo_dir }}"
file_size_bytes=$(stat -c%s "$i")
file_size_kb=$((file_size_bytes / 1024))
file_size_mb=$((file_size_kb / 1024))
message="✅ <b>[step 2/4] build-package - SENDING 📦 TO REPOSITORY</b>
<b>Job:</b> <code>#${GITHUB_RUN_NUMBER}</code>
<b>Workflow:</b> <code>build-package/action.yml</code>
<b>Package:</b> <code>${branch_escaped,,}/${pkgname_escaped}</code>
<b>Size b/Kb/Mb:</b> <code>${file_size_bytes}/${file_size_kb}/${file_size_mb}</code>
<b>Repository:</b> <code>${repo_path}</code>
<b>Branch:</b> <code>${branch_escaped}</code>"
msg_ok "$message"
send_telegram_message "$message"
# Log rsync command to be executed
msg_info "=== rsync command to be executed ==="
rsync_cmd="rsync -s --itemize-changes -apz -e \"ssh -p ${{ inputs.repo_port }}\" ./$i ${{ inputs.repo_user }}@$ip:${{ inputs.repo_dir }}/${branch,,}/x86_64/"
msg_raw "rsync command: $rsync_cmd"
if rsync -s --itemize-changes -v -apz -e "ssh -p ${{ inputs.repo_port }}" "./$i" "${{ inputs.repo_user }}@$ip:${{ inputs.repo_dir }}/${branch,,}/x86_64/" 2>&1; then
message="✅ <b>[step 2.1/4] build-package - PACKAGE SENT SUCCESSFULLY</b>
<b>Job:</b> <code>#${GITHUB_RUN_NUMBER}</code>
<b>Workflow:</b> <code>build-package/action.yml</code>
<b>Package:</b> <code>${pkgname_escaped}</code>
<b>Branch:</b> <code>${branch_escaped}</code>"
# Message sending is commented to avoid too many notifications
else
message="❌ <b>[step 2/4] build-package - FAILED TO SEND PACKAGE</b>
<b>Job:</b> <code>#${GITHUB_RUN_NUMBER}</code>
<b>Workflow:</b> <code>build-package/action.yml</code>
<b>Package:</b> <code>${pkgname_escaped}</code>
<b>Branch:</b> <code>${branch_escaped}</code>"
send_telegram_message "$message"
fi
done
# Log before processing .sig and .md5 files
msg_info "=== Processing .sig and .md5 files ==="
msg_raw ".sig and .md5 files present:"
msg_run "ls -la *.sig *.md5 || echo 'No files found'"
for i in *.sig *.md5; do
[[ ! -f "$i" ]] && continue # Skip if file doesn't exist
msg_raw "Processing file: $i"
msg_raw "Sending file: $i"
rsync -s --itemize-changes -v -apz -e "ssh -p ${{ inputs.repo_port }}" "./$i" "${{ inputs.repo_user }}@$ip:${{ inputs.repo_dir }}/${branch,,}/x86_64/" 2>&1
done
replicate '#'
- name: Clean Old Packages
if: inputs.update_db == 'true' && success()
shell: bash
run: |
# Clean Old Packages - keeps only the most recent package
source /tmp/send_telegram_message.sh
replicate '#'
msg_info '# Determine the branch and database name based on the branch type'
case "${{ inputs.branch_type }}" in
"stable")
branch="STABLE"
db_name="community-stable"
;;
"aur" | "extra")
branch="EXTRA"
db_name="community-extra"
;;
"testing")