Merge pull request #22 from alankernel67/claude/skip-docker-e2e-on-forks
Run fork pull requests' CI on Diffinery's runners, not GitHub's
altugank authored · GitHub committed 2 parents 9948c4a6d0b149commit 1019f324b6eb356fc27f6a527d9a4e7f98401b08Browse files
11 files changed+40−22
Files (11)
- .github/workflows/awesome-lists.yml+1−1
- .github/workflows/ci.yml+6−4
- .github/workflows/d1-replication.yml+2−2
- .github/workflows/deploy.yml+5−4
- .github/workflows/e2e.yml+3−3
- .github/workflows/github-community.yml+1−1
- .github/workflows/live-test.yml+1−1
- CONTRIBUTING.md+6−0
- apps/diffinery/docs/actions/github-runners.md+9−1
- apps/diffinery/docs/self-hosting/deploy.md+1−1
- apps/diffinery/test/unit/contact.test.ts+5−4
modified.github/workflows/awesome-lists.yml+1−1View file
| @@ -26,7 +26,7 @@ | ||
| 26 | 26 | suggest: |
| 27 | 27 | name: Open the list pull requests |
| 28 | 28 | if: ${{ github.server_url != 'https://github.com' && github.repository == 'codician/diffinery' }} |
| 29 | - runs-on: ${{ vars.DIFFINERY_RUNS_ON || 'ubuntu-latest' }} | |
| 29 | + runs-on: ${{ vars.DIFFINERY_RUNS_ON || (github.repository == 'codician-team/diffinery' && 'diffinery') || 'ubuntu-latest' }} | |
| 30 | 30 | environment: github-mirror |
| 31 | 31 | timeout-minutes: 10 |
| 32 | 32 | steps: |
modified.github/workflows/ci.yml+6−4View file
| @@ -4,8 +4,10 @@ | ||
| 4 | 4 | # workflow (e2e.yml), so deploys don't wait for it too. |
| 5 | 5 | # |
| 6 | 6 | # Every job of this repository's workflows runs on the label in the repository variable |
| 7 | -# DIFFINERY_RUNS_ON, else ubuntu-latest (a hosted runner on Diffinery too). The GitHub copy | |
| 8 | -# sets `diffinery` to run on diffinery.com's GitHub runners; forks need nothing. | |
| 7 | +# DIFFINERY_RUNS_ON, else on `diffinery` (diffinery.com's GitHub runners) in | |
| 8 | +# codician-team/diffinery, else ubuntu-latest (a hosted runner on Diffinery too). GitHub passes | |
| 9 | +# no variables to pull requests from forks, so without that middle default they would run on | |
| 10 | +# GitHub's own runners. Other copies of the repository need nothing. | |
| 9 | 11 | |
| 10 | 12 | on: |
| 11 | 13 | push: |
| @@ -24,7 +26,7 @@ | ||
| 24 | 26 | # tests together took longer than either does alone. |
| 25 | 27 | typecheck: |
| 26 | 28 | name: Typecheck and bundle |
| 27 | - runs-on: ${{ vars.DIFFINERY_RUNS_ON || 'ubuntu-latest' }} | |
| 29 | + runs-on: ${{ vars.DIFFINERY_RUNS_ON || (github.repository == 'codician-team/diffinery' && 'diffinery') || 'ubuntu-latest' }} | |
| 28 | 30 | timeout-minutes: 20 |
| 29 | 31 | steps: |
| 30 | 32 | - uses: actions/checkout@v4 |
| @@ -44,7 +46,7 @@ | ||
| 44 | 46 | |
| 45 | 47 | test: |
| 46 | 48 | name: Unit tests (${{ matrix.shard }}/2) |
| 47 | - runs-on: ${{ vars.DIFFINERY_RUNS_ON || 'ubuntu-latest' }} | |
| 49 | + runs-on: ${{ vars.DIFFINERY_RUNS_ON || (github.repository == 'codician-team/diffinery' && 'diffinery') || 'ubuntu-latest' }} | |
| 48 | 50 | timeout-minutes: 20 |
| 49 | 51 | # Two halves of every package's test files, side by side: CI is the first step of a deploy. |
| 50 | 52 | strategy: |
modified.github/workflows/d1-replication.yml+2−2View file
| @@ -18,7 +18,7 @@ | ||
| 18 | 18 | jobs: |
| 19 | 19 | check: |
| 20 | 20 | name: Check sessions on a test database |
| 21 | - runs-on: ${{ vars.DIFFINERY_RUNS_ON || 'ubuntu-latest' }} | |
| 21 | + runs-on: ${{ vars.DIFFINERY_RUNS_ON || (github.repository == 'codician-team/diffinery' && 'diffinery') || 'ubuntu-latest' }} | |
| 22 | 22 | # The Cloudflare secrets are the production environment's. |
| 23 | 23 | environment: production |
| 24 | 24 | timeout-minutes: 20 |
| @@ -81,7 +81,7 @@ | ||
| 81 | 81 | name: Turn on read replication in production |
| 82 | 82 | needs: check |
| 83 | 83 | if: ${{ inputs.enable_production }} |
| 84 | - runs-on: ${{ vars.DIFFINERY_RUNS_ON || 'ubuntu-latest' }} | |
| 84 | + runs-on: ${{ vars.DIFFINERY_RUNS_ON || (github.repository == 'codician-team/diffinery' && 'diffinery') || 'ubuntu-latest' }} | |
| 85 | 85 | environment: |
| 86 | 86 | name: production |
| 87 | 87 | url: https://${{ vars.DIFFINERY_DOMAIN || 'diffinery.com' }} |
modified.github/workflows/deploy.yml+5−4View file
| @@ -10,8 +10,9 @@ | ||
| 10 | 10 | # DIFFINERY_GITHUB_APP_ID, DIFFINERY_GITHUB_APP_SLUG, DIFFINERY_GITHUB_APP_CLIENT_ID, |
| 11 | 11 | # DIFFINERY_GITHUB_APP_URL the GitHub App of GitHub runners (docs/self-hosting/configuration.md) |
| 12 | 12 | # DIFFINERY_RUNS_ON the runner label of every job in this repository's workflows (default |
| 13 | -# ubuntu-latest). `diffinery` runs them on a Diffinery instance's GitHub runners; | |
| 14 | -# set it back to ubuntu-latest to deploy while those can't start. | |
| 13 | +# ubuntu-latest, and `diffinery` in codician-team/diffinery, whose fork pull | |
| 14 | +# requests get no variables). `diffinery` runs them on a Diffinery instance's | |
| 15 | +# GitHub runners; set it back to ubuntu-latest to deploy while those can't start. | |
| 15 | 16 | # |
| 16 | 17 | # It deploys a main commit only once CI (typecheck, unit tests and the Worker bundle) has |
| 17 | 18 | # passed on it, so it doesn't run those itself. End-to-end tests run alongside the deploy. |
| @@ -42,7 +43,7 @@ | ||
| 42 | 43 | # codician/diffinery, an older copy of this repository: GitHub deploys diffinery.com, |
| 43 | 44 | # and that copy lacks the GitHub App's variables a deploy needs. |
| 44 | 45 | if: ${{ !(github.server_url == 'https://diffinery.com' && github.repository == 'codician/diffinery') && (github.event_name == 'workflow_dispatch' || (github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'push')) }} |
| 45 | - runs-on: ${{ vars.DIFFINERY_RUNS_ON || 'ubuntu-latest' }} | |
| 46 | + runs-on: ${{ vars.DIFFINERY_RUNS_ON || (github.repository == 'codician-team/diffinery' && 'diffinery') || 'ubuntu-latest' }} | |
| 46 | 47 | timeout-minutes: 5 |
| 47 | 48 | outputs: |
| 48 | 49 | deploy: ${{ steps.tip.outputs.deploy }} |
| @@ -72,7 +73,7 @@ | ||
| 72 | 73 | name: Deploy to Cloudflare |
| 73 | 74 | needs: gate |
| 74 | 75 | if: ${{ needs.gate.outputs.deploy == 'true' }} |
| 75 | - runs-on: ${{ vars.DIFFINERY_RUNS_ON || 'ubuntu-latest' }} | |
| 76 | + runs-on: ${{ vars.DIFFINERY_RUNS_ON || (github.repository == 'codician-team/diffinery' && 'diffinery') || 'ubuntu-latest' }} | |
| 76 | 77 | timeout-minutes: 45 |
| 77 | 78 | environment: |
| 78 | 79 | name: production |
modified.github/workflows/e2e.yml+3−3View file
| @@ -19,7 +19,7 @@ | ||
| 19 | 19 | # Only the last shard needs a browser (passkeys). |
| 20 | 20 | e2e: |
| 21 | 21 | name: End-to-end (${{ matrix.name }}) |
| 22 | - runs-on: ${{ vars.DIFFINERY_RUNS_ON || 'ubuntu-latest' }} | |
| 22 | + runs-on: ${{ vars.DIFFINERY_RUNS_ON || (github.repository == 'codician-team/diffinery' && 'diffinery') || 'ubuntu-latest' }} | |
| 23 | 23 | timeout-minutes: 20 |
| 24 | 24 | strategy: |
| 25 | 25 | fail-fast: false |
| @@ -88,11 +88,11 @@ | ||
| 88 | 88 | |
| 89 | 89 | # Docker as the hosted runner image runs it, with this change's docker wrapper, daemon config |
| 90 | 90 | # and agent (its registry relay). It needs a Diffinery hosted runner, for the real dockerd: on |
| 91 | - # Diffinery, or on GitHub with DIFFINERY_RUNS_ON=diffinery. On GitHub's own runners it fails. | |
| 91 | + # Diffinery, or on GitHub on the `diffinery` label. On GitHub's own runners it fails. | |
| 92 | 92 | # A daemon an earlier step started is stopped first, so the first uses below start it afresh. |
| 93 | 93 | runner-docker: |
| 94 | 94 | name: End-to-end (runner Docker) |
| 95 | - runs-on: ${{ vars.DIFFINERY_RUNS_ON || 'ubuntu-latest' }} | |
| 95 | + runs-on: ${{ vars.DIFFINERY_RUNS_ON || (github.repository == 'codician-team/diffinery' && 'diffinery') || 'ubuntu-latest' }} | |
| 96 | 96 | timeout-minutes: 20 |
| 97 | 97 | steps: |
| 98 | 98 | - uses: actions/checkout@v4 |
modified.github/workflows/github-community.yml+1−1View file
| @@ -19,7 +19,7 @@ | ||
| 19 | 19 | setup: |
| 20 | 20 | name: Labels, welcome discussion and roadmap issue |
| 21 | 21 | if: ${{ github.server_url != 'https://github.com' && github.repository == 'codician/diffinery' }} |
| 22 | - runs-on: ${{ vars.DIFFINERY_RUNS_ON || 'ubuntu-latest' }} | |
| 22 | + runs-on: ${{ vars.DIFFINERY_RUNS_ON || (github.repository == 'codician-team/diffinery' && 'diffinery') || 'ubuntu-latest' }} | |
| 23 | 23 | environment: github-mirror |
| 24 | 24 | timeout-minutes: 5 |
| 25 | 25 | steps: |
modified.github/workflows/live-test.yml+1−1View file
| @@ -31,7 +31,7 @@ | ||
| 31 | 31 | name: Containers, registry, sandboxes, webhooks, schedules, LFS and pull requests |
| 32 | 32 | # Runs on the host that deploys production (see the gate in deploy.yml). |
| 33 | 33 | if: ${{ github.event_name == 'workflow_dispatch' || (github.server_url == 'https://diffinery.com' && github.event.workflow_run.conclusion == 'success') }} |
| 34 | - runs-on: ${{ vars.DIFFINERY_RUNS_ON || 'ubuntu-latest' }} | |
| 34 | + runs-on: ${{ vars.DIFFINERY_RUNS_ON || (github.repository == 'codician-team/diffinery' && 'diffinery') || 'ubuntu-latest' }} | |
| 35 | 35 | timeout-minutes: 45 |
| 36 | 36 | environment: production |
| 37 | 37 | env: |
modifiedCONTRIBUTING.md+6−0View file
| @@ -57,6 +57,12 @@ | ||
| 57 | 57 | end-to-end shards before they merge. Tests must not depend on the speed of the machine |
| 58 | 58 | they run on. |
| 59 | 59 | |
| 60 | +CI runs on Diffinery's own runners for GitHub (`runs-on: diffinery`), pull requests from | |
| 61 | +forks included: in this repository the workflows default to that label when the | |
| 62 | +repository variable `DIFFINERY_RUNS_ON`, which GitHub doesn't pass to forks, is missing. | |
| 63 | +The "End-to-end (runner Docker)" job needs those runners and fails on GitHub's own. A | |
| 64 | +maintainer may have to approve the workflows of your first pull request before they run. | |
| 65 | + | |
| 60 | 66 | ## Conventions |
| 61 | 67 | |
| 62 | 68 | - **TypeScript everywhere**, in strict mode, sharing code through the workspace packages in |
modifiedapps/diffinery/docs/actions/github-runners.md+9−1View file
| @@ -70,8 +70,16 @@ | ||
| 70 | 70 | runs-on: ${{ vars.RUNS_ON || 'ubuntu-latest' }} |
| 71 | 71 | ``` |
| 72 | 72 | |
| 73 | -Then set the variable to `diffinery` (`gh variable set RUNS_ON --body diffinery`). Setting it back to `ubuntu-latest` returns the jobs to GitHub-hosted runners, for example to keep a deploy working while Diffinery can't start runners. Forks without the variable keep running on GitHub. Diffinery's own repository does this with `DIFFINERY_RUNS_ON`. | |
| 73 | +Then set the variable to `diffinery` (`gh variable set RUNS_ON --body diffinery`). Setting it back to `ubuntu-latest` returns the jobs to GitHub-hosted runners, for example to keep a deploy working while Diffinery can't start runners. Forks without the variable keep running on GitHub. | |
| 74 | 74 | |
| 75 | +GitHub passes no repository variables to workflows of pull requests from forks, so those jobs run on `ubuntu-latest` too. To run them on Diffinery as well, default to `diffinery` in your own repository, and keep `ubuntu-latest` for copies of it: | |
| 76 | + | |
| 77 | +```yaml | |
| 78 | + runs-on: ${{ vars.RUNS_ON || (github.repository == 'my-org/my-repo' && 'diffinery') || 'ubuntu-latest' }} | |
| 79 | +``` | |
| 80 | + | |
| 81 | +Diffinery's own repository does this with `DIFFINERY_RUNS_ON`. Read [Security](#security) first: anyone who opens a pull request can then use your minutes. | |
| 82 | + | |
| 75 | 83 | ## The machine |
| 76 | 84 | |
| 77 | 85 | The container runs the same image as Diffinery's own [hosted runners](/docs/actions/runners#hosted-runners): Ubuntu 24.04 on x64 with Git, Node.js 22, Python 3.12, Docker, the GitHub CLI and `/dev/kvm`. Differences from a GitHub-hosted runner: |
modifiedapps/diffinery/docs/self-hosting/deploy.md+1−1View file
| @@ -111,7 +111,7 @@ | ||
| 111 | 111 | | `MAIL_DOMAIN` | Variable, optional | The domain email is sent from, when it isn't `DIFFINERY_DOMAIN`. | |
| 112 | 112 | | `ACCESS_TEAM_DOMAIN` | Variable, optional | Your Zero Trust team domain, for example `example.cloudflareaccess.com`. Needed only when the token can't read it. | |
| 113 | 113 | | `DIFFINERY_GITHUB_APP_ID`, `DIFFINERY_GITHUB_APP_SLUG`, `DIFFINERY_GITHUB_APP_CLIENT_ID`, `DIFFINERY_GITHUB_APP_URL` | Variables, optional | The GitHub App of [GitHub runners](/docs/self-hosting/configuration#github-runners). The workflow passes them to render-config as `GITHUB_APP_ID` and the rest. | |
| 114 | -| `DIFFINERY_RUNS_ON` | Variable, optional | The `runs-on` label of every job in the repository's workflows. Without it, jobs run on `ubuntu-latest`. Set it to `diffinery` to run them on a Diffinery instance's [GitHub runners](/docs/actions/github-runners) once that instance's GitHub App is installed on the repository. Set it back to `ubuntu-latest` to deploy while those runners can't start, for example while the instance itself is down. | | |
| 114 | +| `DIFFINERY_RUNS_ON` | Variable, optional | The `runs-on` label of every job in the repository's workflows. Without it, jobs run on `ubuntu-latest` (in `codician-team/diffinery` itself, on `diffinery`, so pull requests from forks, which get no variables, run there too). Set it to `diffinery` to run them on a Diffinery instance's [GitHub runners](/docs/actions/github-runners) once that instance's GitHub App is installed on the repository. Set it back to `ubuntu-latest` to deploy while those runners can't start, for example while the instance itself is down. | | |
| 115 | 115 | |
| 116 | 116 | The Deploy job runs in an environment named `production`, so you can also store the secrets as environment secrets there and add required reviewers to that environment. |
| 117 | 117 |
modifiedapps/diffinery/test/unit/contact.test.ts+5−4View file
| @@ -157,10 +157,11 @@ | ||
| 157 | 157 | await submitMessage(env, audit, input("[email protected]", { message: "Second message, about another." }), null, "203.0.113.9"); |
| 158 | 158 | expect(rows(DB)).toHaveLength(2); |
| 159 | 159 | await confirmMessage(env, audit, tokenOf(queued[1])); |
| 160 | - expect(rows(DB).map((r) => [r.message, r.state])).toEqual([ | |
| 161 | - ["First message, about one thing.", "unconfirmed"], | |
| 162 | - ["Second message, about another.", "new"], | |
| 163 | - ]); | |
| 160 | + // Both can have the same created_at millisecond, and then the random id orders them. | |
| 161 | + expect(Object.fromEntries(rows(DB).map((r) => [r.message, r.state]))).toEqual({ | |
| 162 | + "First message, about one thing.": "unconfirmed", | |
| 163 | + "Second message, about another.": "new", | |
| 164 | + }); | |
| 164 | 165 | }); |
| 165 | 166 | |
| 166 | 167 | it("limits one network, one address and the whole form per day, quietly past the last two", async () => { |