Zig CI Setup on Codeberg

Does anyone have an example of using community mirrors properly with codeberg CI?

I imagine I would use something like an alpine container that downloads zig. Not sure yet though.

I’m not sure if anything exists for Woodpecker, but FWIW, Codeberg supports Forgejo Actions, which has sufficient compatibility with GitHub Actions that setup-zig pretty much just works.

The docs do explicitly state that they prefer woodpecker, at least for now.

“Due to outstanding security issues and bus factor (we need more maintainers for our CI service), we are currently providing hosted Actions in limited fashion: see actions/meta: Information and discussions around hosted Forgejo Actions at Codeberg - Codeberg.org. If you need Codeberg to host your CI, please use Woodpecker CI instead.”

Liza provides Woodpecker CI and Forgejo Actions setups. Woodpecker CI often requires manual steps, like generating Access Tokens and granting permissions, see README for details:

came back to this recently, hoping to come up with a setup that doesn’t rely on someone else’s docker image build

A bit late to the party here, but I think it’s safe to say that Forgejo Actions is the preferred CI solution now. It has many active maintainers and we’ve been using it quite successfully for Zig since we migrated to Codeberg. This page probably needs an update.

well shucks what am I supposed to do with this kickass downloader script i just wrote! :slight_smile:

set -ex

# change this to upgrade zig
tarball_name='zig-x86_64-linux-0.16.0.tar.xz'

# tells mirror who is downloading for stats
source='jeffs_bash_script'
# pubkey obtained from https://ziglang.org/download
pubkey='RWSGOq2NVecA2UPNdBUZykf1CCb147pkmdtYxgb3Ti+JO/wCYvhbAb/U'

# ASCII-encoded, one mirror per line, newlines are LF, there is a trailing newline.
mirrors=$(curl --fail https://ziglang.org/download/community-mirrors.txt)

success=0
set +e
for i in {1..5}; do
    {
        mirror_url=$(echo "$mirrors" | shuf -n 1)
        tarball_url="${mirror_url}/${tarball_name}?source=${source}"
        signature_url="${mirror_url}/${tarball_name}.minisig?source=${source}"
        curl --fail -o "${tarball_name}.minisig" "$signature_url"
        curl --fail -o "$tarball_name" "$tarball_url"
        minisign -V -P "$pubkey" -m "$tarball_name"
        success=1
        break
    } || continue;
done
set -e

if [ $success -eq 0 ]; then
    echo "failed to download zig"
    exit 1
fi

mkdir zig
tar --strip-components 1 -xf "$tarball_name" -C zig
chmod +x zig/zig
zig/zig version
echo "success: zig accessible at zig/zig"

I’m bookmarking it! I prefer Woodpecker to Actions, so I’ll put it to good use at some point. Thanks for sharing :wink:

By the way, you should probably have the mirrors checked in somewhere in a repo instead of pulling them from ziglang.org every time, because like this, if ziglang.org is down, you have no mirrors, kinda defeating the purpose :slight_smile:

heres what I came up with, it runs a zig build ci step in an alpine container, downloading zig using the mirrors, curl, minisign, and /bin/sh

and @spiffyk I fixed it to have a list of fallback mirrors if ziglang.org is down like you suggested, thanks!

.woodpecker/ci.yaml

when:
  - event: pull_request
  - event: push
    branch: main

steps:
  - name: build
    image: alpine
    entrypoint: ["/bin/sh", "-c", "./.woodpecker/ci.sh"]

.woodpecker/ci.sh

# intended to be run inside an alpine container 
# downloads zig to ./zig/zig using community mirrors, verifies signature
set -ex

# change this to upgrade zig
tarball_name='zig-x86_64-linux-0.16.0.tar.xz'

# curl for downloading zig
# minisign for signature verification
apk add curl minisign

# tells mirror who is downloading for stats
source='jeffs_bash_script'
# pubkey obtained from https://ziglang.org/download
pubkey='RWSGOq2NVecA2UPNdBUZykf1CCb147pkmdtYxgb3Ti+JO/wCYvhbAb/U'

# ASCII-encoded, one mirror per line, newlines are LF, there is a trailing newline.
fallback_mirrors='https://pkg.hexops.org/zig
https://zigmirror.hryx.net/zig
https://zig.linus.dev/zig
https://zig.squirl.dev
https://zig.mirror.mschae23.de/zig
https://ziglang.freetls.fastly.net
https://zig.tilok.dev
https://zig-mirror.tsimnet.eu/zig
https://zig.karearl.com/zig
https://pkg.earth/zig
https://fs.liujiacai.net/zigbuilds
https://zigmirror.com
https://zig.chainsafe.dev
https://zig.savalione.com
'

set +e
mirrors=$(curl --fail https://ziglang.org/download/community-mirrors.txt) || mirrors="$fallback_mirrors"
set -e

success=0
set +e
for i in 1 2 3 4 5; do
    mirror_url=$(echo "$mirrors" | shuf -n 1)
    tarball_url="${mirror_url}/${tarball_name}?source=${source}"
    signature_url="${mirror_url}/${tarball_name}.minisig?source=${source}"

    if 
        curl --fail -o "${tarball_name}.minisig" "$signature_url" &&
        curl --fail -o "$tarball_name" "$tarball_url" &&
        minisign -V -P "$pubkey" -m "$tarball_name";
    then
        success=1
        break
    fi
done
set -e

if [ $success -eq 0 ]; then
    echo "failed to download zig"
    exit 1
fi

mkdir zig
tar --strip-components 1 -xf "$tarball_name" -C zig
chmod +x zig/zig
zig/zig version
echo "success! zig accessible at zig/zig"
zig/zig build ci --summary all
example ci output
+ tarball_name=zig-x86_64-linux-0.16.0.tar.xz
+ apk add curl minisign
( 1/12) Installing brotli-libs (1.2.0-r0)
( 2/12) Installing c-ares (1.34.6-r0)
( 3/12) Installing libunistring (1.4.1-r0)
( 4/12) Installing libidn2 (2.3.8-r0)
( 5/12) Installing nghttp2-libs (1.68.0-r0)
( 6/12) Installing nghttp3 (1.13.1-r0)
( 7/12) Installing libpsl (0.21.5-r3)
( 8/12) Installing zstd-libs (1.5.7-r2)
( 9/12) Installing libcurl (8.17.0-r1)
(10/12) Installing curl (8.17.0-r1)
(11/12) Installing libsodium (1.0.20-r1)
(12/12) Installing minisign (0.12-r1)
Executing busybox-1.37.0-r30.trigger
OK: 13.6 MiB in 28 packages
+ source=jeffs_bash_script
+ pubkey=RWSGOq2NVecA2UPNdBUZykf1CCb147pkmdtYxgb3Ti+JO/wCYvhbAb/U
+ fallback_mirrors='https://pkg.hexops.org/zig
https://zigmirror.hryx.net/zig
https://zig.linus.dev/zig
https://zig.squirl.dev
https://zig.mirror.mschae23.de/zig
https://ziglang.freetls.fastly.net
https://zig.tilok.dev
https://zig-mirror.tsimnet.eu/zig
https://zig.karearl.com/zig
https://pkg.earth/zig
https://fs.liujiacai.net/zigbuilds
https://zigmirror.com
https://zig.chainsafe.dev
https://zig.savalione.com
'
+ set +e
+ curl --fail https://ziglang.org/download/community-mirrors.txt
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0   0     0   0     0     0     0  --:--:-- --:--:-- --:--:--     0
100   392 100   392   0     0  1137     0  --:--:-- --:--:-- --:--:--  1142
+ mirrors='https://pkg.hexops.org/zig
https://zigmirror.hryx.net/zig
https://zig.linus.dev/zig
https://zig.squirl.dev
https://zig.mirror.mschae23.de/zig
https://ziglang.freetls.fastly.net
https://zig.tilok.dev
https://zig-mirror.tsimnet.eu/zig
https://zig.karearl.com/zig
https://pkg.earth/zig
https://fs.liujiacai.net/zigbuilds
https://zigmirror.com
https://zig.chainsafe.dev
https://zig.savalione.com'
+ set -e
+ success=0
+ set +e
+ echo 'https://pkg.hexops.org/zig
https://zigmirror.hryx.net/zig
https://zig.linus.dev/zig
https://zig.squirl.dev
https://zig.mirror.mschae23.de/zig
https://ziglang.freetls.fastly.net
https://zig.tilok.dev
https://zig-mirror.tsimnet.eu/zig
https://zig.karearl.com/zig
https://pkg.earth/zig
https://fs.liujiacai.net/zigbuilds
https://zigmirror.com
https://zig.chainsafe.dev
https://zig.savalione.com'
+ shuf -n 1
+ mirror_url=https://zig.chainsafe.dev
+ tarball_url='https://zig.chainsafe.dev/zig-x86_64-linux-0.16.0.tar.xz?source=jeffs_bash_script'
+ signature_url='https://zig.chainsafe.dev/zig-x86_64-linux-0.16.0.tar.xz.minisig?source=jeffs_bash_script'
+ curl --fail -o zig-x86_64-linux-0.16.0.tar.xz.minisig 'https://zig.chainsafe.dev/zig-x86_64-linux-0.16.0.tar.xz.minisig?source=jeffs_bash_script'
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0   0     0   0     0     0     0  --:--:-- --:--:-- --:--:--     0
100   325 100   325   0     0  2084     0  --:--:-- --:--:-- --:--:--  2110
+ curl --fail -o zig-x86_64-linux-0.16.0.tar.xz 'https://zig.chainsafe.dev/zig-x86_64-linux-0.16.0.tar.xz?source=jeffs_bash_script'
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0   0     0   0     0     0     0  --:--:-- --:--:-- --:--:--     0
 48 54178k  48 26498k   0     0 87996k     0  --:--:-- --:--:-- --:--:-- 88034k
100 54178k 100 54178k   0     0 76449k     0  --:--:-- --:--:-- --:--:-- 76522k
+ minisign -V -P RWSGOq2NVecA2UPNdBUZykf1CCb147pkmdtYxgb3Ti+JO/wCYvhbAb/U -m zig-x86_64-linux-0.16.0.tar.xz
Signature and comment signature verified
Trusted comment: timestamp:1776173777	file:zig-x86_64-linux-0.16.0.tar.xz	hashed
+ success=1
+ break
+ set -e
+ '[' 1 -eq 0 ]
+ mkdir zig
+ tar --strip-components 1 -xf zig-x86_64-linux-0.16.0.tar.xz -C zig
+ chmod +x zig/zig
+ zig/zig version
0.16.0
success! zig accessible at zig/zig
+ echo 'success! zig accessible at zig/zig'
+ zig/zig build ci --summary all
Build Summary: 27/27 steps succeeded; 6/6 tests passed
ci success
+- test success
|  +- run test 6 pass (6 total) 17ms MaxRSS:6M
|  |  +- compile test Debug native success 663ms MaxRSS:167M
|  +- install hello_world success
|     +- compile exe hello_world Debug native success 575ms MaxRSS:155M
+- install-tool success
|  +- install oci_builder success
|     +- compile exe oci_builder Debug native success 2s MaxRSS:256M
+- create-index success
|  +- install generated to index.json success
|  |  +- create-index success 16ms
|  |     +- compile exe oci_builder Debug native (reused)
|  |     +- create-manifest success 31ms
|  |     |  +- compile exe oci_builder Debug native (reused)
|  |     |  +- create-layer success 34ms
|  |     |  |  +- compile exe oci_builder Debug native (reused)
|  |     |  +- create-layer (+1 more reused dependencies)
|  |     |  +- create-layer (+1 more reused dependencies)
|  |     |  +- create-layer success 10s
|  |     |  |  +- compile exe oci_builder Debug native (reused)
|  |     |  |  +- compile exe hello_world Debug native (reused)
|  |     |  |  +- compile exe hello_world Debug native (reused)
|  |     |  +- create-layer (+3 more reused dependencies)
|  |     |  +- create-layer (+3 more reused dependencies)
|  |     |  +- create-layer success 32ms
|  |     |  |  +- compile exe oci_builder Debug native (reused)
|  |     |  +- create-layer (+1 more reused dependencies)
|  |     |  +- create-layer (+1 more reused dependencies)
|  |     +- create-manifest (+10 more reused dependencies)
|  +- install generated to layout.tar.gz success
|     +- create-layout success 41ms
|        +- compile exe oci_builder Debug native (reused)
|        +- create-index (+3 more reused dependencies)
|        +- create-index (+3 more reused dependencies)
|        +- create-manifest (+10 more reused dependencies)
|        +- create-manifest (+10 more reused dependencies)
|        +- create-manifest (+10 more reused dependencies)
|        +- create-manifest (+10 more reused dependencies)
|        +- create-layer (+1 more reused dependencies)
|        +- create-layer (+1 more reused dependencies)
|        +- create-layer (+3 more reused dependencies)
|        +- create-layer (+3 more reused dependencies)
|        +- create-layer (+1 more reused dependencies)
|        +- create-layer (+1 more reused dependencies)
+- create-manifest success
|  +- install generated to manifest.json success
|  |  +- create-manifest (+10 more reused dependencies)
|  +- install generated to manifest_descriptor.json success
|  |  +- create-manifest (+10 more reused dependencies)
|  +- install generated to config.json success
|  |  +- create-manifest (+10 more reused dependencies)
|  +- install generated to config_descriptor.json success
|     +- create-manifest (+10 more reused dependencies)
+- create-layer success
|  +- install generated to layer_2.tar.gz success
|     +- create-layer (+3 more reused dependencies)
+- oci-dir success
   +- install generated/ success
      +- create-layout (+13 more reused dependencies)

from repo: https://codeberg.org/jeffective/oci