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: 03d8e9aee95ea6117d75a48bcac2e19241f6e667
  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@11bd71901bbe5b1630ceea73d27597364c9af683
 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: extension_bump::generate_token
 78      uses: actions/create-github-app-token@v2
 79      with:
 80        app-id: ${{ secrets.app-id }}
 81        private-key: ${{ secrets.app-secret }}
 82    - name: steps::checkout_repo
 83      uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
 84      with:
 85        clean: false
 86    - name: steps::cache_rust_dependencies_namespace
 87      uses: namespacelabs/nscloud-cache-action@v1
 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 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=This PR bumps the version of the ${EXTENSION_NAME} extension to v${NEW_VERSION}";
125                echo "branch_name=zed-zippy-${EXTENSION_ID}-autobump";
126            } >> "$GITHUB_OUTPUT"
127        fi
128
129        echo "new_version=${NEW_VERSION}" >> "$GITHUB_OUTPUT"
130      env:
131        OLD_VERSION: ${{ needs.check_version_changed.outputs.current_version }}
132        BUMP_TYPE: ${{ inputs.bump-type }}
133        WORKING_DIR: ${{ inputs.working-directory }}
134    - name: extension_bump::create_pull_request
135      uses: peter-evans/create-pull-request@v7
136      with:
137        title: ${{ steps.bump-version.outputs.title }}
138        body: ${{ steps.bump-version.outputs.body }}
139        commit-message: ${{ steps.bump-version.outputs.title }}
140        branch: ${{ steps.bump-version.outputs.branch_name }}
141        committer: zed-zippy[bot] <234243425+zed-zippy[bot]@users.noreply.github.com>
142        base: main
143        delete-branch: true
144        token: ${{ steps.generate-token.outputs.token }}
145        sign-commits: true
146        assignees: ${{ github.actor }}
147    timeout-minutes: 5
148    defaults:
149      run:
150        shell: bash -euxo pipefail {0}
151        working-directory: ${{ inputs.working-directory }}
152  create_version_label:
153    needs:
154    - check_version_changed
155    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'
156    runs-on: namespace-profile-2x4-ubuntu-2404
157    steps:
158    - id: generate-token
159      name: extension_bump::generate_token
160      uses: actions/create-github-app-token@v2
161      with:
162        app-id: ${{ secrets.app-id }}
163        private-key: ${{ secrets.app-secret }}
164    - name: steps::checkout_repo
165      uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
166      with:
167        clean: false
168    - id: determine-tag
169      name: extension_bump::determine_tag
170      run: |
171        EXTENSION_ID="$(sed -n 's/^id = "\(.*\)"/\1/p' < extension.toml | head -1 | tr -d '[:space:]')"
172
173        if [[ "$WORKING_DIR" == "." || -z "$WORKING_DIR" ]]; then
174            TAG="v${CURRENT_VERSION}"
175        else
176            TAG="${EXTENSION_ID}-v${CURRENT_VERSION}"
177        fi
178
179        echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
180      env:
181        CURRENT_VERSION: ${{ needs.check_version_changed.outputs.current_version }}
182        WORKING_DIR: ${{ inputs.working-directory }}
183    - name: extension_bump::create_version_tag
184      uses: actions/github-script@v7
185      with:
186        script: |-
187          github.rest.git.createRef({
188              owner: context.repo.owner,
189              repo: context.repo.repo,
190              ref: 'refs/tags/${{ steps.determine-tag.outputs.tag }}',
191              sha: context.sha
192          })
193        github-token: ${{ steps.generate-token.outputs.token }}
194    outputs:
195      tag: ${{ steps.determine-tag.outputs.tag }}
196    timeout-minutes: 1
197    defaults:
198      run:
199        shell: bash -euxo pipefail {0}
200        working-directory: ${{ inputs.working-directory }}
201  trigger_release:
202    needs:
203    - check_version_changed
204    - create_version_label
205    if: (github.repository_owner == 'zed-industries' || github.repository_owner == 'zed-extensions')
206    runs-on: namespace-profile-2x4-ubuntu-2404
207    steps:
208    - id: generate-token
209      name: extension_bump::generate_token
210      uses: actions/create-github-app-token@v2
211      with:
212        app-id: ${{ secrets.app-id }}
213        private-key: ${{ secrets.app-secret }}
214        owner: zed-industries
215        repositories: extensions
216    - name: steps::checkout_repo
217      uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
218      with:
219        clean: false
220    - id: get-extension-id
221      name: extension_bump::get_extension_id
222      run: |
223        EXTENSION_ID="$(sed -n 's/id = \"\(.*\)\"/\1/p' < extension.toml)"
224
225        echo "extension_id=${EXTENSION_ID}" >> "$GITHUB_OUTPUT"
226    - name: extension_bump::release_action
227      uses: huacnlee/zed-extension-action@v2
228      with:
229        extension-name: ${{ steps.get-extension-id.outputs.extension_id }}
230        push-to: zed-industries/extensions
231        tag: ${{ needs.create_version_label.outputs.tag }}
232      env:
233        COMMITTER_TOKEN: ${{ steps.generate-token.outputs.token }}
234    defaults:
235      run:
236        shell: bash -euxo pipefail {0}
237        working-directory: ${{ inputs.working-directory }}
238concurrency:
239  group: ${{ github.workflow }}-${{ github.ref_name }}-${{ github.ref_name == 'main' && github.sha || 'anysha' }}extension-bump
240  cancel-in-progress: true
241defaults:
242  run:
243    shell: bash -euxo pipefail {0}