Skip to content

Commit a6fa386

Browse files
authored
fix(ci): check R2 when --version is provided to gap detector (#232)
1 parent dd2fd89 commit a6fa386

2 files changed

Lines changed: 24 additions & 11 deletions

File tree

.github/workflows/build-ruby-from-source.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,10 @@ jobs:
4545
R2_ACCESS_KEY: ${{ secrets.CLOUDFLARE_R2_ACCESS_KEY_ID }}
4646
R2_SECRET_KEY: ${{ secrets.CLOUDFLARE_R2_SECRET_ACCESS_KEY }}
4747
run: |
48-
ARGS=""
48+
R2_ARGS="--r2-endpoint=$R2_ENDPOINT --r2-bucket=$R2_BUCKET --r2-access-key=$R2_ACCESS_KEY --r2-secret-key=$R2_SECRET_KEY"
49+
ARGS="$R2_ARGS"
4950
if [ -n "${{ inputs.version }}" ]; then
50-
ARGS="--version=${{ inputs.version }}"
51-
else
52-
ARGS="--r2-endpoint=$R2_ENDPOINT --r2-bucket=$R2_BUCKET --r2-access-key=$R2_ACCESS_KEY --r2-secret-key=$R2_SECRET_KEY"
51+
ARGS="--version=${{ inputs.version }} $R2_ARGS"
5352
fi
5453
5554
MATRIX=$(./scripts/detect-ruby-gaps/detect-ruby-gaps $ARGS)

scripts/detect-ruby-gaps/main.go

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ var allPlatforms = []Platform{
5050
}
5151

5252
var (
53-
versionFlag = flag.String("version", "", "Force all 6 platforms for this version (no R2 check)")
53+
versionFlag = flag.String("version", "", "Build missing platforms for this version (checks R2 if credentials provided, otherwise all platforms)")
5454
r2Endpoint = flag.String("r2-endpoint", "", "R2 endpoint URL")
5555
r2Bucket = flag.String("r2-bucket", "", "R2 bucket name")
5656
r2AccessKey = flag.String("r2-access-key", "", "R2 access key ID")
@@ -77,17 +77,31 @@ var httpClient = &http.Client{
7777
func main() {
7878
flag.Parse()
7979

80-
// If --version is provided, output all 6 platforms without R2 check
80+
hasR2Creds := *r2Endpoint != "" && *r2Bucket != "" && *r2AccessKey != "" && *r2SecretKey != ""
81+
8182
if *versionFlag != "" {
82-
matrix := buildMatrixForVersion(*versionFlag)
83-
outputMatrix(matrix)
83+
// --version provided: check R2 if credentials available, otherwise output all platforms
84+
if hasR2Creds {
85+
fmt.Fprintf(os.Stderr, "Checking R2 for existing builds of Ruby %s...\n", *versionFlag)
86+
existingMeta, err := fetchExistingMeta()
87+
if err != nil {
88+
fmt.Fprintf(os.Stderr, "Error fetching R2 metadata: %v\n", err)
89+
os.Exit(1)
90+
}
91+
matrix := computeGaps([]string{*versionFlag}, existingMeta)
92+
fmt.Fprintf(os.Stderr, "Detected %d missing platforms for %s\n", len(matrix.Include), *versionFlag)
93+
outputMatrix(matrix)
94+
} else {
95+
fmt.Fprintln(os.Stderr, "No R2 credentials provided, outputting all platforms")
96+
matrix := buildMatrixForVersion(*versionFlag)
97+
outputMatrix(matrix)
98+
}
8499
return
85100
}
86101

87-
// Otherwise, detect gaps by comparing upstream vs R2
88-
if *r2Endpoint == "" || *r2Bucket == "" || *r2AccessKey == "" || *r2SecretKey == "" {
102+
// No --version: full auto-detect requires R2 credentials
103+
if !hasR2Creds {
89104
fmt.Fprintln(os.Stderr, "Error: R2 credentials required (--r2-endpoint, --r2-bucket, --r2-access-key, --r2-secret-key)")
90-
fmt.Fprintln(os.Stderr, " Or use --version=X to force all platforms for a specific version")
91105
os.Exit(1)
92106
}
93107

0 commit comments

Comments
 (0)