name: Publish block release on: workflow_dispatch: push: tags: - "seaweed-block/v*" permissions: contents: write packages: write env: REGISTRY: ghcr.io BLOCK_IMAGE: ghcr.io/seaweedfs/seaweed-block CSI_IMAGE: ghcr.io/seaweedfs/seaweed-block-csi jobs: publish: # Publish only from a version tag; a manual run from a branch must not move :alpha. if: startsWith(github.ref, 'refs/tags/seaweed-block/v') runs-on: ubuntu-latest steps: - name: Runner free space working-directory: ${{ runner.temp }} run: | python3 -I - <<'PY' import os import shutil import sys required = 10_000_000_000 for path in dict.fromkeys((os.environ["GITHUB_WORKSPACE"], os.environ["RUNNER_TEMP"])): try: free = shutil.disk_usage(path).free except OSError as err: print(f"runner_disk_check_failed path={path!r} error={err}") sys.exit(75) if free < required: print(f"runner_disk_low path={path!r} free_bytes={free} required_bytes={required}") sys.exit(75) print(f"runner_disk_ok path={path!r} free_bytes={free} required_bytes={required}") PY - name: Checkout uses: actions/checkout@v4 with: fetch-depth: 0 # the tag list decides whether :alpha moves - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Log in to GHCR uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Compute image tags id: tags shell: bash run: | set -euo pipefail # vX.Y.Z-pre (a release candidate) publishes only its own version tag. A stable vX.Y.Z also # publishes sha-*, and moves :alpha only when it is the highest stable version tag, so a later # patch on an older line never moves :alpha back. short_sha="${GITHUB_SHA::12}" version="${GITHUB_REF_NAME#seaweed-block/}" if [[ ! "${version}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.]+)?$ ]]; then echo "refusing to publish: tag ${version} is not vX.Y.Z or vX.Y.Z-pre" >&2 exit 1 fi notes="seaweed-block/docs/releases/${version%%-*}.md" if [[ ! -s "${notes}" ]]; then echo "refusing to publish: release notes ${notes} are missing or empty" >&2 exit 1 fi echo "notes=${notes}" >> "$GITHUB_OUTPUT" stable=false move_alpha=false if [[ "${version}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then stable=true highest="$(git tag -l 'seaweed-block/v*' | sed 's|^seaweed-block/||' | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -n 1)" if [[ "${version}" == "${highest}" ]]; then move_alpha=true fi fi { echo "block_tags<> "$GITHUB_OUTPUT" - name: Build and push block image id: block uses: docker/build-push-action@v6 with: context: . file: .github/dockerfiles/block-sw-block.Dockerfile platforms: linux/amd64 push: true tags: ${{ steps.tags.outputs.block_tags }} - name: Build and push CSI image uses: docker/build-push-action@v6 with: context: . file: .github/dockerfiles/block-blockcsi.Dockerfile platforms: linux/amd64 push: true tags: ${{ steps.tags.outputs.csi_tags }} - name: Publish matching binary tarball env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} BLOCK_DIGEST: ${{ steps.block.outputs.digest }} NOTES: ${{ steps.tags.outputs.notes }} shell: bash run: | set -euo pipefail version="${GITHUB_REF_NAME#seaweed-block/}" out="$RUNNER_TEMP/block-release" mkdir -p "$out/bin" docker pull "${BLOCK_IMAGE}@${BLOCK_DIGEST}" container=$(docker create "${BLOCK_IMAGE}@${BLOCK_DIGEST}") trap 'docker rm "$container" >/dev/null' EXIT for binary in blockmaster blockvolume sw-block; do docker cp "$container:/usr/local/bin/$binary" "$out/bin/$binary" done bash seaweed-block/scripts/refuse-lab-binary.sh "$out/bin/"* asset="sw-block-${version}-linux-amd64.tar.gz" tar -C "$out/bin" -czf "$out/$asset" blockmaster blockvolume sw-block (cd "$out" && sha256sum "$asset" >SHA256SUMS) prerelease=false if [[ "$version" == *-* ]]; then prerelease=true; fi # A rerun replaces the assets, then publishes a draft an interrupted run left. if gh release view "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then gh release upload "$GITHUB_REF_NAME" "$out/$asset" "$out/SHA256SUMS" --repo "$GITHUB_REPOSITORY" --clobber gh release edit "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" --prerelease="$prerelease" --draft=false --latest=false else gh release create "$GITHUB_REF_NAME" "$out/$asset" "$out/SHA256SUMS" --repo "$GITHUB_REPOSITORY" --verify-tag --latest=false \ --prerelease="$prerelease" --title "Seaweed Block $version" --notes-file "$NOTES" fi - name: Clean job workspace # Hosted runners are disposable; their setup-go cache upload runs in # a post action and still needs the checkout. Persistent runners do not # upload that cache, and must release their checkout/build files here. if: always() && runner.environment == 'self-hosted' working-directory: ${{ runner.temp }} run: | python3 -I - <<'PY' import os from pathlib import Path import shutil import sys root = Path(os.environ["GITHUB_WORKSPACE"]) # Refuse aliases rather than resolving them. Open EVERY component without # following symlinks, then keep cleanup anchored to the verified directory fd. if not root.is_absolute() or ".." in root.parts or root == Path(root.anchor) or root.name != root.parent.name or root == Path(os.environ["RUNNER_TEMP"]): print(f"runner_workspace_cleanup_refused path={str(root)!r}") sys.exit(1) flags = os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW fd = os.open(root.anchor, flags) previous = os.open(".", flags) errors = [] try: for part in root.parts[1:]: child = os.open(part, flags, dir_fd=fd) os.close(fd) fd = child if not shutil.rmtree.avoids_symlink_attacks: raise OSError("descriptor-safe directory removal is unavailable") os.fchdir(fd) for entry in os.scandir("."): try: if entry.is_dir(follow_symlinks=False): shutil.rmtree(entry.name) else: os.unlink(entry.name) except OSError as err: errors.append(f"{entry.name}: {err}") except OSError as err: print(f"runner_workspace_cleanup_refused path={str(root)!r} error={err}") sys.exit(1) finally: os.fchdir(previous) os.close(previous) os.close(fd) if errors: print("runner_workspace_cleanup_failed " + "; ".join(errors)) sys.exit(1) print(f"runner_workspace_clean path={str(root)!r}") PY