name: Release # Push a tag such as v0.1.0 to build a static Linux binary (web UI included) # and publish it as a Gitea release. The tag must match the version in # Cargo.toml's [workspace.package], and CHANGELOG.md must have a section for # it: that section becomes the release notes. # # Written for Gitea Actions (act_runner). It lives in .github/workflows so the # CI workflow next to it keeps running too: Gitea ignores .github/workflows # once a .gitea/workflows folder exists. on: push: tags: ["v*"] permissions: contents: write env: TARGET: x86_64-unknown-linux-musl ZIG_VERSION: 0.17.0 CARGO_TERM_COLOR: always CARGO_PROFILE_RELEASE_STRIP: symbols # The Docker image is the release binary on top of this base. Alpine rather # than distroless so there's a shell for `docker exec` and post-move hooks. BASE_IMAGE: alpine:3.24 # crane builds and pushes the image without a Docker daemon. Pinned by hash. CRANE_VERSION: v0.22.1 CRANE_SHA256: 0ab7a1d6932a213aed964ce97666c3077fe691c8606413674a8b3e0b9ec4cda0 jobs: release: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Check the tag matches Cargo.toml run: | version=$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -n1) if [ "$GITHUB_REF_NAME" != "v$version" ]; then echo "::error::Tag $GITHUB_REF_NAME doesn't match Cargo.toml version $version. Bump the version or fix the tag." exit 1 fi - uses: actions/setup-node@v4 with: { node-version: 22, cache: npm, cache-dependency-path: ui/package-lock.json } # Before the long build, so a missing entry fails in seconds. - name: Read the release notes from CHANGELOG.md run: | mkdir -p dist node .github/scripts/changelog.mjs "$GITHUB_REF_NAME" > dist/release-notes.md cat dist/release-notes.md # Gitea doesn't let the workflow's own token push packages, so the image # needs a personal access token. Checked here so a missing secret fails # before the long build, not after the release is published. - name: Check the registry secrets are set env: REGISTRY_USER: ${{ secrets.REGISTRY_USER }} REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }} run: | if [ -z "$REGISTRY_USER" ] || [ -z "$REGISTRY_TOKEN" ]; then echo "::error::Set the REGISTRY_USER (your Gitea username) and REGISTRY_TOKEN (a token with package read and write) secrets under the repo's Settings → Actions → Secrets, then re-run." exit 1 fi - name: Build the UI run: | npm --prefix ui ci npm --prefix ui run check npm --prefix ui run build test -f ui/dist/index.html - uses: dtolnay/rust-toolchain@stable with: { targets: "${{ env.TARGET }}" } - uses: mlugg/setup-zig@v2 with: { version: "${{ env.ZIG_VERSION }}" } - uses: taiki-e/install-action@v2 with: { tool: cargo-zigbuild } - uses: Swatinem/rust-cache@v2 with: { key: "${{ env.TARGET }}" } - name: Test run: cargo test --workspace --locked # musl + zig gives one static binary with no glibc version to match on # the server. - name: Build run: cargo zigbuild --release --locked --target "$TARGET" -p jellymove - name: Package run: | name="jellymove-$GITHUB_REF_NAME-$TARGET" mkdir -p "dist/$name" cp "target/$TARGET/release/jellymove" deploy/jellymove.service \ config.example.toml README.md "dist/$name/" "dist/$name/jellymove" --version tar -C dist -czf "dist/$name.tar.gz" "$name" (cd dist && sha256sum "$name.tar.gz" > "$name.tar.gz.sha256") echo "ASSET=dist/$name.tar.gz" >> "$GITHUB_ENV" - name: Publish the release env: GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: >- node .github/scripts/gitea-release.mjs "$GITHUB_REF_NAME" dist/release-notes.md "$ASSET" "$ASSET.sha256" - name: Install crane run: | curl -fsSLo crane.tar.gz "https://github.com/google/go-containerregistry/releases/download/$CRANE_VERSION/go-containerregistry_Linux_x86_64.tar.gz" echo "$CRANE_SHA256 crane.tar.gz" | sha256sum -c - mkdir -p "$HOME/.local/bin" tar -xzf crane.tar.gz -C "$HOME/.local/bin" crane rm crane.tar.gz echo "$HOME/.local/bin" >> "$GITHUB_PATH" # Pushes //jellymove:, plus :latest unless the # tag is a pre-release. - name: Publish the Docker image env: REGISTRY_USER: ${{ secrets.REGISTRY_USER }} REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }} run: | registry="${GITHUB_SERVER_URL#*://}" registry="${registry%%/*}" image="$registry/$(echo "$GITHUB_REPOSITORY" | tr '[:upper:]' '[:lower:]')" version="${GITHUB_REF_NAME#v}" echo "$REGISTRY_TOKEN" | crane auth login "$registry" -u "$REGISTRY_USER" --password-stdin mkdir -p dist/image/usr/local/bin install -m 755 "target/$TARGET/release/jellymove" dist/image/usr/local/bin/jellymove tar -C dist/image --owner=0 --group=0 --numeric-owner -cf dist/image.tar usr crane append --platform linux/amd64 -b "$BASE_IMAGE" -f dist/image.tar -t "$image:$version" crane mutate "$image:$version" -t "$image:$version" \ --entrypoint /usr/local/bin/jellymove --cmd run \ --env JELLYMOVE_CONFIG=/config/jellymove.toml \ --exposed-ports 8097/tcp --workdir / \ --label "org.opencontainers.image.source=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY" \ --label "org.opencontainers.image.version=$version" \ --label "org.opencontainers.image.revision=$GITHUB_SHA" case "$GITHUB_REF_NAME" in *-*) echo "Pre-release: not moving :latest" ;; *) crane tag "$image:$version" latest ;; esac crane config "$image:$version" echo "Pushed $image:$version"