-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
chore: add repository synchronization gates #4859
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+129
−0
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| name: Dispatch RepoOps sync | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: dispatch-repo-ops-sync | ||
| cancel-in-progress: false | ||
|
|
||
| jobs: | ||
| dispatch: | ||
| if: vars.REPO_OPS_SYNC_ENABLED == 'true' | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Create Dispatcher App token | ||
| id: app-token | ||
| uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0 | ||
| with: | ||
| app-id: ${{ vars.REPO_OPS_DISPATCHER_APP_ID }} | ||
| private-key: ${{ secrets.REPO_OPS_DISPATCHER_APP_PRIVATE_KEY }} | ||
| repositories: ${{ secrets.REPO_OPS_MONO_REPOSITORY }} | ||
| permission-contents: write | ||
|
|
||
| - name: Dispatch the private sync worker | ||
| env: | ||
| GH_TOKEN: ${{ steps.app-token.outputs.token }} | ||
| PUBLIC_SHA: ${{ github.sha }} | ||
| MONO_REPOSITORY: ${{ secrets.REPO_OPS_MONO_REPOSITORY }} | ||
| run: | | ||
| set -euo pipefail | ||
| [[ "$MONO_REPOSITORY" =~ ^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+$ ]] | ||
| [[ "$PUBLIC_SHA" =~ ^[0-9a-f]{40}$ ]] | ||
| gh api "repos/${MONO_REPOSITORY}/dispatches" \ | ||
| --method POST \ | ||
| --field event_type=repo-ops-public-push \ | ||
| --field "client_payload[public_sha]=$PUBLIC_SHA" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| name: repo-ops-sync-gate | ||
|
|
||
| on: | ||
| pull_request: | ||
|
carderne marked this conversation as resolved.
|
||
| types: [opened, edited, reopened, synchronize] | ||
| merge_group: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| gate: | ||
|
carderne marked this conversation as resolved.
|
||
| if: github.event_name == 'pull_request' || vars.REPO_OPS_SYNC_ENABLED == 'true' | ||
| timeout-minutes: 15 | ||
| runs-on: ubuntu-latest | ||
|
carderne marked this conversation as resolved.
|
||
| steps: | ||
| - name: Reject reserved RepoOps trailers | ||
| if: github.event_name == 'pull_request' | ||
| env: | ||
| PR_TITLE: ${{ github.event.pull_request.title }} | ||
| PR_BODY: ${{ github.event.pull_request.body }} | ||
| run: | | ||
| python3 - <<'PY' | ||
| import os | ||
| import re | ||
| import sys | ||
|
|
||
| text = f"{os.environ.get('PR_TITLE', '')}\n{os.environ.get('PR_BODY', '')}" | ||
| match = re.search(r"(?m)^(?:OSS-RevId|Mono-RevId):", text) | ||
| if match: | ||
| print(f"BLOCKED: PR title/body contains reserved RepoOps trailer {match.group(0)!r}", file=sys.stderr) | ||
| raise SystemExit(1) | ||
| print("ok: no reserved RepoOps trailers") | ||
| PY | ||
|
|
||
| - name: Pull request check context | ||
| if: github.event_name == 'pull_request' | ||
| run: echo 'State is checked again against the live tips by merge queue.' | ||
|
|
||
| - name: Create read-only Dispatcher App token | ||
| if: github.event_name == 'merge_group' | ||
| id: app-token | ||
| uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0 | ||
| with: | ||
| app-id: ${{ vars.REPO_OPS_DISPATCHER_APP_ID }} | ||
| private-key: ${{ secrets.REPO_OPS_DISPATCHER_APP_PRIVATE_KEY }} | ||
| repositories: ${{ secrets.REPO_OPS_MONO_REPOSITORY }} | ||
| permission-contents: read | ||
|
|
||
| - name: Wait for pending mono changes | ||
| if: github.event_name == 'merge_group' | ||
| env: | ||
| APP_TOKEN: ${{ steps.app-token.outputs.token }} | ||
| PUBLIC_TOKEN: ${{ github.token }} | ||
| MONO_BASELINE: ${{ vars.REPO_OPS_MONO_BASELINE }} | ||
| PUBLIC_BASELINE: ${{ vars.REPO_OPS_PUBLIC_BASELINE }} | ||
| MONO_REPOSITORY: ${{ secrets.REPO_OPS_MONO_REPOSITORY }} | ||
| PUBLIC_REPOSITORY: ${{ github.repository }} | ||
| run: | | ||
| set -euo pipefail | ||
| [[ "$MONO_REPOSITORY" =~ ^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+$ ]] | ||
| [[ "$PUBLIC_REPOSITORY" =~ ^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+$ ]] | ||
| git clone --filter=blob:none --no-tags \ | ||
| "https://x-access-token:${PUBLIC_TOKEN}@github.com/${PUBLIC_REPOSITORY}.git" public | ||
| git clone --filter=blob:none --no-tags \ | ||
| "https://x-access-token:${APP_TOKEN}@github.com/${MONO_REPOSITORY}.git" mono | ||
|
|
||
| for _ in $(seq 1 60); do | ||
|
carderne marked this conversation as resolved.
|
||
| git -C public fetch --no-tags origin \ | ||
| +refs/heads/main:refs/remotes/origin/main | ||
| git -C mono fetch --no-tags origin \ | ||
| +refs/heads/main:refs/remotes/origin/main | ||
| output="$(mktemp)" | ||
| mono/tooling/plan-repo-ops-outbound.sh \ | ||
| mono public "$(git -C mono rev-parse origin/main)" \ | ||
| "$MONO_BASELINE" "$PUBLIC_BASELINE" "$output" | ||
| native_count="$(grep -E '^native_count=' "$output" | cut -d= -f2)" | ||
| rm -f "$output" | ||
|
|
||
| if (( native_count == 0 )); then | ||
| echo 'No unsynced native mono oss/ commits.' | ||
| exit 0 | ||
| fi | ||
| echo "Waiting for $native_count native mono oss/ commit(s)." | ||
| sleep 10 | ||
| done | ||
| echo 'Timed out waiting for mono-to-public sync.' >&2 | ||
| exit 1 | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.