extension_bump.yml

  1# Generated from xtask::workflows::extension_bump
  2# Rebuild with `cargo xtask workflows`.
  3name: extension_bump
  4env:
  5  CARGO_TERM_COLOR: always
  6  RUST_BACKTRACE: '1'
  7  CARGO_INCREMENTAL: '0'
  8  ZED_EXTENSION_CLI_SHA: 1fa7f1a3ec28ea1eae6db2e937d7a538fb10c0c7
  9on:
 10  workflow_call:
 11    inputs:
 12      bump-type:
 13        description: bump-type
 14        type: string
 15        default: patch
 16      force-bump:
 17        description: force-bump
 18        required: true
 19        type: boolean
 20      working-directory:
 21        description: working-directory
 22        type: string
 23        default: .
 24    secrets:
 25      app-id:
 26        description: The app ID used to create the PR
 27        required: true
 28      app-secret:
 29        description: The app secret for the corresponding app ID
 30        required: true
 31jobs:
 32  check_version_changed:
 33    if: (github.repository_owner == 'zed-industries' || github.repository_owner == 'zed-extensions')
 34    runs-on: namespace-profile-2x4-ubuntu-2404
 35    steps:
 36    - name: steps::checkout_repo
 37      uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
 38      with:
 39        clean: false
 40        fetch-depth: 0
 41    - id: compare-versions-check
 42      name: extension_bump::compare_versions
 43      run: |
 44        CURRENT_VERSION="$(sed -n 's/^version = \"\(.*\)\"/\1/p' < extension.toml | tr -d '[:space:]')"
 45
 46        if [[ "$GITHUB_EVENT_NAME" == "pull_request" ]]; then
 47            PR_FORK_POINT="$(git merge-base origin/main HEAD)"
 48            git checkout "$PR_FORK_POINT"
 49        else
 50            git checkout "$(git log -1 --format=%H)"~1
 51        fi
 52
 53        PARENT_COMMIT_VERSION="$(sed -n 's/^version = \"\(.*\)\"/\1/p' < extension.toml | tr -d '[:space:]')"
 54
 55        [[ "$CURRENT_VERSION" == "$PARENT_COMMIT_VERSION" ]] && \
 56            echo "version_changed=false" >> "$GITHUB_OUTPUT" || \
 57            echo "version_changed=true" >> "$GITHUB_OUTPUT"
 58
 59        echo "current_version=${CURRENT_VERSION}" >> "$GITHUB_OUTPUT"
 60    outputs:
 61      version_changed: ${{ steps.compare-versions-check.outputs.version_changed }}
 62      current_version: ${{ steps.compare-versions-check.outputs.current_version }}
 63    timeout-minutes: 1
 64    defaults:
 65      run:
 66        shell: bash -euxo pipefail {0}
 67        working-directory: ${{ inputs.working-directory }}
 68  bump_extension_version:
 69    needs:
 70    - check_version_changed
 71    if: |-
 72      (github.repository_owner == 'zed-industries' || github.repository_owner == 'zed-extensions') &&
 73      (inputs.force-bump == true || needs.check_version_changed.outputs.version_changed == 'false')
 74    runs-on: namespace-profile-2x4-ubuntu-2404
 75    steps:
 76    - id: generate-token
 77      name: steps::generate_token
 78      uses: actions/create-github-app-token@f8d387b68d61c58ab83c6c016672934102569859
 79      with:
 80        app-id: ${{ secrets.app-id }}
 81        private-key: ${{ secrets.app-secret }}
 82    - name: steps::checkout_repo
 83      uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
 84      with:
 85        clean: false
 86    - name: steps::cache_rust_dependencies_namespace
 87      uses: namespacelabs/nscloud-cache-action@a90bb5d4b27522ce881c6e98eebd7d7e6d1653f9
 88      with:
 89        cache: rust
 90        path: ~/.rustup
 91    - name: extension_bump::install_bump_2_version
 92      run: pip install bump2version --break-system-packages
 93    - id: bump-version
 94      name: extension_bump::bump_version
 95      run: |
 96        BUMP_FILES=("extension.toml")
 97        if [[ -f "Cargo.toml" ]]; then
 98            BUMP_FILES+=("Cargo.toml")
 99        fi
100
101        bump2version \
102            --search "version = \"{current_version}"\" \
103            --replace "version = \"{new_version}"\" \
104            --current-version "$OLD_VERSION" \
105            --no-configured-files "$BUMP_TYPE" "${BUMP_FILES[@]}"
106
107        if [[ -f "Cargo.toml" ]]; then
108            cargo +stable update --workspace
109        fi
110
111        NEW_VERSION="$(sed -n 's/^version = \"\(.*\)\"/\1/p' < extension.toml | tr -d '[:space:]')"
112        EXTENSION_ID="$(sed -n 's/^id = "\(.*\)"/\1/p' < extension.toml | head -1 | tr -d '[:space:]')"
113        EXTENSION_NAME="$(sed -n 's/^name = "\(.*\)"/\1/p' < extension.toml | head -1 | tr -d '[:space:]')"
114
115        if [[ "$WORKING_DIR" == "." || -z "$WORKING_DIR" ]]; then
116            {
117                echo "title=Bump version to ${NEW_VERSION}";
118                echo "body=This PR bumps the version of this extension to v${NEW_VERSION}";
119                echo "branch_name=zed-zippy-autobump";
120            } >> "$GITHUB_OUTPUT"
121        else
122            {
123                echo "title=${EXTENSION_ID}: Bump to v${NEW_VERSION}";
124                echo "body<<EOF";
125                echo "This PR bumps the version of the ${EXTENSION_NAME} extension to v${NEW_VERSION}.";
126                echo "";
127                echo "Release Notes:";
128                echo "";
129                echo "- N/A";
130                echo "EOF";
131                echo "branch_name=zed-zippy-${EXTENSION_ID}-autobump";
132            } >> "$GITHUB_OUTPUT"
133        fi
134
135        echo "new_version=${NEW_VERSION}" >> "$GITHUB_OUTPUT"
136      env:
137        OLD_VERSION: ${{ needs.check_version_changed.outputs.current_version }}
138        BUMP_TYPE: ${{ inputs.bump-type }}
139        WORKING_DIR: ${{ inputs.working-directory }}
140    - name: steps::create_pull_request
141      uses: peter-evans/create-pull-request@98357b18bf14b5342f975ff684046ec3b2a07725
142      with:
143        title: ${{ steps.bump-version.outputs.title }}
144        body: ${{ steps.bump-version.outputs.body }}
145        commit-message: ${{ steps.bump-version.outputs.title }}
146        branch: ${{ steps.bump-version.outputs.branch_name }}
147        committer: zed-zippy[bot] <234243425+zed-zippy[bot]@users.noreply.github.com>
148        author: zed-zippy[bot] <234243425+zed-zippy[bot]@users.noreply.github.com>
149        base: main
150        delete-branch: true
151        token: ${{ steps.generate-token.outputs.token }}
152        sign-commits: true
153        assignees: ${{ github.actor }}
154    timeout-minutes: 5
155    defaults:
156      run:
157        shell: bash -euxo pipefail {0}
158        working-directory: ${{ inputs.working-directory }}
159  create_version_label:
160    needs:
161    - check_version_changed
162    if: (github.repository_owner == 'zed-industries' || github.repository_owner == 'zed-extensions') && github.event_name == 'push' && github.ref == 'refs/heads/main' && needs.check_version_changed.outputs.version_changed == 'true'
163    runs-on: namespace-profile-2x4-ubuntu-2404
164    steps:
165    - id: generate-token
166      name: steps::generate_token
167      uses: actions/create-github-app-token@f8d387b68d61c58ab83c6c016672934102569859
168      with:
169        app-id: ${{ secrets.app-id }}
170        private-key: ${{ secrets.app-secret }}
171    - name: steps::checkout_repo
172      uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
173      with:
174        clean: false
175    - id: determine-tag
176      name: extension_bump::determine_tag
177      run: |
178        EXTENSION_ID="$(sed -n 's/^id = "\(.*\)"/\1/p' < extension.toml | head -1 | tr -d '[:space:]')"
179
180        if [[ "$WORKING_DIR" == "." || -z "$WORKING_DIR" ]]; then
181            TAG="v${CURRENT_VERSION}"
182        else
183            TAG="${EXTENSION_ID}-v${CURRENT_VERSION}"
184        fi
185
186        echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
187      env:
188        CURRENT_VERSION: ${{ needs.check_version_changed.outputs.current_version }}
189        WORKING_DIR: ${{ inputs.working-directory }}
190    - name: extension_bump::create_version_tag
191      uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b
192      with:
193        script: |-
194          github.rest.git.createRef({
195              owner: context.repo.owner,
196              repo: context.repo.repo,
197              ref: 'refs/tags/${{ steps.determine-tag.outputs.tag }}',
198              sha: context.sha
199          })
200        github-token: ${{ steps.generate-token.outputs.token }}
201    outputs:
202      tag: ${{ steps.determine-tag.outputs.tag }}
203    timeout-minutes: 1
204    defaults:
205      run:
206        shell: bash -euxo pipefail {0}
207        working-directory: ${{ inputs.working-directory }}
208  trigger_release:
209    needs:
210    - check_version_changed
211    - create_version_label
212    if: (github.repository_owner == 'zed-industries' || github.repository_owner == 'zed-extensions')
213    runs-on: namespace-profile-2x4-ubuntu-2404
214    steps:
215    - id: generate-token
216      name: steps::generate_token
217      uses: actions/create-github-app-token@f8d387b68d61c58ab83c6c016672934102569859
218      with:
219        app-id: ${{ secrets.app-id }}
220        private-key: ${{ secrets.app-secret }}
221        owner: zed-industries
222        repositories: extensions
223    - name: steps::checkout_repo
224      uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
225      with:
226        clean: false
227    - id: get-extension-id
228      name: extension_bump::get_extension_id
229      run: |
230        EXTENSION_ID="$(sed -n 's/id = \"\(.*\)\"/\1/p' < extension.toml)"
231
232        echo "extension_id=${EXTENSION_ID}" >> "$GITHUB_OUTPUT"
233    - id: extension-update
234      name: extension_bump::release_action
235      uses: huacnlee/zed-extension-action@82920ff0876879f65ffbcfa3403589114a8919c6
236      with:
237        extension-name: ${{ steps.get-extension-id.outputs.extension_id }}
238        push-to: zed-industries/extensions
239        tag: ${{ needs.create_version_label.outputs.tag }}
240      env:
241        COMMITTER_TOKEN: ${{ steps.generate-token.outputs.token }}
242    - name: extension_bump::enable_automerge_if_staff
243      uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b
244      with:
245        github-token: ${{ steps.generate-token.outputs.token }}
246        script: |
247          const prNumber = process.env.PR_NUMBER;
248          if (!prNumber) {
249              console.log('No pull request number set, skipping automerge.');
250              return;
251          }
252
253          const author = process.env.GITHUB_ACTOR;
254          let isStaff = false;
255          try {
256              const response = await github.rest.teams.getMembershipForUserInOrg({
257                  org: 'zed-industries',
258                  team_slug: 'staff',
259                  username: author
260              });
261              isStaff = response.data.state === 'active';
262          } catch (error) {
263              if (error.status !== 404) {
264                  throw error;
265              }
266          }
267
268          if (!isStaff) {
269              console.log(`Actor ${author} is not a staff member, skipping automerge.`);
270              return;
271          }
272
273          // Assign staff member responsible for the bump
274          const pullNumber = parseInt(prNumber);
275
276          await github.rest.issues.addAssignees({
277              owner: 'zed-industries',
278              repo: 'extensions',
279              issue_number: pullNumber,
280              assignees: [author]
281          });
282          console.log(`Assigned ${author} to PR #${prNumber} in zed-industries/extensions`);
283
284          // Get the GraphQL node ID
285          const { data: pr } = await github.rest.pulls.get({
286              owner: 'zed-industries',
287              repo: 'extensions',
288              pull_number: pullNumber
289          });
290
291          await github.graphql(`
292              mutation($pullRequestId: ID!) {
293                  enablePullRequestAutoMerge(input: { pullRequestId: $pullRequestId, mergeMethod: SQUASH }) {
294                      pullRequest {
295                          autoMergeRequest {
296                              enabledAt
297                          }
298                      }
299                  }
300              }
301          `, { pullRequestId: pr.node_id });
302
303          console.log(`Automerge enabled for PR #${prNumber} in zed-industries/extensions`);
304      env:
305        PR_NUMBER: ${{ steps.extension-update.outputs.pull-request-number }}
306    defaults:
307      run:
308        shell: bash -euxo pipefail {0}
309        working-directory: ${{ inputs.working-directory }}
310concurrency:
311  group: ${{ github.workflow }}-${{ github.ref_name }}-${{ github.ref_name == 'main' && github.sha || 'anysha' }}extension-bump
312  cancel-in-progress: true
313defaults:
314  run:
315    shell: bash -euxo pipefail {0}