Diffinery

codician/diffinerypublic

Open-source, agent-first GitHub and GitHub Actions alternative that runs on your own Cloudflare account: git hosting, pull requests, code review and drop-in GitHub Actions YAML on Workers, Durable Objects, R2 and Containers.

Import campaign: running imported workflows is opt-in (#41)

They are third-party code that would run with a job token on Diffinery, so
the campaign imports and checks repositories without running them unless
run_workflows is set.


Claude-Session: https://claude.ai/code/session_01AizKXSsengXZRegJxRATkL

Co-authored-by: Claude <noreply@anthropic.com>
Canberk Demirci authored · GitHub committed signed1 parent be5ab61commit 6b6c691ca7cc4e9ea62df465172aa7aacdcb916aBrowse files
2 files changed+12−3
modified.github/workflows/import-campaign.yml+8−2View file
@@ -1,7 +1,7 @@
11 name: Import campaign
22
33 # Imports a varied set of public GitHub repositories into Diffinery as private test
4-# repositories (<owner>/campaign-*), runs their push workflows there, and reports what
4+# repositories (<owner>/campaign-*), optionally runs their push workflows there, and reports what
55 # came across and what ran (scripts/import-campaign.sh). Started by hand.
66 #
77 # Dispatched on GitHub, it starts the same workflow on Diffinery and prints its report;
@@ -22,6 +22,10 @@
2222 description: How long to wait for imports and workflow runs, in minutes
2323 type: string
2424 default: "300"
25+ run_workflows:
26+ description: Also run the imported repositories' push workflows (third-party code)
27+ type: boolean
28+ default: false
2529
2630 permissions:
2731 contents: read
@@ -46,11 +50,12 @@
4650 env:
4751 REPOS: ${{ inputs.repos }}
4852 MINUTES: ${{ inputs.minutes }}
53+ RUN_WORKFLOWS: ${{ inputs.run_workflows }}
4954 run: |
5055 set -euo pipefail
5156 api() { curl -fsS --retry 3 -X "$1" "$DIFFINERY/api/v3$2" -H "Authorization: Bearer $TOKEN" -H "content-type: application/json" ${3:+--data "$3"}; }
5257 before=$(api GET "/repos/$R/actions/workflows/import-campaign.yml/runs?per_page=1" | jq -r '.workflow_runs[0].id // 0')
53- api POST "/repos/$R/actions/workflows/import-campaign.yml/dispatches" "$(jq -nc --arg r "$REPOS" --arg m "$MINUTES" '{ref: "main", inputs: {repos: $r, minutes: $m}}')" >/dev/null
58+ api POST "/repos/$R/actions/workflows/import-campaign.yml/dispatches" "$(jq -nc --arg r "$REPOS" --arg m "$MINUTES" --arg w "$RUN_WORKFLOWS" '{ref: "main", inputs: {repos: $r, minutes: $m, run_workflows: $w}}')" >/dev/null
5459 for i in $(seq 1 60); do
5560 run=$(api GET "/repos/$R/actions/workflows/import-campaign.yml/runs?per_page=1" | jq -c '.workflow_runs[0] // empty')
5661 [ -n "$run" ] && [ "$(jq -r .id <<<"$run")" != "$before" ] && break
@@ -80,6 +85,7 @@
8085 env:
8186 REPOS: ${{ inputs.repos }}
8287 MINUTES: ${{ inputs.minutes }}
88+ RUN_WORKFLOWS: ${{ inputs.run_workflows }}
8389 run: |
8490 [ -n "$GITHUB_TOKEN_FOR_IMPORT" ] || echo "::warning::IMPORT_GITHUB_TOKEN is not set, so imports use GitHub's anonymous rate limit"
8591 # shellcheck disable=SC2086
modifiedscripts/import-campaign.sh+4−1View file
@@ -10,7 +10,9 @@
1010 #
1111 # Usage: DIFFINERY=https://diffinery.com TOKEN=... [GITHUB_TOKEN_FOR_IMPORT=...] \
1212 # import-campaign.sh owner/repo [owner/repo...]
13-# Env: MINUTES (default 180) bounds the whole campaign; REPORT (default report.md).
13+# Env: MINUTES (default 180) bounds the whole campaign; REPORT (default report.md);
14+# RUN_WORKFLOWS=true starts the imported repositories' push workflows (off by default:
15+# they are third-party code, run with a job token on Diffinery).
1416 set -euo pipefail
1517 MINUTES=${MINUTES:-180}
1618 REPORT=${REPORT:-report.md}
@@ -67,6 +69,7 @@
6769 branch=$(jq -r .default_branch <<<"$repo")
6870 api GET "/repos/$owner/$name/actions/workflows" | jq '[.workflows[] | {name, path, state}]' > "$work/$name.workflows.json" || echo '[]' > "$work/$name.workflows.json"
6971 [ "$(jq length "$work/$name.workflows.json")" -gt 0 ] || continue
72+ [ "${RUN_WORKFLOWS:-false}" = true ] || continue
7073 put=$(jq -nc --arg b "$branch" --arg c "$(printf 'Imported from %s and run on Diffinery\n' "$src" | base64 -w0)" '{message: "Run the workflows on Diffinery", content: $c, branch: $b}')
7174 if out=$(api PUT "/repos/$owner/$name/contents/.diffinery-campaign" "$put"); then
7275 sha[$src]=$(jq -r .commit.sha <<<"$out")