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.

92 lines · 4.0 KBRaw History
1name: Import campaign
2
3# 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
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
26permissions:
27 contents: read
28
29concurrency:
30 group: import-campaign
31 cancel-in-progress: false
32
33jobs:
34 relay:
35 name: Start the campaign on Diffinery and print its report
36 if: ${{ github.server_url == 'https://github.com' }}
37 runs-on: ubuntu-latest
38 timeout-minutes: 360
39 environment: production
40 env:
41 DIFFINERY: https://diffinery.com
42 TOKEN: ${{ secrets.DIFFINERY_LIVE_TOKEN }}
43 R: codician-team/diffinery
44 steps:
45 - name: Dispatch and follow
46 env:
47 REPOS: ${{ inputs.repos }}
48 MINUTES: ${{ inputs.minutes }}
49 run: |
50 set -euo pipefail
51 api() { curl -fsS --retry 3 -X "$1" "$DIFFINERY/api/v3$2" -H "Authorization: Bearer $TOKEN" -H "content-type: application/json" ${3:+--data "$3"}; }
52 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
54 for i in $(seq 1 60); do
55 run=$(api GET "/repos/$R/actions/workflows/import-campaign.yml/runs?per_page=1" | jq -c '.workflow_runs[0] // empty')
56 [ -n "$run" ] && [ "$(jq -r .id <<<"$run")" != "$before" ] && break
57 sleep 5
58 done
59 id=$(jq -r .id <<<"$run")
60 echo "Diffinery run: $(jq -r .html_url <<<"$run")"
61 while [ "$(api GET "/repos/$R/actions/runs/$id" | jq -r .status)" != completed ]; do sleep 30; done
62 run=$(api GET "/repos/$R/actions/runs/$id")
63 for job in $(api GET "/repos/$R/actions/runs/$id/jobs" | jq -r '.jobs[].id'); do
64 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"
65 done
66 [ "$(jq -r .conclusion <<<"$run")" = success ] || { echo "::error::the campaign run on Diffinery ended $(jq -r .conclusion <<<"$run")"; exit 1; }
67
68 campaign:
69 name: Import, run and report
70 if: ${{ github.server_url != 'https://github.com' }}
71 runs-on: ubuntu-latest
72 timeout-minutes: 360
73 env:
74 DIFFINERY: ${{ github.server_url }}
75 TOKEN: ${{ secrets.DIFFINERY_LIVE_TOKEN }}
76 GITHUB_TOKEN_FOR_IMPORT: ${{ secrets.IMPORT_GITHUB_TOKEN }}
77 steps:
78 - uses: actions/checkout@v4
79 - name: Import and run
80 env:
81 REPOS: ${{ inputs.repos }}
82 MINUTES: ${{ inputs.minutes }}
83 run: |
84 [ -n "$GITHUB_TOKEN_FOR_IMPORT" ] || echo "::warning::IMPORT_GITHUB_TOKEN is not set, so imports use GitHub's anonymous rate limit"
85 # shellcheck disable=SC2086
86 REPORT=report.md scripts/import-campaign.sh $REPOS
87 cat report.md >> "$GITHUB_STEP_SUMMARY"
88 - uses: actions/upload-artifact@v4
89 if: always()
90 with:
91 name: import-campaign-report
92 path: report.md