Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions .github/workflows/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,4 @@ jobs:
env:
GH_TOKEN: ${{ github.token }}
RUN_ID: ${{ github.run_id }}
run: |
has_source=$(gh api "repos/$GITHUB_REPOSITORY/actions/runs/$RUN_ID/artifacts" --jq 'any(.artifacts[]; .name == "registry-source" and .expired == false)')
if [ "$has_source" = true ]; then
gh workflow run registry.yml --ref main -f provider=all -f source_run="$RUN_ID"
fi
run: bash scripts/dispatch-registry.sh
15 changes: 15 additions & 0 deletions scripts/dispatch-registry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
set -euo pipefail

has_source=$(gh api "repos/$GITHUB_REPOSITORY/actions/runs/$RUN_ID/artifacts" --jq 'any(.artifacts[]; .name == "registry-source" and .expired == false)')
if [ "$has_source" != true ]; then
exit 0
fi

state=$(gh api "repos/$GITHUB_REPOSITORY/actions/workflows/registry.yml" --jq '.state')
if [ "$state" != active ]; then
echo "Registry transfers skipped: registry.yml is $state."
exit 0
fi

gh workflow run registry.yml --ref main -f provider=all -f source_run="$RUN_ID"
57 changes: 57 additions & 0 deletions test/bench/registry_dispatch_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
require_relative "test_helper"

class RegistryDispatchTest < Minitest::Test
def test_dispatches_an_active_workflow_with_source_artifacts
output, status, calls = dispatch(source: "true", state: "active")

assert status.success?, output
assert_includes calls, "workflow run registry.yml --ref main -f provider=all -f source_run=123"
end

def test_skips_a_disabled_workflow
output, status, calls = dispatch(source: "true", state: "disabled_manually")

assert status.success?, output
assert_includes output, "Registry transfers skipped: registry.yml is disabled_manually."
refute_includes calls, "workflow run"
end

def test_does_not_query_the_workflow_without_source_artifacts
output, status, calls = dispatch(source: "false", state: "active")

assert status.success?, output
refute_includes calls, "actions/workflows"
refute_includes calls, "workflow run"
end

def test_keeps_api_failures_fatal
output, status, calls = dispatch(source: "true", state: "active", api_status: "1")

refute status.success?, output
refute_includes calls, "workflow run"
end

private
def dispatch(source:, state:, api_status: "0")
Dir.mktmpdir do |dir|
gh = File.join(dir, "gh")
calls = File.join(dir, "calls")
File.write(gh, <<~SH)
#!/usr/bin/env bash
echo "$*" >> "$CALLS"
case "$2" in
*/artifacts) echo "$SOURCE" ;;
*/registry.yml) echo "$STATE"; exit "$API_STATUS" ;;
esac
SH
File.chmod(0o755, gh)
output, status = Open3.capture2e(
{ "PATH" => "#{dir}:#{ENV.fetch("PATH")}", "CALLS" => calls,
"SOURCE" => source, "STATE" => state, "API_STATUS" => api_status,
"GITHUB_REPOSITORY" => "boringcache/benchmarks", "RUN_ID" => "123" },
"bash", File.join(Bench::ROOT, "scripts/dispatch-registry.sh")
)
[output, status, File.read(calls)]
end
end
end
Loading