@devries-cameron20 / composio Mirror · read-only
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 03:37 UTC

next
yml 184 lines 6.37 KB
Raw
1 name: Docs - Rebuild KB Semantic Artifact
2
3 on:
4 workflow_run:
5 workflows: ['Docs - Tests']
6 types: [completed]
7
8 permissions:
9 contents: read
10
11 jobs:
12 authorize:
13 name: Authorize originating pull request
14 runs-on: ubuntu-latest
15 timeout-minutes: 5
16 permissions:
17 actions: read
18 contents: read
19 pull-requests: read
20 outputs:
21 trusted: ${{ steps.trust.outputs.trusted }}
22 head_sha: ${{ steps.trust.outputs.head_sha }}
23 head_ref: ${{ steps.trust.outputs.head_ref }}
24
25 steps:
26 - name: Authorize originating pull request
27 id: trust
28 env:
29 GH_TOKEN: ${{ github.token }}
30 REPOSITORY: ${{ github.repository }}
31 RUN_ID: ${{ github.event.workflow_run.id }}
32 run: |
33 echo "trusted=false" >> "$GITHUB_OUTPUT"
34
35 run_json=$(gh api "repos/$REPOSITORY/actions/runs/$RUN_ID")
36 event_name=$(jq -r '.event' <<< "$run_json")
37 repository_id=$(jq -r '.repository.id' <<< "$run_json")
38 head_repository_id=$(jq -r '.head_repository.id // empty' <<< "$run_json")
39 head_branch=$(jq -r '.head_branch // empty' <<< "$run_json")
40 head_sha=$(jq -r '.head_sha // empty' <<< "$run_json")
41
42 if [ "$event_name" != "pull_request" ] ||
43 [ -z "$head_repository_id" ] ||
44 [ "$head_repository_id" != "$repository_id" ] ||
45 [ -z "$head_branch" ] ||
46 [ -z "$head_sha" ]; then
47 echo "Skipping a non-pull-request or fork workflow run."
48 exit 0
49 fi
50
51 pull_matches=$(jq -c \
52 --arg head_repository_id "$head_repository_id" \
53 --arg head_branch "$head_branch" \
54 --arg head_sha "$head_sha" \
55 '[
56 (.pull_requests // [])[]
57 | select(
58 (.head.repo.id | tostring) == $head_repository_id and
59 .head.ref == $head_branch and
60 .head.sha == $head_sha
61 )
62 ]' <<< "$run_json")
63
64 if [ "$(jq 'length' <<< "$pull_matches")" != "1" ]; then
65 echo "Skipping a workflow run without exactly one matching pull request."
66 exit 0
67 fi
68
69 pull_number=$(jq -r '.[0].number' <<< "$pull_matches")
70 pull_json=$(gh api "repos/$REPOSITORY/pulls/$pull_number")
71 association=$(jq -r '.author_association' <<< "$pull_json")
72 live_head_repository_id=$(jq -r '.head.repo.id // empty' <<< "$pull_json")
73 live_head_sha=$(jq -r '.head.sha // empty' <<< "$pull_json")
74 live_head_ref=$(jq -r '.head.ref // empty' <<< "$pull_json")
75 state=$(jq -r '.state' <<< "$pull_json")
76
77 if [ "$state" != "open" ] ||
78 [ "$live_head_repository_id" != "$repository_id" ] ||
79 [ "$live_head_sha" != "$head_sha" ] ||
80 [ "$live_head_ref" != "$head_branch" ]; then
81 echo "Skipping a closed or stale pull request."
82 exit 0
83 fi
84
85 case "$association" in
86 MEMBER|OWNER) ;;
87 *)
88 echo "Skipping a pull request whose author is not a repository member or owner."
89 exit 0
90 ;;
91 esac
92
93 echo "trusted=true" >> "$GITHUB_OUTPUT"
94 echo "head_sha=$live_head_sha" >> "$GITHUB_OUTPUT"
95 echo "head_ref=$live_head_ref" >> "$GITHUB_OUTPUT"
96
97 rebuild:
98 name: Rebuild stale artifact for trusted PRs
99 needs: authorize
100 if: needs.authorize.outputs.trusted == 'true'
101 runs-on: ubuntu-latest
102 timeout-minutes: 20
103 permissions:
104 contents: read
105 defaults:
106 run:
107 working-directory: ./docs
108
109 steps:
110 - name: Checkout pull request
111 uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
112 with:
113 ref: ${{ needs.authorize.outputs.head_sha }}
114 persist-credentials: false
115
116 - name: Setup Node.js, pnpm, Bun
117 uses: ./.github/actions/setup-node-pnpm-bun
118
119 - name: Cache Bun dependencies
120 uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
121 with:
122 path: ~/.bun/install/cache
123 key: ${{ runner.os }}-bun-${{ hashFiles('docs/bun.lock') }}
124 restore-keys: |
125 ${{ runner.os }}-bun-
126
127 - name: Install dependencies
128 run: bun install
129
130 - name: Check semantic artifact freshness
131 id: freshness
132 continue-on-error: true
133 run: bun run check:kb-semantic
134
135 - name: Rebuild semantic artifact
136 if: steps.freshness.outcome == 'failure'
137 env:
138 OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
139 run: bun run build:kb-semantic
140
141 - name: Verify rebuilt artifact
142 if: steps.freshness.outcome == 'failure'
143 run: bun run check:kb-semantic
144
145 - name: Generate write token
146 id: write-token
147 if: steps.freshness.outcome == 'failure'
148 uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0
149 with:
150 client-id: ${{ vars.RELEASE_BOT_CLIENT_ID }}
151 private-key: ${{ secrets.RELEASE_BOT_APP_PRIVATE_KEY }}
152 owner: ComposioHQ
153 repositories: composio
154 permission-contents: write
155
156 - name: Resolve bot identity
157 id: bot-user
158 if: steps.freshness.outcome == 'failure'
159 env:
160 APP_SLUG: ${{ steps.write-token.outputs.app-slug }}
161 GH_TOKEN: ${{ steps.write-token.outputs.token }}
162 run: |
163 user_id=$(gh api "/users/${APP_SLUG}[bot]" --jq '.id')
164 echo "user-id=$user_id" >> "$GITHUB_OUTPUT"
165
166 - name: Commit rebuilt artifact
167 if: steps.freshness.outcome == 'failure'
168 env:
169 APP_SLUG: ${{ steps.write-token.outputs.app-slug }}
170 BOT_USER_ID: ${{ steps.bot-user.outputs.user-id }}
171 GH_TOKEN: ${{ steps.write-token.outputs.token }}
172 HEAD_REF: ${{ needs.authorize.outputs.head_ref }}
173 run: |
174 git add kb/semantic-index.json
175 if git diff --cached --quiet; then
176 echo "::error::Semantic freshness failed, but rebuilding produced no tracked artifact changes."
177 exit 1
178 fi
179
180 git config user.name "${APP_SLUG}[bot]"
181 git config user.email "${BOT_USER_ID}+${APP_SLUG}[bot]@users.noreply.github.com"
182 git commit -m "chore(docs): rebuild KB semantic artifact"
183 gh auth setup-git
184 git push origin "HEAD:$HEAD_REF"