Skip to content

Commit

Permalink
feat: set fixed versions for vsix extensions (#1062)
Browse files Browse the repository at this point in the history
* feat: set fixed versions for vsix extensions; add script to update versions

Signed-off-by: Valeriy Svydenko <[email protected]>

* update doenload_vsix script

Signed-off-by: Valeriy Svydenko <[email protected]>

* remove built-in git extension

Signed-off-by: Valeriy Svydenko <[email protected]>

* add depended vscode.git extension

Signed-off-by: Valeriy Svydenko <[email protected]>

* add github action to update versions

Signed-off-by: Valeriy Svydenko <[email protected]>

* update workflow to check new versions each month

Signed-off-by: Valeriy Svydenko <[email protected]>

---------

Signed-off-by: Valeriy Svydenko <[email protected]>
  • Loading branch information
svor authored Apr 16, 2024
1 parent 7962c3b commit a4f79a1
Show file tree
Hide file tree
Showing 4 changed files with 516 additions and 262 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/update-vsix-versions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#
# Copyright (c) 2024 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#

name: Check new versions of VSIX extensions

on:
schedule:
- cron: '0 0 1 * *' # Run at midnight (00:00) on the 1st day of every month

jobs:
Check-new-extensions-versions:
runs-on: ubuntu-20.04

steps:

- name: Clone source code
uses: actions/checkout@v3
with:
fetch-depth: 1
token: ${{secrets.CRW_BUILD_TOKEN}}

- name: Validate content
run: |
cd dependencies/che-plugin-registry/build/scripts
./update_extensions_versions.sh
- name: Verify Changed files
uses: tj-actions/verify-changed-files@v19
id: verify-changed-files
with:
files: dependencies/che-plugin-registry/openvsx-sync.json

- name: Create Pull Request
if: steps.verify-changed-files.outputs.files_changed == 'true'
run: |
# Set up git configuration
export GITHUB_TOKEN=${{ secrets.CRW_BUILD_TOKEN }}
git config user.email "[email protected]"
git config user.name "devstudio-release"
# Create a new branch
git checkout -b new-extension-version-branch
# Add and commit changes
git add .
git commit -m "Auto-generated changes; update vsix extensions versions"
# Push changes to the remote repository
git push origin new-extension-version-branch
# Create a pull request
gh pr create --title "chore: Auto-generated PR to update extnesions versions" --body "This pull request was automatically generated by GitHub Actions" --base devspaces-3-rhel-8
176 changes: 73 additions & 103 deletions dependencies/che-plugin-registry/build/scripts/download_vsix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,32 @@ trap EXIT
set -e
set -o pipefail

downloadVsix=1
openvsxJson="/openvsx-server/openvsx-sync.json"

usage()
{
usage() {
echo "Usage: $0 -b devspaces-3.y-rhel-8 -j /path/to/openvsx-sync.json --no-download
All arguments are optional.
-b|--branch Specify a devspaces branch. Otherwise will be computed from local git directory
-j|--json Specify a path for openvsx-sync.json. Default: /openvsx-server/openvsx-sync.json
--no-download Do not download vsix files, only update versions in the openvsx-sync.json"
-j|--json Specify a path for openvsx-sync.json. Default: /openvsx-server/openvsx-sync.json"
exit
}

# commandline args
while [[ "$#" -gt 0 ]]; do
case $1 in
'-b'|'--branch') scriptBranch="$2"; shift 1;;
'-j'|'--json') openvsxJson="$2"; shift 1;;
'--no-download') downloadVsix=0;;
'-h'|'--help') usage;;
esac
shift 1
case $1 in
'-b' | '--branch')
scriptBranch="$2"
shift 1
;;
'-j' | '--json')
openvsxJson="$2"
shift 1
;;
'-h' | '--help') usage ;;
esac
shift 1
done

RED="\e[31m"
Expand All @@ -43,17 +45,16 @@ DEFAULT_EMOJI_FAIL="✘" # could be overriden with EMOJI_FAIL="[FAIL]"
EMOJI_FAIL=${EMOJI_FAIL:-$DEFAULT_EMOJI_FAIL}

function initTest() {
echo -n -e "${BOLD}\n${EMOJI_HEADER} ${1}${RESETSTYLE} ... "
echo -n -e "${BOLD}\n${EMOJI_HEADER} ${1}${RESETSTYLE} ... "
}

vsixMetadata="" #now global so it can be set/checked via function
getMetadata(){
getMetadata() {
vsixName=$1
key=$2

# check there is no error field in the metadata and retry if there is
for j in 1 2 3 4 5
do
for j in 1 2 3 4 5; do
vsixMetadata=$(curl -sLS "https://open-vsx.org/api/${vsixName}/${key}")
if [[ $(echo "${vsixMetadata}" | jq -r ".error") != null ]]; then
echo "Attempt $j/5: Error while getting metadata for ${vsixName} version ${key}"
Expand All @@ -70,11 +71,10 @@ getMetadata(){
}

versionsPage=""
getVersions(){
getVersions() {
vsixName=$1
# check the versions page is empty and retry if it is
for j in 1 2 3 4 5
do
for j in 1 2 3 4 5; do
versionsPage=$(curl -sLS "https://open-vsx.org/api/${vsixName}/versions?size=200")
totalSize=$(echo "${versionsPage}" | jq -r ".totalSize")
if [[ "$totalSize" != "null" && "$totalSize" -eq 0 ]]; then
Expand Down Expand Up @@ -106,7 +106,7 @@ fi
mkdir -p /tmp/vsix
openVsxSyncFileContent=$(cat "$openvsxJson")
numberOfExtensions=$(echo "${openVsxSyncFileContent}" | jq ". | length")
IFS=$'\n'
IFS=$'\n'

for i in $(seq 0 "$((numberOfExtensions - 1))"); do
vsixFullName=$(echo "${openVsxSyncFileContent}" | jq -r ".[$i].id")
Expand All @@ -124,63 +124,35 @@ for i in $(seq 0 "$((numberOfExtensions - 1))"); do
# grab metadata for the vsix file
# if version wasn't set, use latest
if [[ $vsixVersion == null ]]; then
getVersions "${vsixName}"
echo "Version is not set for ${vsixName}"
exit 1
fi

# if version wasn't set in json, grab it from metadata and add it into the file
# get all versions of the extension
allVersions=$(echo "${versionsPage}" | jq -r '.versions')
if [[ "$allVersions" == "{}" ]]; then
echo "No versions found for ${vsixName}"
exit 1
fi
key_value_pairs=$(echo "$allVersions" | jq -r 'to_entries[] | [ .key, .value ] | @tsv')

# go through all versions of the extension to find the latest stable version that is compatible with the VS Code version
resultedVersion=null
while IFS=$'\t' read -r key value; do
# get metadata for the version
getMetadata "${vsixName}" "${key}"

# check if the version is pre-release
preRelease=$(echo "${vsixMetadata}" | jq -r '.preRelease')
if [[ $preRelease == true ]]; then
echo "Skipping pre-release version ${value}"
continue
fi

# extract the engine version from the json metadata
vscodeEngineVersion=$(echo "${vsixMetadata}" | jq -r '.engines.vscode')
# remove ^ from the engine version
vscodeEngineVersion="${vscodeEngineVersion//^/}"
# remove >= from the engine version
vscodeEngineVersion="${vscodeEngineVersion//>=/}"
# replace x by 0 in the engine version
vscodeEngineVersion="${vscodeEngineVersion//x/0}"
# check if the extension's engine version is compatible with the code version
# if the extension's engine version is ahead of the code version, check a next version of the extension
if [[ "$vscodeEngineVersion" = "$(echo -e "$vscodeEngineVersion\n$codeVersion" | sort -V | head -n1)" ]]; then
#VS Code version >= Engine version, can proceed."
resultedVersion=$(echo "${vsixMetadata}" | jq -r ".version")
break
else
echo "Skipping ${value}, it is not compatible with VS Code editor $codeVersion"
continue
fi
done <<< "$key_value_pairs"

if [[ $resultedVersion == null ]]; then
echo "[ERROR] No stable version of $vsixFullName is compatible with VS Code editor verision $codeVersion; must exit!"
exit 1
else
vsixVersion=$resultedVersion
fi
# get metadata for the version
getMetadata "${vsixName}" "${vsixVersion}"

# check if the version is pre-release
preRelease=$(echo "${vsixMetadata}" | jq -r '.preRelease')
if [[ $preRelease == true ]]; then
echo "Version ${vsixVersion} is marked as pre-release for ${vsixName}, it should be stable one"
exit 1
fi

# extract the engine version from the json metadata
vscodeEngineVersion=$(echo "${vsixMetadata}" | jq -r '.engines.vscode')
# remove ^ from the engine version
vscodeEngineVersion="${vscodeEngineVersion//^/}"
# remove >= from the engine version
vscodeEngineVersion="${vscodeEngineVersion//>=/}"
# replace x by 0 in the engine version
vscodeEngineVersion="${vscodeEngineVersion//x/0}"
# check if the extension's engine version is compatible with the code version
# if the extension's engine version is ahead of the code version, print an error
if [[ "$vscodeEngineVersion" != "$(echo -e "$vscodeEngineVersion\n$codeVersion" | sort -V | head -n1)" ]]; then
echo "Version ${vsixVersion} of ${vsixName} is not compatible with VS Code editor $codeVersion"
exit 1
fi

jq --argjson i "$i" --arg version "$vsixVersion" '.[$i] += { "version": $version }' "$openvsxJson" > tmp.json
mv tmp.json "$openvsxJson"
else
getMetadata "${vsixName}" "${vsixVersion}"
fi

# extract the download link from the json metadata
vsixDownloadLink=$(echo "${vsixMetadata}" | jq -r '.files.download')
# get universal download link
Expand All @@ -196,32 +168,30 @@ for i in $(seq 0 "$((numberOfExtensions - 1))"); do
fi
fi

if [[ $downloadVsix = 1 ]]; then
echo "Downloading ${vsixDownloadLink} into ${vsixPublisher} folder..."
vsixFilename="/tmp/vsix/${vsixFullName}-${vsixVersion}.vsix"
# download the latest vsix file in the publisher directory
curl -sLS "${vsixDownloadLink}" -o "${vsixFilename}"

initTest "Checking $vsixFilename"

# Extract the supported version of VS Code engine from the package.json
vscodeEngineVersion=$(unzip -p "$vsixFilename" "extension/package.json" | jq -r '.engines.vscode')

# remove ^ from the engine version
vscodeEngineVersion="${vscodeEngineVersion//^/}"
# remove >= from the engine version
vscodeEngineVersion="${vscodeEngineVersion//>=/}"
# replace x by 0 in the engine version
vscodeEngineVersion="${vscodeEngineVersion//x/0}"
# check if the extension's engine version is compatible with the code version
# if the extension's engine version is ahead of the code version, check a next version of the extension
if [[ "$vscodeEngineVersion" = "$(echo -e "$vscodeEngineVersion\n$codeVersion" | sort -V | head -n1)" ]]; then
#VS Code version >= Engine version, can proceed."
echo -e "${GREEN}${EMOJI_PASS}${RESETSTYLE} compatible."
else
echo -e "Extension requires a newer engine version than Che Code version ($codeVersion)."
echo -e "${RED}${EMOJI_FAIL}${RESETSTYLE} Test failed!"
exit 1
fi
echo "Downloading ${vsixDownloadLink} into ${vsixPublisher} folder..."
vsixFilename="/tmp/vsix/${vsixFullName}-${vsixVersion}.vsix"
# download the latest vsix file in the publisher directory
curl -sLS "${vsixDownloadLink}" -o "${vsixFilename}"

initTest "Checking $vsixFilename"

# Extract the supported version of VS Code engine from the package.json
vscodeEngineVersion=$(unzip -p "$vsixFilename" "extension/package.json" | jq -r '.engines.vscode')

# remove ^ from the engine version
vscodeEngineVersion="${vscodeEngineVersion//^/}"
# remove >= from the engine version
vscodeEngineVersion="${vscodeEngineVersion//>=/}"
# replace x by 0 in the engine version
vscodeEngineVersion="${vscodeEngineVersion//x/0}"
# check if the extension's engine version is compatible with the code version
# if the extension's engine version is ahead of the code version, check a next version of the extension
if [[ "$vscodeEngineVersion" = "$(echo -e "$vscodeEngineVersion\n$codeVersion" | sort -V | head -n1)" ]]; then
#VS Code version >= Engine version, can proceed."
echo -e "${GREEN}${EMOJI_PASS}${RESETSTYLE} compatible."
else
echo -e "Extension requires a newer engine version than Che Code version ($codeVersion)."
echo -e "${RED}${EMOJI_FAIL}${RESETSTYLE} Test failed!"
exit 1
fi
done;
done
Loading

0 comments on commit a4f79a1

Please sign in to comment.