diff --git a/.github/workflows/registry-check.yml b/.github/workflows/registry-check.yml new file mode 100644 index 0000000..50de30f --- /dev/null +++ b/.github/workflows/registry-check.yml @@ -0,0 +1,88 @@ +name: Check RubyGems release + +# The publish job waits for an approval, so the wait starts when that workflow +# finishes, not when the tag is pushed. +on: + workflow_run: + workflows: [Publish to RubyGems] + types: [completed] + workflow_dispatch: + inputs: + version: + description: "Gem version to look for on RubyGems, for example 6.2.0" + required: true + type: string + +permissions: + contents: read + +jobs: + check: + name: Confirm version is on RubyGems + # Runs after every publish run, failed and cancelled ones too. The tag + # already exists by then, and a failed publish can still have uploaded the + # package, so the registry is the only way to tell. + runs-on: ubuntu-latest + timeout-minutes: 60 + env: + GEM_NAME: customerio + # Poll every 3 minutes for up to 50 minutes. + POLL_INTERVAL_SECONDS: "180" + POLL_TIMEOUT_SECONDS: "3000" + # Secrets can't be read in step `if`, so the alert step tests this copy. + # Empty until the org secret exists, which skips the alert. + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_NOTIFY_RELEASES_WEBHOOK_URL }} + + steps: + - name: Wait for the version to appear on RubyGems + id: check + env: + # For a publish run started by a tag push, head_branch is the tag. + RAW_VERSION: ${{ inputs.version || github.event.workflow_run.head_branch }} + run: | + version="${RAW_VERSION#v}" + if ! [[ "$version" =~ ^[0-9A-Za-z][0-9A-Za-z.+_-]*$ ]]; then + echo "::error::'$RAW_VERSION' is not a valid version" + exit 1 + fi + echo "version=$version" >> "$GITHUB_OUTPUT" + + url="https://rubygems.org/api/v2/rubygems/${GEM_NAME}/versions/${version}.json" + deadline=$(( $(date +%s) + POLL_TIMEOUT_SECONDS )) + while true; do + status=$(curl -s -o /dev/null -w '%{http_code}' --max-time 20 "$url" || true) + if [ "$status" = "200" ]; then + echo "${GEM_NAME} ${version} is on RubyGems" + exit 0 + fi + echo "${GEM_NAME} ${version} not found yet (HTTP ${status:-none})" + if [ "$(date +%s)" -ge "$deadline" ]; then + echo "::error::${GEM_NAME} ${version} was not on RubyGems after ${POLL_TIMEOUT_SECONDS}s" + exit 1 + fi + sleep "$POLL_INTERVAL_SECONDS" + done + + - name: Alert Slack that the version is missing + if: failure() && steps.check.outcome == 'failure' && env.SLACK_WEBHOOK_URL != '' + uses: slackapi/slack-github-action@dcb1066f776dd043e64d0e8ba94ca15cc7e1875d # v4.0.0 + continue-on-error: true + with: + webhook: ${{ env.SLACK_WEBHOOK_URL }} + webhook-type: incoming-webhook + payload: | + { + "text": "Ruby SDK ${{ steps.check.outputs.version }} is missing from RubyGems", + "username": "Ruby deployment bot", + "icon_url": "https://raw.githubusercontent.com/github/explore/main/topics/ruby/ruby.png", + "channel": "#server-sdk-deployments", + "blocks": [ + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "*Ruby* SDK ${{ steps.check.outputs.version }} is not on RubyGems 50 minutes after the publish workflow finished :warning:\nThe publish workflow ended as ${{ github.event.workflow_run.conclusion || 'not run' }}. View ." + } + } + ] + }