1
- name : Build Context Generator Executable
1
+ ---
2
+
3
+ name : 📦 Build binary
2
4
3
5
on : # yamllint disable-line rule:truthy
4
6
release :
5
7
types :
6
8
- published
7
9
8
10
jobs :
9
- build :
11
+ build-unix :
10
12
runs-on : ubuntu-latest
11
- name : 📦 Build CTX Executable
13
+ name : 📦 Build Unix Executables
14
+ strategy :
15
+ fail-fast : false
16
+ matrix :
17
+ platform :
18
+ - os : linux
19
+ arch : amd64
20
+ - os : linux
21
+ arch : arm64
12
22
13
23
steps :
14
24
- name : Checkout code
15
25
uses : actions/checkout@v3
16
26
27
+ - name : Set up QEMU
28
+ uses : docker/setup-qemu-action@v2
29
+ with :
30
+ platforms : arm64,amd64
31
+
17
32
- name : Set up Docker Buildx
18
33
uses : docker/setup-buildx-action@v2
19
34
20
- - name : Set current version from ${{ github.ref_name }}
35
+ - name : Extract version from tag
36
+ id : get_version
21
37
run : |
22
- echo "{\"version\": \"${{ github.ref_name }}\", \"type\":\"bin\"}" > version.json
38
+ if [[ "$GITHUB_REF_NAME" == refs/pull/* ]]; then
39
+ # For pull requests, use "dev" as version
40
+ VERSION="dev"
41
+ else
42
+ # For releases, extract version from tag (remove 'v' prefix if present)
43
+ VERSION=${GITHUB_REF_NAME#v}
44
+ fi
45
+ echo "VERSION=$VERSION" >> $GITHUB_ENV
46
+ echo "{\"version\": \"$VERSION\", \"type\":\"bin\"}" > version.json
23
47
24
- - name : Build Docker image
48
+ - name : Build Docker image for ${{ matrix.platform.os }}-${{ matrix.platform.arch }}
25
49
uses : docker/build-push-action@v4
26
50
with :
27
51
context : .
28
52
push : false
29
53
load : true
30
- tags : ctx-builder:latest
31
- cache-from : type=gha
32
- cache-to : type=gha,mode=max
54
+ tags : ctx-builder-${{ matrix.platform.os }}-${{ matrix.platform.arch }}:latest
55
+ platforms : linux/${{ matrix.platform.arch }}
56
+ build-args : |
57
+ TARGET_OS=${{ matrix.platform.os }}
58
+ TARGET_ARCH=${{ matrix.platform.arch }}
59
+ VERSION=${{ env.VERSION }}
60
+ cache-from : type=gha,scope=${{ matrix.platform.os }}-${{ matrix.platform.arch }}
61
+ cache-to : type=gha,mode=max,scope=${{ matrix.platform.os }}-${{ matrix.platform.arch }}
33
62
34
- - name : Extract executable from Docker container
63
+ - name : Extract executable
35
64
run : |
36
65
mkdir -p dist
37
- container_id=$(docker create ctx-builder:latest)
38
- docker cp $container_id:/app/.build/bin/ ctx ./dist/ctx
66
+ container_id=$(docker create ctx-builder-${{ matrix.platform.os }}-${{ matrix.platform.arch }} :latest)
67
+ docker cp $container_id:/.output/ ctx ./dist/ctx-${{ env.VERSION }}-${{ matrix.platform.os }}-${{ matrix.platform.arch }}
39
68
docker rm $container_id
40
- chmod +x ./dist/ctx
41
69
42
70
- name : 📤 Upload release assets
43
71
44
72
if : startsWith(github.ref, 'refs/tags/')
45
73
with :
46
74
token : " ${{ secrets.RELEASE_TOKEN }}"
47
75
files : |
48
- ./dist/ctx
76
+ ./dist/ctx-${{ env.VERSION }}-${{ matrix.platform.os }}-${{ matrix.platform.arch }}
77
+
78
+ build-windows :
79
+ runs-on : windows-latest
80
+ name : 📦 Build Windows (x64)
81
+ steps :
82
+ - name : Checkout code
83
+ uses : actions/checkout@v3
84
+
85
+ - name : Set up PHP
86
+ uses : shivammathur/setup-php@v2
87
+ with :
88
+ php-version : ' 8.3'
89
+ extensions : mbstring, xml, curl, sockets
90
+ coverage : none
91
+
92
+ - name : Extract version from tag or set dev version
93
+ id : get_version
94
+ shell : bash
95
+ run : |
96
+ if [[ "$GITHUB_REF" == refs/pull/* ]]; then
97
+ # For pull requests, use "dev" as version
98
+ VERSION="dev"
99
+ else
100
+ # For releases, extract version from tag (remove 'v' prefix if present)
101
+ VERSION=${GITHUB_REF_NAME#v}
102
+ fi
103
+ echo "VERSION=$VERSION" >> $GITHUB_ENV
104
+ echo "{\"version\": \"$VERSION\", \"type\":\"bin\"}" > version.json
105
+
106
+ - name : Install Composer dependencies
107
+ run : composer install --no-dev --prefer-dist --ignore-platform-reqs
108
+
109
+ - name : Create build directories
110
+ run : New-Item -Path ".build\phar", ".build\bin" -ItemType Directory -Force
111
+
112
+ - name : Download box tool
113
+ run : |
114
+ Invoke-WebRequest -Uri "https://github.com/box-project/box/releases/download/4.6.6/box.phar" -OutFile ".build/bin/box.phar"
115
+
116
+ - name : Download SPC for Windows
117
+ run : |
118
+ Invoke-WebRequest -Uri "https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-windows-x64.exe" -OutFile ".build/bin/spc.exe"
119
+
120
+ - name : Download required PHP extensions
121
+ run : .build/bin/spc.exe download micro --for-extensions=ctype,dom,filter,libxml,mbstring,phar,simplexml,sockets,tokenizer,xml,xmlwriter,curl --with-php=8.3 --prefer-pre-built
122
+
123
+ # todo: fix this
124
+ # - name: Install UPX for compression
125
+ # run: |
126
+ # .build/bin/spc.exe install-pkg upx
127
+
128
+ - name : Verify environment is ready
129
+ run : |
130
+ .build/bin/spc.exe doctor --auto-fix
131
+
132
+ - name : Build the self-executable binary
133
+ run : .build/bin/spc.exe build "ctype,dom,filter,libxml,mbstring,phar,simplexml,sockets,tokenizer,xml,xmlwriter,curl" --build-micro --with-upx-pack
134
+
135
+ - name : Build PHAR file
136
+ run : |
137
+ php .build/bin/box.phar compile -v
138
+
139
+ - name : Combine micro.sfx with the PHAR
140
+ run : |
141
+ New-Item -Path "dist" -ItemType Directory -Force
142
+ .build\bin\spc.exe micro:combine .build\phar\ctx.phar --output=dist\ctx-${{ env.VERSION }}-windows-amd64.exe
143
+
144
+ - name : 📤 Upload release assets
145
+
146
+ if : startsWith(github.ref, 'refs/tags/')
147
+ with :
148
+ token : " ${{ secrets.RELEASE_TOKEN }}"
149
+ files : |
150
+ ./dist/ctx-${{ env.VERSION }}-windows-amd64.exe
0 commit comments