github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/.github/cloud-compatibility-check.rb (about) 1 #!/usr/bin/env ruby 2 3 require 'json' 4 5 # system "curl \ 6 # --silent \ 7 # -H \"Accept: application/vnd.github+json\" \ 8 # -H \"Authorization: Bearer #{ENV["GITHUB_TOKEN"]}\" \ 9 # https://api.github.com/repos/pyroscope-io/cloudstorage/actions/workflows/34992245/runs" 10 11 latest_run = JSON.parse(`curl \ 12 --silent \ 13 -H "Accept: application/vnd.github+json" \ 14 -H "Authorization: Bearer #{ENV["GITHUB_TOKEN"]}" \ 15 https://api.github.com/repos/pyroscope-io/cloudstorage/actions/workflows/34992245/runs`)["workflow_runs"][0] 16 17 puts "latest run: #{latest_run ? latest_run["id"] : "none"}" 18 19 20 puts "triggering a run" 21 system "curl \ 22 -X POST \ 23 -H \"Accept: application/vnd.github+json\" \ 24 -H \"Authorization: Bearer #{ENV["GITHUB_TOKEN"]}\" \ 25 https://api.github.com/repos/pyroscope-io/cloudstorage/actions/workflows/34992245/dispatches \ 26 -d '{\"ref\":\"main\",\"inputs\":{\"gitRef\":\"#{ENV["HEAD_REF"] || "main"}\"}'" 27 28 # TODO: this logic is prone to race conditions, consider improving 29 run_id = nil 30 10.times do 31 runs = JSON.parse(`curl \ 32 --silent \ 33 -H "Accept: application/vnd.github+json" \ 34 -H "Authorization: Bearer #{ENV["GITHUB_TOKEN"]}" \ 35 https://api.github.com/repos/pyroscope-io/cloudstorage/actions/workflows/34992245/runs`)["workflow_runs"] 36 37 run = runs.find { |r| latest_run.nil? || r["created_at"] > latest_run["created_at"] } 38 if run 39 run_id = run["id"] 40 break 41 end 42 end 43 44 raise "could not find run" unless run_id 45 46 puts "current run_id: #{run_id}" 47 48 60.times do 49 status=JSON.parse(`curl \ 50 --silent \ 51 -H "Accept: application/vnd.github+json" \ 52 -H "Authorization: Bearer #{ENV["GITHUB_TOKEN"]}" \ 53 https://api.github.com/repos/pyroscope-io/cloudstorage/actions/runs/#{run_id}`)["status"] 54 55 puts "status: #{status}" 56 break if status == "completed" 57 sleep 10 58 end 59 60 run = JSON.parse(`curl \ 61 --silent \ 62 -H "Accept: application/vnd.github+json" \ 63 -H "Authorization: Bearer #{ENV["GITHUB_TOKEN"]}" \ 64 https://api.github.com/repos/pyroscope-io/cloudstorage/actions/runs/#{run_id}`) 65 66 conclusion=run["conclusion"] 67 68 puts "conclusion: #{conclusion}" 69 70 puts "" 71 puts "---" 72 puts "" 73 74 if conclusion != "success" 75 puts "This version of pyroscope OSS is not compatible with downstream Pyroscope Cloud project" 76 puts "Go to https://github.com/pyroscope-io/cloudstorage/actions/runs/#{run_id} for more information" 77 # exit 1 78 end