Skip to content

Commit

Permalink
feat: add workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
s1n7ax committed Dec 24, 2024
1 parent b543a64 commit 8673368
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 43 deletions.
35 changes: 2 additions & 33 deletions .github/workflows/jdtls-milestone-checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,8 @@ jobs:
- name: Get latest milestone from Eclipse
id: get_latest
run: |
# Fetch the latest milestone release page
LATEST_PAGE=$(curl -s https://download.eclipse.org/jdtls/milestones | grep -oP 'href="\K[0-9]+(?=/")' | sort -n | tail -1)
if [ -z "$LATEST_PAGE" ]; then
echo "Error: Unable to fetch latest milestone page."
exit 1
fi
# Check for existing release
echo "latest_version=$LATEST_PAGE" >> $GITHUB_ENV
echo "Latest milestone page: $LATEST_PAGE"
pip install requests
echo "latest_version=$(python ./get_latest.py)" >> $GITHUB_ENV
- name: Check if release already exists
id: check_release
Expand All @@ -41,26 +33,3 @@ jobs:
else
echo "Release does not exist."
echo "release_exists=false" >> $GITHUB_ENV
- name: Download milestone files
if: env.release_exists == 'false'
run: |
mkdir -p jdtls
curl -LO "https://download.eclipse.org/jdtls/milestones/${{ env.latest_version }}/jdt-language-server-${{ env.latest_version }}.tar.gz"
mv jdt-language-server-${{ env.latest_version }}.tar.gz jdtls/
- name: Create GitHub release
if: env.release_exists == 'false'
uses: actions/create-release@v1
with:
tag_name: ${{ env.latest_version }}
release_name: "JDTLS Milestone ${{ env.latest_version }}"
body: |
JDTLS Milestone Release: ${{ env.latest_version }}
Downloaded from [Eclipse JDTLS Milestones](https://download.eclipse.org/jdtls/milestones/).
draft: false
prerelease: true
files: |
jdtls/jdt-language-server-${{ env.latest_version }}.tar.gz
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.direnv
61 changes: 61 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 26 additions & 9 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
{
description = "A flake for a Python development environment with requests package";
description = "A devShell example";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};

outputs =
{ self, nixpkgs }:
{
devShells.default = nixpkgs.lib.mkShell {
packages = with nixpkgs; [
python310
(python310Packages.requests) # Add the requests package
];
};
};
nixpkgs,
flake-utils,
...
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs { inherit system; };
in
with pkgs;
{
devShells.default = mkShell {
buildInputs = [
python310
(python310Packages.requests)
];

shellHook = ''
alias ls=eza
alias find=fd
'';
};
}
);
}
17 changes: 17 additions & 0 deletions get_latest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import re
import requests

base_url = 'https://download.eclipse.org/jdtls/milestones/'

def get_latest_version():
milestones_res = requests.get(base_url, allow_redirects=True)
if(milestones_res.status_code != 200):
raise Exception('Failed to get all versions from milestones page')
version_match_regex = r"<a href='(.*?)'> (\d*.\d*.\d*.)</a>"
matches = re.findall(version_match_regex, milestones_res.text)
versions = [match[1] for match in matches]

sorted_versions = sorted(versions, key=lambda x: list(map(int, x.split('.'))))
return sorted_versions[-1]
version = get_latest_version()
print(version)
68 changes: 68 additions & 0 deletions repackage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import re
import requests
from urllib.parse import urljoin
import urllib.request
import tarfile
import os
import tempfile
from shutil import move, copyfile

base_url = 'https://download.eclipse.org/jdtls/milestones/'

def get_latest_version():
milestones_res = requests.get(base_url, allow_redirects=True)
if(milestones_res.status_code != 200):
raise Exception('Failed to get all versions from milestones page')
version_match_regex = r"<a href='(.*?)'> (\d*.\d*.\d*.)</a>"
matches = re.findall(version_match_regex, milestones_res.text)
versions = [match[1] for match in matches]

sorted_versions = sorted(versions, key=lambda x: list(map(int, x.split('.'))))
return sorted_versions[-1]

def get_jdtls_download_url(version):
url = urljoin(base_url, f'{version}/latest.txt')
pkg_name_res = requests.get(url)
file_name = pkg_name_res.text.strip()
return urljoin(base_url, f'{version}/{file_name}')

def get_equinox_launcher_name(version):
plugins_res = requests.get(f"https://download.eclipse.org/jdtls/milestones/{version}/repository/plugins/")
pattern = r"<a .*?>(org.eclipse.equinox.launcher_.*?.jar)</a>"
matches = re.findall(pattern, plugins_res.text)

if len(matches) < 1:
raise Exception('Could not find the equinox launcher plugin')

if len(matches) > 1:
raise Exception('Found more than one equinox launcher plugin')

return matches[0]

def download_file(url):
with tempfile.TemporaryDirectory() as tmp:
res = requests.get(url)
file_path = urljoin(tmp, 'jdtls.tar.gz')
with open(file_path, 'wb') as file:
file.write(res.content)
return file_path

def extract_tar_gz(tar_gz_path, equinox_plugin_path):
with tarfile.open(tar_gz_path, "r:gz") as tar:
with tempfile.TemporaryDirectory() as tmp:
ex_dir = f'{tmp}/jdtls'
tar.extractall(path=ex_dir)
move(f'{ex_dir}/plugins/{equinox_plugin_path}', f'{ex_dir}/plugins/org.eclipse.equinox.launcher.jar')
with tempfile.TemporaryDirectory() as tmpout:
out_path = f'{tmpout}/jdtls.tar.gz'
with tarfile.open(out_path, "w:gz") as tarout:
for file in os.listdir(ex_dir):
tarout.add(f'{ex_dir}/{file}',arcname=file, recursive=True)
copyfile(f'{tmpout}/jdtls.tar.gz', '/home/s1n7ax/Downloads/Test/jdtls.tar.gz')


version = get_latest_version()
download_url = get_jdtls_download_url(version)
equinox_plugin_path = get_equinox_launcher_name(version)
downloaded_path = download_file(download_url)
extract_tar_gz(downloaded_path, equinox_plugin_path)
1 change: 0 additions & 1 deletion run.py

This file was deleted.

0 comments on commit 8673368

Please sign in to comment.