|
| 1 | +name: Build baseutils (Alpine + LLVM) |
| 2 | + |
| 3 | +concurrency: |
| 4 | + group: build-${{ github.ref }} |
| 5 | + cancel-in-progress: true |
| 6 | + |
| 7 | +on: |
| 8 | + push: |
| 9 | + branches: ['**'] |
| 10 | + tags: ['**'] |
| 11 | + workflow_dispatch: |
| 12 | + |
| 13 | +env: |
| 14 | + CC: clang |
| 15 | + AR: llvm-ar |
| 16 | + STRIP: llvm-strip |
| 17 | + LD: ld.mold |
| 18 | + CFLAGS: "-O2 -static" |
| 19 | + LDFLAGS: "-static" |
| 20 | + |
| 21 | +jobs: |
| 22 | + fetch-submodules: |
| 23 | + name: Fetch submodules |
| 24 | + runs-on: ubuntu-latest |
| 25 | + |
| 26 | + container: |
| 27 | + image: alpine:latest |
| 28 | + volumes: |
| 29 | + - /:/host |
| 30 | + - /tmp/node20:/__e/node20 |
| 31 | + |
| 32 | + steps: |
| 33 | + - name: Patch Alpine for GitHub Actions |
| 34 | + run: | |
| 35 | + apk add --no-cache nodejs npm gcompat git tar |
| 36 | + sed -i 's/^ID=.*/ID=gha/' /etc/os-release |
| 37 | + mkdir -p /__e/node20/bin |
| 38 | + ln -sf /usr/bin/node /__e/node20/bin/node |
| 39 | + ln -sf /usr/bin/npm /__e/node20/bin/npm |
| 40 | +
|
| 41 | + - uses: actions/checkout@v4 |
| 42 | + with: |
| 43 | + fetch-depth: 0 |
| 44 | + |
| 45 | + - name: Restore submodules cache |
| 46 | + id: cache-submodules |
| 47 | + uses: actions/cache/restore@v4 |
| 48 | + with: |
| 49 | + path: .git/modules |
| 50 | + key: submodules-${{ hashFiles('.gitmodules') }} |
| 51 | + |
| 52 | + - name: Fetch submodules |
| 53 | + run: | |
| 54 | + git config --global --add safe.directory "$GITHUB_WORKSPACE" |
| 55 | + git submodule update --init --recursive |
| 56 | +
|
| 57 | + - name: Save submodules cache |
| 58 | + if: steps.cache-submodules.outputs.cache-hit != 'true' |
| 59 | + uses: actions/cache/save@v4 |
| 60 | + with: |
| 61 | + path: .git/modules |
| 62 | + key: submodules-${{ hashFiles('.gitmodules') }} |
| 63 | + |
| 64 | + - name: Create submodules tarball |
| 65 | + run: | |
| 66 | + tar -czf submodules.tar.gz .git/modules |
| 67 | + apk del tar |
| 68 | +
|
| 69 | + - uses: actions/upload-artifact@v4 |
| 70 | + with: |
| 71 | + name: submodules |
| 72 | + path: submodules.tar.gz |
| 73 | + retention-days: 1 |
| 74 | + |
| 75 | + build: |
| 76 | + name: ${{ matrix.arch }} |
| 77 | + needs: fetch-submodules |
| 78 | + runs-on: ubuntu-latest |
| 79 | + |
| 80 | + container: |
| 81 | + image: alpine:latest |
| 82 | + volumes: |
| 83 | + - /:/host |
| 84 | + - /tmp/node20:/__e/node20 |
| 85 | + |
| 86 | + strategy: |
| 87 | + fail-fast: false |
| 88 | + matrix: |
| 89 | + arch: [x86_64, aarch64, i386, riscv64] |
| 90 | + |
| 91 | + steps: |
| 92 | + - name: Patch Alpine for GitHub Actions |
| 93 | + run: | |
| 94 | + apk add --no-cache nodejs npm gcompat git |
| 95 | + sed -i 's/^ID=.*/ID=gha/' /etc/os-release |
| 96 | + mkdir -p /__e/node20/bin |
| 97 | + ln -sf /usr/bin/node /__e/node20/bin/node |
| 98 | + ln -sf /usr/bin/npm /__e/node20/bin/npm |
| 99 | +
|
| 100 | + - uses: actions/checkout@v4 |
| 101 | + with: |
| 102 | + fetch-depth: 0 |
| 103 | + |
| 104 | + - uses: actions/download-artifact@v4 |
| 105 | + with: |
| 106 | + name: submodules |
| 107 | + |
| 108 | + - name: Restore submodules |
| 109 | + run: | |
| 110 | + git config --global --add safe.directory "$GITHUB_WORKSPACE" |
| 111 | + tar -xzf submodules.tar.gz |
| 112 | + git submodule update --init --recursive |
| 113 | +
|
| 114 | + - name: Install LLVM toolchain |
| 115 | + run: | |
| 116 | + apk add --no-cache \ |
| 117 | + clang llvm mold \ |
| 118 | + musl-dev make curl \ |
| 119 | + linux-headers \ |
| 120 | + binutils \ |
| 121 | + bash |
| 122 | +
|
| 123 | + # busybox is disgusting |
| 124 | + # toybox is disgusting |
| 125 | + # I've not written an alternative to them yet |
| 126 | + # So we ought to make do |
| 127 | +
|
| 128 | + #for t in ar ranlib nm objcopy objdump strip strings size readelf addr2line; do |
| 129 | + # ln -sf "/usr/bin/llvm-$t" "/usr/bin/$t" |
| 130 | + #done |
| 131 | +
|
| 132 | + ln -sfT /usr/bin/clang /usr/bin/cc |
| 133 | +
|
| 134 | + - name: Build |
| 135 | + env: |
| 136 | + ARCH: ${{ matrix.arch }} |
| 137 | + TARGET: ${{ matrix.arch }}-alpine-linux-musl |
| 138 | + run: | |
| 139 | + set -e |
| 140 | + ./cbuild.sh clean |
| 141 | + ./cbuild.sh -vvv |
| 142 | +
|
| 143 | + mkdir -p dist |
| 144 | + find . -maxdepth 1 -type f -perm -111 ! -name '*.sh' -exec mv {} dist/ \; |
| 145 | +
|
| 146 | + - name: Normalize outputs |
| 147 | + run: | |
| 148 | + for f in dist/*; do |
| 149 | + mv "$f" "dist/$(basename "$f")_${{ matrix.arch }}" |
| 150 | + done |
| 151 | +
|
| 152 | + - uses: actions/upload-artifact@v4 |
| 153 | + with: |
| 154 | + name: baseutils-${{ matrix.arch }} |
| 155 | + path: dist/* |
| 156 | + |
| 157 | + release: |
| 158 | + needs: build |
| 159 | + runs-on: ubuntu-latest |
| 160 | + if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/') |
| 161 | + |
| 162 | + steps: |
| 163 | + - uses: actions/download-artifact@v4 |
| 164 | + with: |
| 165 | + path: artifacts |
| 166 | + pattern: baseutils-* |
| 167 | + merge-multiple: true |
| 168 | + |
| 169 | + - name: Update continuous release |
| 170 | + if: github.ref == 'refs/heads/main' |
| 171 | + uses: softprops/action-gh-release@v2 |
| 172 | + with: |
| 173 | + tag_name: continuous |
| 174 | + prerelease: true |
| 175 | + files: artifacts/* |
| 176 | + |
| 177 | + - name: Update tag release |
| 178 | + if: startsWith(github.ref, 'refs/tags/') |
| 179 | + uses: softprops/action-gh-release@v2 |
| 180 | + with: |
| 181 | + tag_name: ${{ github.ref_name }} |
| 182 | + files: artifacts/* |
0 commit comments