name: "go: build dev binaries" on: push: branches: [ master ] paths: - 'weed/**' - 'go.mod' - 'go.sum' - '.github/workflows/binaries_dev.yml' workflow_dispatch: # Let an in-progress dev build finish. A new push replaces only the pending # run; cancelling mid-build left the dev release without assets. concurrency: group: binaries-dev-${{ github.ref }} cancel-in-progress: false permissions: contents: read jobs: prepare: runs-on: ubuntu-latest outputs: build_time: ${{ steps.build_time.outputs.value }} steps: - name: Ref guard if: github.ref != 'refs/heads/master' env: GH_REF: ${{ github.ref }} run: | echo "dev builds only publish from master (got $GH_REF)" >&2 exit 1 - name: Set BUILD_TIME id: build_time run: | echo "value=$(date -u +%Y%m%d-%H%M)" >> "$GITHUB_OUTPUT" build_dev_linux_windows: permissions: contents: write # for wangyoucao577/go-release-action to upload release assets needs: prepare runs-on: ubuntu-latest env: BUILD_TIME: ${{ needs.prepare.outputs.build_time }} strategy: matrix: goos: [linux, windows] goarch: [amd64] steps: - name: Validate BUILD_TIME run: | : "${BUILD_TIME:?prepare output missing}" - name: Check out code into the Go module directory uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v2 - name: Go Release Binaries Large Disk uses: wangyoucao577/go-release-action@279495102627de7960cbc33434ab01a12bae144b # v1.22 with: goversion: go.mod # reads the go directive, so releases build with the toolchain go.mod declares github_token: ${{ secrets.GITHUB_TOKEN }} goos: ${{ matrix.goos }} goarch: ${{ matrix.goarch }} release_tag: dev overwrite: true pre_command: export CGO_ENABLED=0 && export GODEBUG=http2client=0 build_flags: -tags 5BytesOffset # optional, default is ldflags: -s -w -extldflags -static -X github.com/seaweedfs/seaweedfs/weed/util/version.COMMIT=${{github.sha}} # Where to run `go build .` project_path: weed binary_name: weed-large-disk asset_name: "weed-large-disk-${{ env.BUILD_TIME }}-${{ matrix.goos }}-${{ matrix.goarch }}" - name: Go Release Binaries Normal Volume Size uses: wangyoucao577/go-release-action@279495102627de7960cbc33434ab01a12bae144b # v1.22 with: goversion: go.mod # reads the go directive, so releases build with the toolchain go.mod declares github_token: ${{ secrets.GITHUB_TOKEN }} goos: ${{ matrix.goos }} goarch: ${{ matrix.goarch }} release_tag: dev overwrite: true pre_command: export CGO_ENABLED=0 && export GODEBUG=http2client=0 ldflags: -s -w -extldflags -static -X github.com/seaweedfs/seaweedfs/weed/util/version.COMMIT=${{github.sha}} # Where to run `go build .` project_path: weed binary_name: weed-normal-disk asset_name: "weed-${{ env.BUILD_TIME }}-${{ matrix.goos }}-${{ matrix.goarch }}" build_dev_darwin: permissions: contents: write # for wangyoucao577/go-release-action to upload release assets needs: [prepare, build_dev_linux_windows] runs-on: ubuntu-latest env: BUILD_TIME: ${{ needs.prepare.outputs.build_time }} strategy: matrix: goos: [darwin] goarch: [amd64, arm64] steps: - name: Validate BUILD_TIME run: | : "${BUILD_TIME:?prepare output missing}" - name: Check out code into the Go module directory uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v2 - name: Go Release Binaries Large Disk uses: wangyoucao577/go-release-action@279495102627de7960cbc33434ab01a12bae144b # v1.22 with: goversion: go.mod # reads the go directive, so releases build with the toolchain go.mod declares github_token: ${{ secrets.GITHUB_TOKEN }} goos: ${{ matrix.goos }} goarch: ${{ matrix.goarch }} release_tag: dev overwrite: true pre_command: export CGO_ENABLED=0 && export GODEBUG=http2client=0 build_flags: -tags 5BytesOffset # optional, default is ldflags: -s -w -extldflags -static -X github.com/seaweedfs/seaweedfs/weed/util/version.COMMIT=${{github.sha}} # Where to run `go build .` project_path: weed binary_name: weed-large-disk asset_name: "weed-large-disk-${{ env.BUILD_TIME }}-${{ matrix.goos }}-${{ matrix.goarch }}" - name: Go Release Binaries Normal Volume Size uses: wangyoucao577/go-release-action@279495102627de7960cbc33434ab01a12bae144b # v1.22 with: goversion: go.mod # reads the go directive, so releases build with the toolchain go.mod declares github_token: ${{ secrets.GITHUB_TOKEN }} goos: ${{ matrix.goos }} goarch: ${{ matrix.goarch }} release_tag: dev overwrite: true pre_command: export CGO_ENABLED=0 && export GODEBUG=http2client=0 ldflags: -s -w -extldflags -static -X github.com/seaweedfs/seaweedfs/weed/util/version.COMMIT=${{github.sha}} # Where to run `go build .` project_path: weed binary_name: weed-normal-disk asset_name: "weed-${{ env.BUILD_TIME }}-${{ matrix.goos }}-${{ matrix.goarch }}" prune: needs: [prepare, build_dev_linux_windows, build_dev_darwin] runs-on: ubuntu-latest timeout-minutes: 15 permissions: contents: write env: BUILD_TIME: ${{ needs.prepare.outputs.build_time }} RELEASE_TAG: dev steps: - name: Delete dev binaries from older builds env: GH_TOKEN: ${{ github.token }} run: | set -euo pipefail : "${BUILD_TIME:?BUILD_TIME is empty}" case "$BUILD_TIME" in [0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]) ;; *) echo "Invalid BUILD_TIME: $BUILD_TIME" >&2; exit 1 ;; esac release_tag="${RELEASE_TAG:-dev}" if ! release_json=$(gh api "repos/$GITHUB_REPOSITORY/releases/tags/$release_tag" 2>&1); then case "$release_json" in *"Not Found"*) echo "No $release_tag release; nothing to prune"; exit 0 ;; esac echo "Release lookup failed: $release_json" >&2 exit 1 fi release_id=$(jq -r '.id // empty' <<<"$release_json") if [ -z "$release_id" ]; then echo "Release lookup returned no id" >&2 exit 1 fi assets_file=$(mktemp) trap 'rm -f "$assets_file"' EXIT if ! gh api "repos/$GITHUB_REPOSITORY/releases/$release_id/assets" --paginate \ --jq '.[] | select((.name | startswith("weed-large-disk-")) or (.name | test("^weed-[0-9]"))) | [.id, .name] | @tsv' \ > "$assets_file"; then echo "Failed to list release assets" >&2 exit 1 fi total=$(awk 'END{print NR+0}' "$assets_file") matching=$(awk -v s="-$BUILD_TIME-" 'index($0,s){n++} END{print n+0}' "$assets_file") if [ "$matching" -eq 0 ]; then echo "No assets carry stamp $BUILD_TIME; refusing to prune" >&2 exit 1 fi build_key=${BUILD_TIME/-/} kept=0; newer=0; deleted=0; gone=0; failed=0 while IFS=$'\t' read -r id name || [ -n "${name:-}" ]; do [ -n "${id:-}" ] || continue case "$name" in *"-$BUILD_TIME-"*) kept=$((kept+1)); continue ;; esac if [[ "$name" =~ -([0-9]{8})-([0-9]{4})- ]] && [ "${BASH_REMATCH[1]}${BASH_REMATCH[2]}" -gt "$build_key" ]; then newer=$((newer+1)); continue fi if out=$(gh api -X DELETE "repos/$GITHUB_REPOSITORY/releases/assets/$id" &1); then deleted=$((deleted+1)) else case "$out" in *"Not Found"*) gone=$((gone+1)) ;; *) failed=$((failed+1)); echo "Failed to delete asset $name ($id): $out" >&2 ;; esac fi done < "$assets_file" [ "$((kept+newer+deleted+gone+failed))" -eq "$total" ] || { echo "Processed $((kept+newer+deleted+gone+failed)) of $total assets" >&2; exit 1; } echo "Kept $kept assets from this build and $newer from newer builds; deleted $deleted older assets; $gone already gone; $failed failures" [ "$failed" -eq 0 ] || { echo "::warning::prune: $failed deletions failed"; exit 1; }