1# Generated from xtask::workflows::extension_workflow_rollout
2# Rebuild with `cargo xtask workflows`.
3name: extension_workflow_rollout
4env:
5 CARGO_TERM_COLOR: always
6on:
7 workflow_dispatch:
8 inputs:
9 filter-repos:
10 description: Comma-separated list of repository names to rollout to. Leave empty for all repos.
11 type: string
12 default: ''
13 change-description:
14 description: Description for the changes to be expected with this rollout
15 type: string
16 default: ''
17jobs:
18 fetch_extension_repos:
19 if: (github.repository_owner == 'zed-industries' || github.repository_owner == 'zed-extensions') && github.ref == 'refs/heads/main'
20 runs-on: namespace-profile-2x4-ubuntu-2404
21 steps:
22 - name: checkout_zed_repo
23 uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
24 with:
25 clean: false
26 fetch-depth: 0
27 - id: prev-tag
28 name: extension_workflow_rollout::fetch_extension_repos::get_previous_tag_commit
29 run: |
30 PREV_COMMIT=$(git rev-parse "extension-workflows^{commit}" 2>/dev/null || echo "")
31 if [ -z "$PREV_COMMIT" ]; then
32 echo "::error::No previous rollout tag 'extension-workflows' found. Cannot determine file changes."
33 exit 1
34 fi
35 echo "Found previous rollout at commit: $PREV_COMMIT"
36 echo "prev_commit=$PREV_COMMIT" >> "$GITHUB_OUTPUT"
37 - id: calc-changes
38 name: extension_workflow_rollout::fetch_extension_repos::get_removed_files
39 run: |
40 for workflow_type in "ci" "shared"; do
41 if [ "$workflow_type" = "ci" ]; then
42 WORKFLOW_DIR="extensions/workflows"
43 else
44 WORKFLOW_DIR="extensions/workflows/shared"
45 fi
46
47 REMOVED=$(git diff --name-status -M "$PREV_COMMIT" HEAD -- "$WORKFLOW_DIR" | \
48 awk '/^D/ { print $2 } /^R/ { print $2 }' | \
49 xargs -I{} basename {} 2>/dev/null | \
50 tr '\n' ' ' || echo "")
51 REMOVED=$(echo "$REMOVED" | xargs)
52
53 echo "Removed files for $workflow_type: $REMOVED"
54 echo "removed_${workflow_type}=$REMOVED" >> "$GITHUB_OUTPUT"
55 done
56 env:
57 PREV_COMMIT: ${{ steps.prev-tag.outputs.prev_commit }}
58 - id: list-repos
59 name: extension_workflow_rollout::fetch_extension_repos::get_repositories
60 uses: actions/github-script@v7
61 with:
62 script: |
63 const repos = await github.paginate(github.rest.repos.listForOrg, {
64 org: 'zed-extensions',
65 type: 'public',
66 per_page: 100,
67 });
68
69 let filteredRepos = repos
70 .filter(repo => !repo.archived)
71 .map(repo => repo.name);
72
73 const filterInput = `${{ inputs.filter-repos }}`.trim();
74 if (filterInput.length > 0) {
75 const allowedNames = filterInput.split(',').map(s => s.trim()).filter(s => s.length > 0);
76 filteredRepos = filteredRepos.filter(name => allowedNames.includes(name));
77 console.log(`Filter applied. Matched ${filteredRepos.length} repos from ${allowedNames.length} requested.`);
78 }
79
80 console.log(`Found ${filteredRepos.length} extension repos`);
81 return filteredRepos;
82 result-encoding: json
83 - name: steps::cache_rust_dependencies_namespace
84 uses: namespacelabs/nscloud-cache-action@v1
85 with:
86 cache: rust
87 path: ~/.rustup
88 - name: extension_workflow_rollout::fetch_extension_repos::generate_workflow_files
89 run: |
90 cargo xtask workflows "$COMMIT_SHA"
91 env:
92 COMMIT_SHA: ${{ github.sha }}
93 - name: extension_workflow_rollout::fetch_extension_repos::upload_workflow_files
94 uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4
95 with:
96 name: extension-workflow-files
97 path: extensions/workflows/**/*.yml
98 if-no-files-found: error
99 outputs:
100 repos: ${{ steps.list-repos.outputs.result }}
101 prev_commit: ${{ steps.prev-tag.outputs.prev_commit }}
102 removed_ci: ${{ steps.calc-changes.outputs.removed_ci }}
103 removed_shared: ${{ steps.calc-changes.outputs.removed_shared }}
104 timeout-minutes: 10
105 rollout_workflows_to_extension:
106 needs:
107 - fetch_extension_repos
108 if: needs.fetch_extension_repos.outputs.repos != '[]'
109 runs-on: namespace-profile-2x4-ubuntu-2404
110 strategy:
111 matrix:
112 repo: ${{ fromJson(needs.fetch_extension_repos.outputs.repos) }}
113 fail-fast: false
114 max-parallel: 10
115 steps:
116 - id: generate-token
117 name: extension_bump::generate_token
118 uses: actions/create-github-app-token@v2
119 with:
120 app-id: ${{ secrets.ZED_ZIPPY_APP_ID }}
121 private-key: ${{ secrets.ZED_ZIPPY_APP_PRIVATE_KEY }}
122 owner: zed-extensions
123 repositories: ${{ matrix.repo }}
124 permission-pull-requests: write
125 permission-contents: write
126 permission-workflows: write
127 - name: checkout_extension_repo
128 uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
129 with:
130 clean: false
131 path: extension
132 repository: zed-extensions/${{ matrix.repo }}
133 token: ${{ steps.generate-token.outputs.token }}
134 - name: extension_workflow_rollout::rollout_workflows_to_extension::download_workflow_files
135 uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53
136 with:
137 name: extension-workflow-files
138 path: workflow-files
139 - name: extension_workflow_rollout::rollout_workflows_to_extension::sync_workflow_files
140 run: |
141 mkdir -p extension/.github/workflows
142
143 if [ "$MATRIX_REPO" = "workflows" ]; then
144 REMOVED_FILES="$REMOVED_CI"
145 else
146 REMOVED_FILES="$REMOVED_SHARED"
147 fi
148
149 cd extension/.github/workflows
150
151 if [ -n "$REMOVED_FILES" ]; then
152 for file in $REMOVED_FILES; do
153 if [ -f "$file" ]; then
154 rm -f "$file"
155 fi
156 done
157 fi
158
159 cd - > /dev/null
160
161 if [ "$MATRIX_REPO" = "workflows" ]; then
162 cp workflow-files/*.yml extension/.github/workflows/
163 else
164 cp workflow-files/shared/*.yml extension/.github/workflows/
165 fi
166 env:
167 REMOVED_CI: ${{ needs.fetch_extension_repos.outputs.removed_ci }}
168 REMOVED_SHARED: ${{ needs.fetch_extension_repos.outputs.removed_shared }}
169 MATRIX_REPO: ${{ matrix.repo }}
170 - id: short-sha
171 name: extension_workflow_rollout::rollout_workflows_to_extension::get_short_sha
172 run: |
173 echo "sha_short=$(echo "$GITHUB_SHA" | cut -c1-7)" >> "$GITHUB_OUTPUT"
174 - id: create-pr
175 name: extension_workflow_rollout::rollout_workflows_to_extension::create_pull_request
176 uses: peter-evans/create-pull-request@v7
177 with:
178 path: extension
179 title: Update CI workflows to `${{ steps.short-sha.outputs.sha_short }}`
180 body: |
181 This PR updates the CI workflow files from the main Zed repository
182 based on the commit zed-industries/zed@${{ github.sha }}
183
184 ${{ inputs.change-description }}
185 commit-message: Update CI workflows to `${{ steps.short-sha.outputs.sha_short }}`
186 branch: update-workflows
187 committer: zed-zippy[bot] <234243425+zed-zippy[bot]@users.noreply.github.com>
188 author: zed-zippy[bot] <234243425+zed-zippy[bot]@users.noreply.github.com>
189 base: main
190 delete-branch: true
191 token: ${{ steps.generate-token.outputs.token }}
192 sign-commits: true
193 - name: extension_workflow_rollout::rollout_workflows_to_extension::enable_auto_merge
194 run: |
195 if [ -n "$PR_NUMBER" ]; then
196 gh pr merge "$PR_NUMBER" --auto --squash
197 fi
198 env:
199 GH_TOKEN: ${{ steps.generate-token.outputs.token }}
200 PR_NUMBER: ${{ steps.create-pr.outputs.pull-request-number }}
201 working-directory: extension
202 timeout-minutes: 10
203 create_rollout_tag:
204 needs:
205 - rollout_workflows_to_extension
206 if: inputs.filter-repos == ''
207 runs-on: namespace-profile-2x4-ubuntu-2404
208 steps:
209 - id: generate-token
210 name: extension_bump::generate_token
211 uses: actions/create-github-app-token@v2
212 with:
213 app-id: ${{ secrets.ZED_ZIPPY_APP_ID }}
214 private-key: ${{ secrets.ZED_ZIPPY_APP_PRIVATE_KEY }}
215 permission-contents: write
216 - name: steps::checkout_repo
217 uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
218 with:
219 clean: false
220 fetch-depth: 0
221 token: ${{ steps.generate-token.outputs.token }}
222 - name: extension_workflow_rollout::create_rollout_tag::configure_git
223 run: |
224 git config user.name "zed-zippy[bot]"
225 git config user.email "234243425+zed-zippy[bot]@users.noreply.github.com"
226 - name: extension_workflow_rollout::create_rollout_tag::update_rollout_tag
227 run: |
228 if git rev-parse "extension-workflows" >/dev/null 2>&1; then
229 git tag -d "extension-workflows"
230 git push origin ":refs/tags/extension-workflows" || true
231 fi
232
233 echo "Creating new tag 'extension-workflows' at $(git rev-parse --short HEAD)"
234 git tag "extension-workflows"
235 git push origin "extension-workflows"
236 timeout-minutes: 1
237defaults:
238 run:
239 shell: bash -euxo pipefail {0}