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: extension_bump::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        base: main
149        delete-branch: true
150        token: ${{ steps.generate-token.outputs.token }}
151        sign-commits: true
152        assignees: ${{ github.actor }}
153    timeout-minutes: 5
154    defaults:
155      run:
156        shell: bash -euxo pipefail {0}
157        working-directory: ${{ inputs.working-directory }}
158  create_version_label:
159    needs:
160    - check_version_changed
161    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'
162    runs-on: namespace-profile-2x4-ubuntu-2404
163    steps:
164    - id: generate-token
165      name: steps::generate_token
166      uses: actions/create-github-app-token@f8d387b68d61c58ab83c6c016672934102569859
167      with:
168        app-id: ${{ secrets.app-id }}
169        private-key: ${{ secrets.app-secret }}
170    - name: steps::checkout_repo
171      uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
172      with:
173        clean: false
174    - id: determine-tag
175      name: extension_bump::determine_tag
176      run: |
177        EXTENSION_ID="$(sed -n 's/^id = "\(.*\)"/\1/p' < extension.toml | head -1 | tr -d '[:space:]')"
178
179        if [[ "$WORKING_DIR" == "." || -z "$WORKING_DIR" ]]; then
180            TAG="v${CURRENT_VERSION}"
181        else
182            TAG="${EXTENSION_ID}-v${CURRENT_VERSION}"
183        fi
184
185        echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
186      env:
187        CURRENT_VERSION: ${{ needs.check_version_changed.outputs.current_version }}
188        WORKING_DIR: ${{ inputs.working-directory }}
189    - name: extension_bump::create_version_tag
190      uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b
191      with:
192        script: |-
193          github.rest.git.createRef({
194              owner: context.repo.owner,
195              repo: context.repo.repo,
196              ref: 'refs/tags/${{ steps.determine-tag.outputs.tag }}',
197              sha: context.sha
198          })
199        github-token: ${{ steps.generate-token.outputs.token }}
200    outputs:
201      tag: ${{ steps.determine-tag.outputs.tag }}
202    timeout-minutes: 1
203    defaults:
204      run:
205        shell: bash -euxo pipefail {0}
206        working-directory: ${{ inputs.working-directory }}
207  trigger_release:
208    needs:
209    - check_version_changed
210    - create_version_label
211    if: (github.repository_owner == 'zed-industries' || github.repository_owner == 'zed-extensions')
212    runs-on: namespace-profile-2x4-ubuntu-2404
213    steps:
214    - id: generate-token
215      name: steps::generate_token
216      uses: actions/create-github-app-token@f8d387b68d61c58ab83c6c016672934102569859
217      with:
218        app-id: ${{ secrets.app-id }}
219        private-key: ${{ secrets.app-secret }}
220        owner: zed-industries
221        repositories: extensions
222    - name: steps::checkout_repo
223      uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
224      with:
225        clean: false
226    - id: get-extension-id
227      name: extension_bump::get_extension_id
228      run: |
229        EXTENSION_ID="$(sed -n 's/id = \"\(.*\)\"/\1/p' < extension.toml)"
230
231        echo "extension_id=${EXTENSION_ID}" >> "$GITHUB_OUTPUT"
232    - id: extension-update
233      name: extension_bump::release_action
234      uses: huacnlee/zed-extension-action@82920ff0876879f65ffbcfa3403589114a8919c6
235      with:
236        extension-name: ${{ steps.get-extension-id.outputs.extension_id }}
237        push-to: zed-industries/extensions
238        tag: ${{ needs.create_version_label.outputs.tag }}
239      env:
240        COMMITTER_TOKEN: ${{ steps.generate-token.outputs.token }}
241    - name: extension_bump::enable_automerge_if_staff
242      uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b
243      with:
244        github-token: ${{ steps.generate-token.outputs.token }}
245        script: |
246          const prNumber = process.env.PR_NUMBER;
247          if (!prNumber) {
248              console.log('No pull request number set, skipping automerge.');
249              return;
250          }
251
252          const author = process.env.GITHUB_ACTOR;
253          let isStaff = false;
254          try {
255              const response = await github.rest.teams.getMembershipForUserInOrg({
256                  org: 'zed-industries',
257                  team_slug: 'staff',
258                  username: author
259              });
260              isStaff = response.data.state === 'active';
261          } catch (error) {
262              if (error.status !== 404) {
263                  throw error;
264              }
265          }
266
267          if (!isStaff) {
268              console.log(`Actor ${author} is not a staff member, skipping automerge.`);
269              return;
270          }
271
272          // Assign staff member responsible for the bump
273          const pullNumber = parseInt(prNumber);
274
275          await github.rest.issues.addAssignees({
276              owner: 'zed-industries',
277              repo: 'extensions',
278              issue_number: pullNumber,
279              assignees: [author]
280          });
281          console.log(`Assigned ${author} to PR #${prNumber} in zed-industries/extensions`);
282
283          // Get the GraphQL node ID
284          const { data: pr } = await github.rest.pulls.get({
285              owner: 'zed-industries',
286              repo: 'extensions',
287              pull_number: pullNumber
288          });
289
290          await github.graphql(`
291              mutation($pullRequestId: ID!) {
292                  enablePullRequestAutoMerge(input: { pullRequestId: $pullRequestId, mergeMethod: SQUASH }) {
293                      pullRequest {
294                          autoMergeRequest {
295                              enabledAt
296                          }
297                      }
298                  }
299              }
300          `, { pullRequestId: pr.node_id });
301
302          console.log(`Automerge enabled for PR #${prNumber} in zed-industries/extensions`);
303      env:
304        PR_NUMBER: ${{ steps.extension-update.outputs.pull-request-number }}
305    defaults:
306      run:
307        shell: bash -euxo pipefail {0}
308        working-directory: ${{ inputs.working-directory }}
309concurrency:
310  group: ${{ github.workflow }}-${{ github.ref_name }}-${{ github.ref_name == 'main' && github.sha || 'anysha' }}extension-bump
311  cancel-in-progress: true
312defaults:
313  run:
314    shell: bash -euxo pipefail {0}