Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 115 additions & 0 deletions .github/workflows/sync-graphql-schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
name: Sync GraphQL Schema to UI

on:
workflow_dispatch:
push:
branches:
- main
paths:
- "graphql/schema/**"

concurrency:
group: sync-graphql-schema
cancel-in-progress: false

jobs:
sync-schema:
name: Sync GraphQL Schema and Open PR
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Generate GitHub App token
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.SYNC_APP_ID }}
private-key: ${{ secrets.SYNC_APP_PRIVATE_KEY }}
owner: evergreen-ci
repositories: ui

- name: Checkout evergreen repo
uses: actions/checkout@v4
with:
path: evergreen

- name: Clone evergreen-ci/ui repo
run: git clone https://x-access-token:${{ steps.app-token.outputs.token }}@github.com/evergreen-ci/ui.git ui

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "22.18.0"

- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10
run_install: false

- name: Install UI dependencies
working-directory: ui
run: pnpm install --frozen-lockfile

- name: Create sdlschema symlinks
run: |
ln -s ${{ github.workspace }}/evergreen/graphql/schema ui/apps/spruce/sdlschema
ln -s ${{ github.workspace }}/evergreen/graphql/schema ui/apps/parsley/sdlschema
ln -s ${{ github.workspace }}/evergreen/graphql/schema ui/packages/lib/sdlschema

- name: Run codegen
working-directory: ui
run: pnpm codegen

- name: Create branch, commit, and push
working-directory: ui
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

BRANCH="evergreen/sync-graphql-schema"
SHORT_SHA="${{ github.sha }}"
SHORT_SHA="${SHORT_SHA:0:7}"

git checkout -B "$BRANCH"
git add apps/spruce/src/gql/generated/types.ts
git add apps/parsley/src/gql/generated/types.ts
git add packages/lib/src/gql/generated/types.ts
git commit --allow-empty -m "Update generated GraphQL types from evergreen@${SHORT_SHA}"
git push --force-with-lease origin "$BRANCH"

- name: Create pull request
working-directory: ui
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
COMMIT_SHA="${{ github.sha }}"
SHORT_SHA="${COMMIT_SHA:0:7}"
COMMIT_URL="https://github.com/${{ github.repository }}/commit/${COMMIT_SHA}"
COMMIT_MSG=$(cd ${{ github.workspace }}/evergreen && git log -1 --format='%s')

# Extract DEVPROD ticket from the commit message if present
TICKET=$(echo "$COMMIT_MSG" | grep -oE 'DEVPROD-[0-9]+' | head -1)
if [ -z "$TICKET" ]; then
TICKET="DEVPROD-XXX"
fi

TITLE="${TICKET}: Bump GraphQL types from evergreen@${SHORT_SHA}"
BODY="$(cat <<EOF
${TICKET}

Bump GraphQL codegen TypeScript types after merge from evergreen@[${SHORT_SHA}](${COMMIT_URL}).

Triggered by: ${COMMIT_MSG}

---
*This PR was automatically generated by the [sync-graphql-schema](https://github.com/${{ github.repository }}/actions/workflows/sync-graphql-schema.yml) workflow.*
EOF
)"

gh pr create \
--repo evergreen-ci/ui \
--head "evergreen/sync-graphql-schema" \
--base main \
--title "$TITLE" \
--body "$BODY"
Loading