diff --git a/.github/workflows/build-ruby-from-source.yml b/.github/workflows/build-ruby-from-source.yml index 184d3b6..6744063 100644 --- a/.github/workflows/build-ruby-from-source.yml +++ b/.github/workflows/build-ruby-from-source.yml @@ -45,11 +45,10 @@ jobs: R2_ACCESS_KEY: ${{ secrets.CLOUDFLARE_R2_ACCESS_KEY_ID }} R2_SECRET_KEY: ${{ secrets.CLOUDFLARE_R2_SECRET_ACCESS_KEY }} run: | - ARGS="" + R2_ARGS="--r2-endpoint=$R2_ENDPOINT --r2-bucket=$R2_BUCKET --r2-access-key=$R2_ACCESS_KEY --r2-secret-key=$R2_SECRET_KEY" + ARGS="$R2_ARGS" if [ -n "${{ inputs.version }}" ]; then - ARGS="--version=${{ inputs.version }}" - else - ARGS="--r2-endpoint=$R2_ENDPOINT --r2-bucket=$R2_BUCKET --r2-access-key=$R2_ACCESS_KEY --r2-secret-key=$R2_SECRET_KEY" + ARGS="--version=${{ inputs.version }} $R2_ARGS" fi MATRIX=$(./scripts/detect-ruby-gaps/detect-ruby-gaps $ARGS) diff --git a/scripts/detect-ruby-gaps/main.go b/scripts/detect-ruby-gaps/main.go index 2105db6..44d1a0c 100644 --- a/scripts/detect-ruby-gaps/main.go +++ b/scripts/detect-ruby-gaps/main.go @@ -50,7 +50,7 @@ var allPlatforms = []Platform{ } var ( - versionFlag = flag.String("version", "", "Force all 6 platforms for this version (no R2 check)") + versionFlag = flag.String("version", "", "Build missing platforms for this version (checks R2 if credentials provided, otherwise all platforms)") r2Endpoint = flag.String("r2-endpoint", "", "R2 endpoint URL") r2Bucket = flag.String("r2-bucket", "", "R2 bucket name") r2AccessKey = flag.String("r2-access-key", "", "R2 access key ID") @@ -77,17 +77,31 @@ var httpClient = &http.Client{ func main() { flag.Parse() - // If --version is provided, output all 6 platforms without R2 check + hasR2Creds := *r2Endpoint != "" && *r2Bucket != "" && *r2AccessKey != "" && *r2SecretKey != "" + if *versionFlag != "" { - matrix := buildMatrixForVersion(*versionFlag) - outputMatrix(matrix) + // --version provided: check R2 if credentials available, otherwise output all platforms + if hasR2Creds { + fmt.Fprintf(os.Stderr, "Checking R2 for existing builds of Ruby %s...\n", *versionFlag) + existingMeta, err := fetchExistingMeta() + if err != nil { + fmt.Fprintf(os.Stderr, "Error fetching R2 metadata: %v\n", err) + os.Exit(1) + } + matrix := computeGaps([]string{*versionFlag}, existingMeta) + fmt.Fprintf(os.Stderr, "Detected %d missing platforms for %s\n", len(matrix.Include), *versionFlag) + outputMatrix(matrix) + } else { + fmt.Fprintln(os.Stderr, "No R2 credentials provided, outputting all platforms") + matrix := buildMatrixForVersion(*versionFlag) + outputMatrix(matrix) + } return } - // Otherwise, detect gaps by comparing upstream vs R2 - if *r2Endpoint == "" || *r2Bucket == "" || *r2AccessKey == "" || *r2SecretKey == "" { + // No --version: full auto-detect requires R2 credentials + if !hasR2Creds { fmt.Fprintln(os.Stderr, "Error: R2 credentials required (--r2-endpoint, --r2-bucket, --r2-access-key, --r2-secret-key)") - fmt.Fprintln(os.Stderr, " Or use --version=X to force all platforms for a specific version") os.Exit(1) }