-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build(updater): setup autoupdater (#219)
* build(updater): setup autoupdater
- Loading branch information
1 parent
4046158
commit 52a2cbe
Showing
6 changed files
with
232 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
name: updater | ||
on: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: '0 12 * * 1' # every Monday at 07:00 Colombia Time | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Harden Runner | ||
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1 | ||
with: | ||
egress-policy: audit | ||
|
||
- name: Generate a token | ||
id: generate_token | ||
uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a # v2.1.0 | ||
with: | ||
app_id: ${{ secrets.APP_ID_ADMIN_GITHUB }} | ||
private_key: ${{ secrets.APP_PRIVATE_KEY_ADMIN_GITHUB }} | ||
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | ||
with: | ||
ref: trunk | ||
token: ${{ steps.generate_token.outputs.token }} | ||
- name: Set up JDK 17 | ||
uses: actions/setup-java@2dfa2011c5b2a0f1489bf9e433881c92c1631f88 # v4.3.0 | ||
with: | ||
distribution: 'temurin' | ||
java-version: 17 | ||
- name: Set up NodeJS Latest | ||
uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 #v4.0.4 | ||
with: | ||
node-version: 'latest' | ||
- name: Check for updates | ||
working-directory: ./ide_extension/intellij | ||
run: node ide_extension/intellij/updater/index.js | ||
- name: Check for changes | ||
id: git_changes | ||
run: | | ||
git diff --name-only | ||
if [[ $(git diff --name-only) ]]; then | ||
echo "Changes detected!" | ||
echo "HAS_CHANGES=true" >> $GITHUB_ENV | ||
else | ||
echo "No changes detected!" | ||
echo "HAS_CHANGES=false" >> $GITHUB_ENV | ||
fi | ||
- name: Create Pull Request | ||
if: env.HAS_CHANGES == 'true' | ||
uses: peter-evans/create-pull-request@5e914681df9dc83aa4e4905692ca88beb2f9e91f # v7.0.5 | ||
with: | ||
token: ${{ steps.generate_token.outputs.token }} | ||
committer: Dependencies Bot <[email protected]> | ||
commit-message: 'fix(deps): update dependencies' | ||
title: 'fix(deps): update dependencies' | ||
body: 'This PR updates dependencies to latest versions' | ||
branch: 'feature/autoupdate-deps' | ||
base: 'trunk' | ||
labels: 'dependencies' | ||
reviewers: 'juancgalvis,santitigaga' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
const { exec } = require('child_process'); | ||
const fs = require('fs'); | ||
|
||
// Regular expression to match Gradle dependencies | ||
const dependencyRegex = /(\w[\w.-]*:\w[\w.-]*):(\d+\.\d+\.\d+)/; | ||
// Regular expression to match Gradle plugins | ||
const pluginRegex = /id\("(.+?)"\) version "(\d+(\.\d+)+)"/; | ||
|
||
async function fetchDependencyLatestVersion(dependency) { | ||
const [groupId, artifactId] = dependency.split(':'); | ||
const url = `https://search.maven.org/solrsearch/select?q=g:${groupId}+AND+a:${artifactId}&rows=10&wt=json&core=gav`; | ||
console.log(`Fetching version for ${dependency} from ${url}`); | ||
|
||
try { | ||
const response = await fetch(url); | ||
if (response.ok) { | ||
const body = await response.json(); | ||
const stableVersions = body.response.docs | ||
.map(doc => doc.v) | ||
.filter(version => !/-(alpha|beta|rc|m|snapshot|cr|dev)/i.test(version)); | ||
return stableVersions.length > 0 ? stableVersions[0] : null; | ||
} | ||
} catch (error) { | ||
console.error(`Error fetching version for ${dependency}: ${error.message}`); | ||
} | ||
return null; | ||
} | ||
|
||
async function fetchLatestPluginVersion(pluginId) { | ||
const pluginIdPath = pluginId.replace(/\./g, '/'); | ||
const url = `https://plugins.gradle.org/m2/${pluginIdPath}/${pluginId}.gradle.plugin/maven-metadata.xml`; | ||
|
||
console.log(`Fetching plugin version for ${pluginId} from ${url}`); | ||
|
||
try { | ||
const response = await fetch(url); | ||
if (response.ok) { | ||
const body = await response.text(); | ||
const match = body.match(/<version>(.+?)<\/version>/); | ||
if (match) { | ||
console.log(`Fetched plugin version for ${pluginId}:${match[1]}`); | ||
return match[1]; | ||
} | ||
} | ||
} catch (error) { | ||
console.error(`Error fetching plugin version for ${pluginId}: ${error.message}`); | ||
} | ||
return null; | ||
} | ||
|
||
async function updateDependencyLine(line) { | ||
let updatedLine = line; | ||
|
||
const match = line.match(dependencyRegex); | ||
if (match) { | ||
const dependency = match[1]; | ||
const currentVersion = match[2]; | ||
console.log(`Found dependency: ${dependency}:${currentVersion}`); | ||
|
||
const latestVersion = await fetchDependencyLatestVersion(dependency); | ||
if (latestVersion) { | ||
console.log(`Updating ${dependency} from ${currentVersion} to ${latestVersion}`); | ||
updatedLine = line.replace(currentVersion, latestVersion); | ||
} | ||
} else { | ||
const pluginMatch = line.match(pluginRegex); | ||
if (pluginMatch) { | ||
const pluginId = pluginMatch[1]; | ||
const currentVersion = pluginMatch[2]; | ||
console.log(`Found plugin: ${pluginId}:${currentVersion}`); | ||
|
||
const latestPluginVersion = await fetchLatestPluginVersion(pluginId); | ||
if (latestPluginVersion) { | ||
console.log(`Updating ${pluginId} from ${currentVersion} to ${latestPluginVersion}`); | ||
updatedLine = line.replace(currentVersion, latestPluginVersion); | ||
} | ||
} | ||
} | ||
return updatedLine; | ||
} | ||
|
||
async function updateFileByLines(filePath, processLine) { | ||
const fileContent = fs.readFileSync(filePath, 'utf8'); | ||
const lines = fileContent.split('\n'); | ||
const updatedLines = []; | ||
|
||
for (const line of lines) { | ||
updatedLines.push(await processLine(line)); | ||
} | ||
|
||
fs.writeFileSync(filePath, updatedLines.join('\n'), 'utf8'); | ||
console.log(`File ${filePath} updated successfully!`); | ||
} | ||
|
||
function wildCardBuild(build) { | ||
return build.split(".")[0] + ".*"; | ||
} | ||
|
||
function extractICVersion(data) { | ||
const latestRelease = data.filter((item) => item.code === "IIU")[0].releases.filter((release) => release.type === "release")[0]; | ||
return { version: latestRelease.version, build: wildCardBuild(latestRelease.build) }; | ||
} | ||
|
||
async function getIntellijCommunityVersion() { | ||
const response = await fetch("https://data.services.jetbrains.com/products?code=IIU%2CIIC&release.type=release"); | ||
if (response.ok) { | ||
const data = await response.json(); | ||
return extractICVersion(data); | ||
} | ||
throw new Error("Failed to fetch IntelliJ Community version", response.status); | ||
} | ||
|
||
async function getGradleVersion() { | ||
const response = await fetch("https://services.gradle.org/versions/current"); | ||
if (response.ok) { | ||
const data = await response.json(); | ||
return data.version; | ||
} | ||
throw new Error("Failed to fetch latest gradle version", response.status); | ||
} | ||
|
||
function updateGradleProperties({ intellijVersion, gradleVersion }) { | ||
return async function (line) { | ||
let updatedLine = line; | ||
if (line.startsWith("platformVersion")) { | ||
updatedLine = `platformVersion=${intellijVersion.version}`; | ||
} else if (line.startsWith("pluginUntilBuild")) { | ||
updatedLine = `pluginUntilBuild=${intellijVersion.build}`; | ||
} else if (line.startsWith("gradleVersion")) { | ||
updatedLine = `gradleVersion=${gradleVersion}`; | ||
} | ||
return updatedLine; | ||
} | ||
} | ||
|
||
function gradleWrapper() { | ||
exec('./gradlew wrapper', (error, stdout, stderr) => { | ||
if (error) { | ||
console.error(`Error executing command: ${error.message}`); | ||
return; | ||
} | ||
if (stderr) { | ||
console.error(`stderr: ${stderr}`); | ||
return; | ||
} | ||
console.log(stdout); | ||
}); | ||
} | ||
|
||
async function update() { | ||
updateFileByLines('build.gradle.kts', updateDependencyLine) | ||
.catch(console.error); | ||
const intellijVersion = await getIntellijCommunityVersion(); | ||
console.log(`IntelliJ Community version: ${intellijVersion.version} (${intellijVersion.build})`); | ||
const gradleVersion = await getGradleVersion(); | ||
console.log(`Gradle version: ${gradleVersion}`); | ||
updateFileByLines('gradle.properties', updateGradleProperties({ intellijVersion, gradleVersion })) | ||
.catch(console.error); | ||
console.log("Updating gradle wrapper"); | ||
gradleWrapper(); | ||
} | ||
|
||
update(); |