Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add action to update vscode extension with latest version #394

Merged
merged 1 commit into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .github/actions/update-vscode-extension/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Update VSCode Extension

description: 'Update the CLI version in vscode-extension'

inputs:
latest_tag:
required: true
description: 'The latest tag from the workflow that uses this action'
access_token:
required: true
description: 'The access token to use for authentication'

runs:
using: 'composite'
steps:
- name: Check out code
uses: actions/checkout@v3
with:
repository: DevCycleHQ/vscode-extension
path: vscode-extension
token: ${{ inputs.access_token }}
fetch-depth: 0

- name: Set Git author
shell: bash
working-directory: vscode-extension
run: |
git config --global user.email "[email protected]"
git config --global user.name "DevCycle Automation"

- name: Set branch name
shell: bash
working-directory: vscode-extension
run: echo "BRANCH_NAME=update-cli-version-to-${{ inputs.latest_tag }}" >> $GITHUB_ENV

- name: Update CLI version in vscode extension
shell: bash
working-directory: vscode-extension
run: |
# Remove 'v' prefix from latest_tag
LATEST_TAG="${{ inputs.latest_tag }}"
CLI_VERSION="${LATEST_TAG#v}"
git checkout -b "$BRANCH_NAME"
sed -i "s/export const CLI_VERSION = .*/export const CLI_VERSION = '${CLI_VERSION}' \/\/ auto updated by dvc cli release workflow/" src/constants.ts
git add src/constants.ts
git commit -m "Update CLI version to ${{ inputs.latest_tag }}"

- name: Push code to extension repo
shell: bash
working-directory: vscode-extension
run: git push --set-upstream origin "$BRANCH_NAME"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider adding error handling for git push

Adding error handling for the git push command can help catch and handle any issues that might occur during the push operation, ensuring the workflow does not fail silently.

Suggested change
run: git push --set-upstream origin "$BRANCH_NAME"
run: |
set -e
git push --set-upstream origin "$BRANCH_NAME" || {
echo "Error: Failed to push code to the repository."
exit 1
}


- name: Create PR
shell: bash
working-directory: vscode-extension
env:
GH_TOKEN: ${{ inputs.access_token }}
run: gh pr create --repo DevCycleHQ/vscode-extension --base main --head "$BRANCH_NAME" --title "Update CLI version to $LATEST_TAG" --body "This PR was automatically created by the DevCycle CLI release workflow."
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Use inputs.latest_tag instead of $LATEST_TAG

The variable $LATEST_TAG is not defined in this context. It should be replaced with ${{ inputs.latest_tag }} to ensure the correct value is used.

7 changes: 7 additions & 0 deletions .github/workflows/cli-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ jobs:
with:
latest_tag: $LATEST_TAG
access_token: ${{ secrets.AUTOMATION_USER_TOKEN }}

- name: Update VSCode Extension
if: inputs.npm-version == 'minor' || inputs.npm-version == 'patch'
uses: ./.github/actions/update-vscode-extension
with:
latest_tag: $LATEST_TAG
access_token: ${{ secrets.AUTOMATION_USER_TOKEN }}

# Move this to release action yml once it works the first time
- name: Update Homebrew Formula
Expand Down
Loading