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.

98 lines · 4.3 KBRaw History
1name: Import campaign
2
3# Imports a varied set of public GitHub repositories into Diffinery as private test
4# repositories (<owner>/campaign-*), optionally runs their push workflows there, and reports what
5# came across and what ran (scripts/import-campaign.sh). Started by hand.
6#
7# Dispatched on GitHub, it starts the same workflow on Diffinery and prints its report;
8# on Diffinery it does the work. Imports use the IMPORT_GITHUB_TOKEN secret when it is
9# set (a read-only token for public repositories), otherwise GitHub's anonymous rate
10# limit applies and large repositories take hours.
11on:
12 workflow_dispatch:
13 inputs:
14 repos:
15 description: GitHub repositories to import, separated by spaces
16 type: string
17 default: >-
18 octocat/git-consortium sindresorhus/slugify expressjs/cors spf13/pflag
19 pallets/markupsafe BurntSushi/walkdir actions/hello-world-javascript-action
20 actions/hello-world-docker-action jekyll/minima
21 minutes:
22 description: How long to wait for imports and workflow runs, in minutes
23 type: string
24 default: "300"
25 run_workflows:
26 description: Also run the imported repositories' push workflows (third-party code)
27 type: boolean
28 default: false
29
30permissions:
31 contents: read
32
33concurrency:
34 group: import-campaign
35 cancel-in-progress: false
36
37jobs:
38 relay:
39 name: Start the campaign on Diffinery and print its report
40 if: ${{ github.server_url == 'https://github.com' }}
41 runs-on: ubuntu-latest
42 timeout-minutes: 360
43 environment: production
44 env:
45 DIFFINERY: https://diffinery.com
46 TOKEN: ${{ secrets.DIFFINERY_LIVE_TOKEN }}
47 R: codician-team/diffinery
48 steps:
49 - name: Dispatch and follow
50 env:
51 REPOS: ${{ inputs.repos }}
52 MINUTES: ${{ inputs.minutes }}
53 RUN_WORKFLOWS: ${{ inputs.run_workflows }}
54 run: |
55 set -euo pipefail
56 api() { curl -fsS --retry 3 -X "$1" "$DIFFINERY/api/v3$2" -H "Authorization: Bearer $TOKEN" -H "content-type: application/json" ${3:+--data "$3"}; }
57 before=$(api GET "/repos/$R/actions/workflows/import-campaign.yml/runs?per_page=1" | jq -r '.workflow_runs[0].id // 0')
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
59 for i in $(seq 1 60); do
60 run=$(api GET "/repos/$R/actions/workflows/import-campaign.yml/runs?per_page=1" | jq -c '.workflow_runs[0] // empty')
61 [ -n "$run" ] && [ "$(jq -r .id <<<"$run")" != "$before" ] && break
62 sleep 5
63 done
64 id=$(jq -r .id <<<"$run")
65 echo "Diffinery run: $(jq -r .html_url <<<"$run")"
66 while [ "$(api GET "/repos/$R/actions/runs/$id" | jq -r .status)" != completed ]; do sleep 30; done
67 run=$(api GET "/repos/$R/actions/runs/$id")
68 for job in $(api GET "/repos/$R/actions/runs/$id/jobs" | jq -r '.jobs[].id'); do
69 curl -fsS "$DIFFINERY/api/v3/repos/$R/actions/jobs/$job/logs" -H "Authorization: Bearer $TOKEN" | sed -n '/^# Import campaign/,$p' | tee -a "$GITHUB_STEP_SUMMARY"
70 done
71 [ "$(jq -r .conclusion <<<"$run")" = success ] || { echo "::error::the campaign run on Diffinery ended $(jq -r .conclusion <<<"$run")"; exit 1; }
72
73 campaign:
74 name: Import, run and report
75 if: ${{ github.server_url != 'https://github.com' }}
76 runs-on: ubuntu-latest
77 timeout-minutes: 360
78 env:
79 DIFFINERY: ${{ github.server_url }}
80 TOKEN: ${{ secrets.DIFFINERY_LIVE_TOKEN }}
81 GITHUB_TOKEN_FOR_IMPORT: ${{ secrets.IMPORT_GITHUB_TOKEN }}
82 steps:
83 - uses: actions/checkout@v4
84 - name: Import and run
85 env:
86 REPOS: ${{ inputs.repos }}
87 MINUTES: ${{ inputs.minutes }}
88 RUN_WORKFLOWS: ${{ inputs.run_workflows }}
89 run: |
90 [ -n "$GITHUB_TOKEN_FOR_IMPORT" ] || echo "::warning::IMPORT_GITHUB_TOKEN is not set, so imports use GitHub's anonymous rate limit"
91 # shellcheck disable=SC2086
92 REPORT=report.md scripts/import-campaign.sh $REPOS
93 cat report.md >> "$GITHUB_STEP_SUMMARY"
94 - uses: actions/upload-artifact@v4
95 if: always()
96 with:
97 name: import-campaign-report
98 path: report.md