v / .github / workflows / update_tccbin.yml
216 lines · 196 sloc · 7.97 KB · eca96b530eeb5d34c5badc10e007f49ef5429ef4
Raw
1name: Update tccbin
2
3on:
4 workflow_dispatch:
5 inputs:
6 tcc_commit:
7 description: 'TinyCC ref, branch, or commit to build'
8 required: false
9 default: mob
10 publish:
11 description: 'Push the rebuilt bundle to vlang/tccbin'
12 type: boolean
13 required: false
14 default: false
15 force_rebuild:
16 description: 'Rebuild even when tccbin already records the same TinyCC hash'
17 type: boolean
18 required: false
19 default: false
20 schedule:
21 - cron: '17 3 1 * *'
22
23permissions:
24 contents: read
25
26concurrency:
27 group: update-tccbin-${{ github.ref }}
28 cancel-in-progress: false
29
30jobs:
31 update-tccbin-hosted:
32 if: github.repository == 'vlang/v' && (github.event_name != 'schedule' || github.ref == 'refs/heads/master')
33 strategy:
34 fail-fast: false
35 matrix:
36 include:
37 - id: linux-amd64
38 os: ubuntu-latest
39 branch: thirdparty-linux-amd64
40 script: thirdparty/build_scripts/thirdparty-linux-amd64_tcc.sh
41 - id: macos-amd64
42 os: macos-15-intel
43 branch: thirdparty-macos-amd64
44 script: thirdparty/build_scripts/thirdparty-macos-amd64_tcc.sh
45 - id: macos-arm64
46 os: macos-latest
47 branch: thirdparty-macos-arm64
48 script: thirdparty/build_scripts/thirdparty-macos-arm64_tcc.sh
49 runs-on: ${{ matrix.os }}
50 env:
51 TCC_COMMIT: ${{ github.event.inputs.tcc_commit || 'mob' }}
52 TCCBIN_REPO: vlang/tccbin
53 PUBLISH: ${{ github.event_name == 'schedule' || github.event.inputs.publish == 'true' }}
54 FORCE_REBUILD: ${{ github.event.inputs.force_rebuild == 'true' }}
55 steps:
56 - uses: actions/checkout@v6
57
58 - name: Install macOS build dependencies
59 if: runner.os == 'macOS'
60 run: brew install make
61
62 - name: Resolve TinyCC source hash
63 id: tinycc
64 shell: bash
65 run: |
66 set -euo pipefail
67 git clone --quiet https://repo.or.cz/tinycc.git /tmp/tinycc-ref
68 git -C /tmp/tinycc-ref checkout --quiet "$TCC_COMMIT"
69 hash="$(git -C /tmp/tinycc-ref rev-parse HEAD)"
70 echo "hash=$hash" >> "$GITHUB_OUTPUT"
71 echo "TinyCC $TCC_COMMIT resolves to $hash"
72
73 - name: Clone tccbin branch
74 shell: bash
75 env:
76 TCCBIN_TOKEN: ${{ secrets.VLANG_BOT_SECRET }}
77 run: |
78 set -euo pipefail
79 git clone --branch "${{ matrix.branch }}" --depth=1 \
80 "https://github.com/${TCCBIN_REPO}.git" thirdparty/tcc
81 if [ "$PUBLISH" = 'true' ]; then
82 if [ -z "$TCCBIN_TOKEN" ]; then
83 echo "::error::VLANG_BOT_SECRET is required to publish to ${TCCBIN_REPO}"
84 exit 1
85 fi
86 git -C thirdparty/tcc remote set-url origin \
87 "https://vlang-bot:${TCCBIN_TOKEN}@github.com/${TCCBIN_REPO}.git"
88 fi
89
90 - name: Check whether rebuild is needed
91 id: rebuild
92 shell: bash
93 run: |
94 set -euo pipefail
95 if [ "$FORCE_REBUILD" != 'true' ] \
96 && [ -f thirdparty/tcc/build_source_hash.txt ] \
97 && [ "$(cat thirdparty/tcc/build_source_hash.txt)" = "${{ steps.tinycc.outputs.hash }}" ]; then
98 echo "skip=true" >> "$GITHUB_OUTPUT"
99 echo "tccbin/${{ matrix.branch }} already has TinyCC ${{ steps.tinycc.outputs.hash }}"
100 else
101 echo "skip=false" >> "$GITHUB_OUTPUT"
102 fi
103
104 - name: Configure git identity
105 if: steps.rebuild.outputs.skip != 'true'
106 run: |
107 git config --global user.name vlang-bot
108 git config --global user.email [email protected]
109
110 - name: Build TCC bundle
111 if: steps.rebuild.outputs.skip != 'true'
112 shell: bash
113 env:
114 BUILD_CMD: TCC_COMMIT=${{ env.TCC_COMMIT }} TCC_FOLDER=thirdparty/tcc bash ${{ matrix.script }}
115 run: |
116 set -euo pipefail
117 TCC_FOLDER=thirdparty/tcc bash "${{ matrix.script }}"
118 test "$(cat thirdparty/tcc/build_source_hash.txt)" = "${{ steps.tinycc.outputs.hash }}"
119 thirdparty/tcc/tcc.exe --version
120 thirdparty/tcc/tcc.exe -v -v
121
122 - name: Upload TCC bundle artifact
123 if: steps.rebuild.outputs.skip != 'true'
124 uses: actions/upload-artifact@v7
125 with:
126 name: tccbin-${{ matrix.id }}
127 path: thirdparty/tcc
128
129 - name: Push tccbin branch
130 if: steps.rebuild.outputs.skip != 'true' && env.PUBLISH == 'true'
131 shell: bash
132 run: |
133 set -euo pipefail
134 git -C thirdparty/tcc push origin HEAD:${{ matrix.branch }}
135
136 update-tccbin-bsd:
137 if: github.repository == 'vlang/v' && (github.event_name != 'schedule' || github.ref == 'refs/heads/master')
138 strategy:
139 fail-fast: false
140 matrix:
141 include:
142 - id: freebsd-amd64
143 operating_system: freebsd
144 version: '15.0'
145 branch: thirdparty-freebsd-amd64
146 script: thirdparty/build_scripts/thirdparty-freebsd-amd64_tcc.sh
147 install: sudo pkg install -y bash git gmake rsync
148 cc: cc
149 - id: openbsd-amd64
150 operating_system: openbsd
151 version: '7.8'
152 branch: thirdparty-openbsd-amd64
153 script: thirdparty/build_scripts/thirdparty-openbsd-amd64_tcc.sh
154 install: sudo pkg_add bash git gmake rsync
155 cc: clang
156 runs-on: ubuntu-latest
157 env:
158 TCC_COMMIT: ${{ github.event.inputs.tcc_commit || 'mob' }}
159 TCCBIN_REPO: vlang/tccbin
160 PUBLISH: ${{ github.event_name == 'schedule' || github.event.inputs.publish == 'true' }}
161 FORCE_REBUILD: ${{ github.event.inputs.force_rebuild == 'true' }}
162 TCCBIN_TOKEN: ${{ secrets.VLANG_BOT_SECRET }}
163 steps:
164 - uses: actions/checkout@v6
165
166 - name: Start ${{ matrix.id }} VM
167 uses: cross-platform-actions/[email protected]
168 with:
169 operating_system: ${{ matrix.operating_system }}
170 version: ${{ matrix.version }}
171 memory: 4G
172 shell: sh
173 sync_files: runner-to-vm
174 environment_variables: TCC_COMMIT TCCBIN_REPO PUBLISH FORCE_REBUILD TCCBIN_TOKEN
175
176 - name: Build and publish ${{ matrix.id }} TCC bundle
177 shell: cpa.sh {0}
178 run: |
179 set -eu
180 ${{ matrix.install }}
181 git config --global user.name vlang-bot
182 git config --global user.email [email protected]
183 git config --global --add safe.directory "$PWD"
184
185 git clone --quiet https://repo.or.cz/tinycc.git /tmp/tinycc-ref
186 git -C /tmp/tinycc-ref checkout --quiet "$TCC_COMMIT"
187 tinycc_hash="$(git -C /tmp/tinycc-ref rev-parse HEAD)"
188 echo "TinyCC $TCC_COMMIT resolves to $tinycc_hash"
189
190 git clone --branch "${{ matrix.branch }}" --depth=1 \
191 "https://github.com/${TCCBIN_REPO}.git" thirdparty/tcc
192 if [ "$PUBLISH" = 'true' ]; then
193 if [ -z "$TCCBIN_TOKEN" ]; then
194 echo "VLANG_BOT_SECRET is required to publish to ${TCCBIN_REPO}" >&2
195 exit 1
196 fi
197 git -C thirdparty/tcc remote set-url origin \
198 "https://vlang-bot:${TCCBIN_TOKEN}@github.com/${TCCBIN_REPO}.git"
199 fi
200
201 if [ "$FORCE_REBUILD" != 'true' ] \
202 && [ -f thirdparty/tcc/build_source_hash.txt ] \
203 && [ "$(cat thirdparty/tcc/build_source_hash.txt)" = "$tinycc_hash" ]; then
204 echo "tccbin/${{ matrix.branch }} already has TinyCC $tinycc_hash"
205 exit 0
206 fi
207
208 BUILD_CMD="TCC_COMMIT=$TCC_COMMIT TCC_FOLDER=thirdparty/tcc CC=${{ matrix.cc }} bash ${{ matrix.script }}" \
209 TCC_FOLDER=thirdparty/tcc CC="${{ matrix.cc }}" bash "${{ matrix.script }}"
210 test "$(cat thirdparty/tcc/build_source_hash.txt)" = "$tinycc_hash"
211 thirdparty/tcc/tcc.exe --version
212 thirdparty/tcc/tcc.exe -v -v
213
214 if [ "$PUBLISH" = 'true' ]; then
215 git -C thirdparty/tcc push origin HEAD:${{ matrix.branch }}
216 fi
217