Repository navigation
Expand file tree
/
Copy pathenable-autopilot-rollouts-command.yml
More file actions
210 lines (186 loc) · 8.31 KB
/
Copy pathenable-autopilot-rollouts-command.yml
File metadata and controls
210 lines (186 loc) · 8.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
name: Enable autopilot rollouts for connectors in a PR
on:
workflow_dispatch:
inputs:
pr:
description: "Pull request number. The connector metadata edit is committed to this PR's branch."
type: number
required: false
comment-id:
description: "Optional. The comment-id of the slash command. Used to update the comment with the status."
required: false
connector:
description: "Optional. Explicit connector name (e.g. source-github). If omitted, modified connectors in the PR are detected."
required: false
default: ""
strategy:
description: "Optional. Autopilot pacing strategy: fast, slow, or default. Defaults to fast."
required: false
default: "fast"
# These must be declared, but they are unused and ignored.
# TODO: Infer 'repo' and 'gitref' from PR number on other workflows, so we can remove these.
repo:
description: "Repo (Ignored)"
required: false
default: "airbytehq/airbyte"
gitref:
description: "Ref (Ignored)"
required: false
env:
SENTRY_ENVIRONMENT: gitops-prod
permissions:
contents: read
issues: write
pull-requests: write
run-name: "Enable autopilot rollouts in PR: #${{ github.event.inputs.pr }}"
concurrency:
group: ${{ github.workflow }}-${{ github.event.inputs.pr }}
# Cancel any previous runs on the same branch if they are still in progress
cancel-in-progress: true
jobs:
enable-autopilot-rollouts:
name: "Enable autopilot rollouts for connectors in this PR"
runs-on: ubuntu-24.04
steps:
- name: Get job variables
id: job-vars
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.inputs.pr }}
shell: bash
run: |
PR_JSON=$(gh api "repos/${{ github.repository }}/pulls/$PR_NUMBER")
echo "repo=$(echo "$PR_JSON" | jq -r .head.repo.full_name)" >> $GITHUB_OUTPUT
echo "branch=$(echo "$PR_JSON" | jq -r .head.ref)" >> $GITHUB_OUTPUT
echo "run-url=https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" >> $GITHUB_OUTPUT
# NOTE: We still use a PAT here (rather than a GitHub App) because the workflow needs
# permissions to add commits to our main repo as well as forks. This will only work on
# forks if the user installs the app into their fork. Until we document this as a clear
# path, we will have to keep using the PAT.
- name: Checkout Airbyte
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
repository: ${{ steps.job-vars.outputs.repo }}
ref: ${{ steps.job-vars.outputs.branch }}
fetch-depth: 1
# Important that token is a PAT so that CI checks are triggered again.
# Without this we would be forever waiting on required checks to pass.
token: ${{ secrets.GH_PAT_APPROVINGTON_OCTAVIA }}
- name: Append comment with job run link
# If comment-id is not provided, this will create a new
# comment with the job run link.
id: first-comment-action
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0
with:
comment-id: ${{ github.event.inputs.comment-id }}
issue-number: ${{ github.event.inputs.pr }}
body: |
> Enable Autopilot Rollouts job started... [Check job output.][1]
[1]: ${{ steps.job-vars.outputs.run-url }}
- name: Install uv
uses: astral-sh/setup-uv@cec208311dfd045dd5311c1add060b2062131d57 # v8.0.0
- name: Install airbyte-ops CLI
run: uv tool install airbyte-internal-ops
- name: Resolve target connectors
id: detect-connectors
env:
PR_NUMBER: ${{ github.event.inputs.pr }}
EXPLICIT_CONNECTOR: ${{ github.event.inputs.connector }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [ -n "$EXPLICIT_CONNECTOR" ]; then
echo "Using explicitly requested connector: $EXPLICIT_CONNECTOR"
CONNECTORS="$EXPLICIT_CONNECTOR"
else
echo "No connector specified; detecting modified connectors in PR #$PR_NUMBER."
CONNECTORS=$(
airbyte-ops local connector list \
--repo-path "$GITHUB_WORKSPACE" \
--modified-only \
--pr "$PR_NUMBER" \
--gh-token "$GH_TOKEN" \
--output-format lines
)
fi
if [ -z "$CONNECTORS" ]; then
echo "No connectors to update."
else
echo "Target connectors:"
echo "$CONNECTORS"
fi
# Pass the connector list to the next step via GITHUB_OUTPUT.
# Only set the multiline output when CONNECTORS is non-empty so that
# the downstream `if:` reliably evaluates to false for empty lists.
if [ -n "$CONNECTORS" ]; then
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "connectors<<$EOF" >> $GITHUB_OUTPUT
echo "$CONNECTORS" >> $GITHUB_OUTPUT
echo "$EOF" >> $GITHUB_OUTPUT
fi
- name: Enable autopilot rollouts for target connectors
if: steps.detect-connectors.outputs.connectors != ''
env:
STRATEGY: ${{ github.event.inputs.strategy }}
CONNECTORS: ${{ steps.detect-connectors.outputs.connectors }}
run: |
echo "Strategy: $STRATEGY"
echo ""
echo "$CONNECTORS" | while IFS= read -r connector; do
[ -z "$connector" ] && continue
echo "--- Enabling autopilot rollouts for $connector ---"
airbyte-ops local connector rollouts enable \
--name "$connector" \
--repo-path "$GITHUB_WORKSPACE" \
--strategy "$STRATEGY"
done
# This is helpful in the case that we change a previously committed generated file to be ignored by git.
- name: Remove any files that have been gitignored
run: git ls-files -i -c --exclude-from=.gitignore | xargs -r git rm --cached
# Check for changes in git
- name: Check for changes
id: git-diff
run: |
git diff --quiet && echo "No changes to commit" || echo "changes=true" >> $GITHUB_OUTPUT
shell: bash
# Commit changes (if any)
- name: Commit changes
id: commit-step
if: steps.git-diff.outputs.changes == 'true'
run: |
git config --global user.name "Octavia Squidington III"
git config --global user.email "octavia-squidington-iii@users.noreply.github.com"
git add .
git commit -m "chore: enable autopilot rollouts"
echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
- name: Push changes to '(${{ steps.job-vars.outputs.repo }})'
if: steps.git-diff.outputs.changes == 'true'
env:
CONTRIBUTOR_REPO: ${{ steps.job-vars.outputs.repo }}
HEAD_BRANCH: ${{ steps.job-vars.outputs.branch }}
run: |
git remote add contributor "https://github.com/$CONTRIBUTOR_REPO.git"
git push contributor "HEAD:$HEAD_BRANCH"
- name: Append success comment
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0
if: steps.git-diff.outputs.changes == 'true'
with:
comment-id: ${{ steps.first-comment-action.outputs.comment-id }}
reactions: hooray
body: |
> ✅ Autopilot rollouts enabled. (${{ steps.commit-step.outputs.sha }})
- name: Append success comment (no-op)
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0
if: steps.git-diff.outputs.changes != 'true'
with:
comment-id: ${{ steps.first-comment-action.outputs.comment-id }}
reactions: eyes
body: |
> ℹ️ No changes applied — autopilot rollouts already enabled for the target connector(s).
- name: Append failure comment
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0
if: failure()
with:
comment-id: ${{ steps.first-comment-action.outputs.comment-id }}
reactions: confused
body: |
> 🔴 Job failed.