From d33c9f326f55b23267f5a0ac5d7001347118f18e Mon Sep 17 00:00:00 2001 From: unknowIfGuestInDream Date: Sat, 3 May 2025 08:23:24 +0800 Subject: [PATCH 1/5] =?UTF-8?q?ci:=20=E6=96=B0=E5=A2=9E=E5=AF=B9dependabot?= =?UTF-8?q?=E7=9A=84=E9=98=BF=E9=87=8C=E4=BA=91=E4=BE=9D=E8=B5=96=E6=A3=80?= =?UTF-8?q?=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Close #2125 Signed-off-by: unknowIfGuestInDream --- .github/workflows/check-aliyun-maven.yml | 96 ++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 .github/workflows/check-aliyun-maven.yml diff --git a/.github/workflows/check-aliyun-maven.yml b/.github/workflows/check-aliyun-maven.yml new file mode 100644 index 000000000..9261f2e5a --- /dev/null +++ b/.github/workflows/check-aliyun-maven.yml @@ -0,0 +1,96 @@ +name: Check Aliyun Maven Dependencies + +on: + pull_request_target: + types: [ opened, synchronize ] + workflow_dispatch: + +jobs: + check-dependencies: + # 只在dependabot的PR上运行 + if: github.actor == 'dependabot[bot]' + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.ref }} + + - name: Set up Java + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '17' + + - name: Check Aliyun Maven availability + id: check-aliyun + uses: actions/github-script@v7 + with: + script: | + const { execSync } = require('child_process'); + const core = require('@actions/core'); + const github = require('@actions/github'); + + try { + // 获取变更的依赖 + const diffOutput = execSync('git diff origin/${{ github.event.pull_request.base.ref }} -- build.gradle || git diff origin/${{ github.event.pull_request.base.ref }} -- pom.xml').toString(); + + // 解析依赖变更 + const dependencies = []; + const regex = /([+-])\s*(implementation|api|compile|testImplementation|runtimeOnly)\s*['"]([^'"]+)['"]/g; + let match; + + while ((match = regex.exec(diffOutput)) !== null) { + if (match[1] === '+') { // 只关心新增的依赖 + const depParts = match[3].split(':'); + if (depParts.length === 3) { + dependencies.push({ + group: depParts[0], + artifact: depParts[1], + version: depParts[2] + }); + } + } + } + + if (dependencies.length === 0) { + core.setOutput('result', 'No dependency changes found'); + return 'No dependency changes to check'; + } + + // 检查阿里云Maven是否有这些依赖 + const results = []; + const aliMavenUrl = 'https://maven.aliyun.com/repository/public'; + + for (const dep of dependencies) { + const artifactPath = dep.group.replace(/\./g, '/') + '/' + dep.artifact + '/' + dep.version; + const pomUrl = `${aliMavenUrl}/${artifactPath}/${dep.artifact}-${dep.version}.pom`; + + try { + execSync(`curl -I -s -o /dev/null -w "%{http_code}" ${pomUrl} | grep 200`); + results.push(`✅ ${dep.group}:${dep.artifact}:${dep.version} - 可用`); + } catch (e) { + results.push(`❌ ${dep.group}:${dep.artifact}:${dep.version} - 不可用`); + } + } + + const commentBody = `### 阿里云 Maven 依赖检查结果\n\n${results.join('\n')}`; + core.setOutput('result', commentBody); + + // 添加PR评论 + const octokit = github.getOctokit(process.env.GITHUB_TOKEN); + await octokit.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + body: commentBody + }); + + return commentBody; + } catch (error) { + core.setFailed(`Action failed with error: ${error}`); + } + + - name: Output result + run: echo "${{ steps.check-aliyun.outputs.result }}" From 6fa79f0f143b98636566c271b61649d3a3f7b1dd Mon Sep 17 00:00:00 2001 From: unknowIfGuestInDream Date: Sat, 3 May 2025 08:35:12 +0800 Subject: [PATCH 2/5] =?UTF-8?q?ci:=20=E6=96=B0=E5=A2=9E=E5=AF=B9dependabot?= =?UTF-8?q?=E7=9A=84=E9=98=BF=E9=87=8C=E4=BA=91=E4=BE=9D=E8=B5=96=E6=A3=80?= =?UTF-8?q?=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Close #2125 Signed-off-by: unknowIfGuestInDream --- .github/workflows/check-aliyun-maven.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/check-aliyun-maven.yml b/.github/workflows/check-aliyun-maven.yml index 9261f2e5a..fe174aca6 100644 --- a/.github/workflows/check-aliyun-maven.yml +++ b/.github/workflows/check-aliyun-maven.yml @@ -4,6 +4,12 @@ on: pull_request_target: types: [ opened, synchronize ] workflow_dispatch: + schedule: + - cron: '0 0 * * *' # 每天UTC时间午夜(北京时间早上8点) + +permissions: + contents: read + pull-requests: write jobs: check-dependencies: From f5c1fcf1784ef212a447d9f33a693825baa61408 Mon Sep 17 00:00:00 2001 From: unknowIfGuestInDream Date: Sat, 3 May 2025 08:48:09 +0800 Subject: [PATCH 3/5] =?UTF-8?q?ci:=20=E6=96=B0=E5=A2=9E=E5=AF=B9dependabot?= =?UTF-8?q?=E7=9A=84=E9=98=BF=E9=87=8C=E4=BA=91=E4=BE=9D=E8=B5=96=E6=A3=80?= =?UTF-8?q?=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Close #2125 Signed-off-by: unknowIfGuestInDream --- .github/workflows/check-aliyun-maven.yml | 141 ++++++++++++++++------- 1 file changed, 102 insertions(+), 39 deletions(-) diff --git a/.github/workflows/check-aliyun-maven.yml b/.github/workflows/check-aliyun-maven.yml index fe174aca6..fe2bb0159 100644 --- a/.github/workflows/check-aliyun-maven.yml +++ b/.github/workflows/check-aliyun-maven.yml @@ -4,8 +4,6 @@ on: pull_request_target: types: [ opened, synchronize ] workflow_dispatch: - schedule: - - cron: '0 0 * * *' # 每天UTC时间午夜(北京时间早上8点) permissions: contents: read @@ -29,45 +27,107 @@ jobs: distribution: 'temurin' java-version: '17' - - name: Check Aliyun Maven availability - id: check-aliyun + - name: Get build file changes + id: get-changes + run: | + # 检测项目类型并获取变更内容 + if [ -f "pom.xml" ]; then + echo "build_type=maven" >> $GITHUB_OUTPUT + # PR事件获取当前PR的pom.xml变更 + git diff origin/${{ github.event.pull_request.base.ref }} -- pom.xml > changes.diff || true + elif [ -f "build.gradle" ]; then + echo "build_type=gradle" >> $GITHUB_OUTPUT + git diff origin/${{ github.event.pull_request.base.ref }} -- build.gradle > changes.diff || true + else + echo "No supported build file found" + exit 0 + fi + echo "changes<> $GITHUB_OUTPUT + cat changes.diff >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + + - name: Parse dependencies + id: parse-deps uses: actions/github-script@v7 with: script: | - const { execSync } = require('child_process'); const core = require('@actions/core'); - const github = require('@actions/github'); try { - // 获取变更的依赖 - const diffOutput = execSync('git diff origin/${{ github.event.pull_request.base.ref }} -- build.gradle || git diff origin/${{ github.event.pull_request.base.ref }} -- pom.xml').toString(); - - // 解析依赖变更 + const buildType = '${{ steps.detect-build.outputs.build_type }}'; + const changes = '${{ steps.detect-build.outputs.changes }}'; const dependencies = []; - const regex = /([+-])\s*(implementation|api|compile|testImplementation|runtimeOnly)\s*['"]([^'"]+)['"]/g; - let match; - - while ((match = regex.exec(diffOutput)) !== null) { - if (match[1] === '+') { // 只关心新增的依赖 - const depParts = match[3].split(':'); - if (depParts.length === 3) { - dependencies.push({ - group: depParts[0], - artifact: depParts[1], - version: depParts[2] - }); + + if (buildType === 'gradle') { + // Gradle 依赖解析 + const regex = /([+-])\s*(implementation|api|compile|testImplementation|runtimeOnly)\s*['"]([^'"]+)['"]/g; + let match; + + while ((match = regex.exec(changes)) !== null) { + if (match[1] === '+') { + const depParts = match[3].split(':'); + if (depParts.length === 3) { + dependencies.push({ + group: depParts[0], + artifact: depParts[1], + version: depParts[2] + }); + } + } + } + } else if (buildType === 'maven') { + // Maven 依赖解析 + const diffLines = changes.split('\n'); + let currentDep = null; + let inDependency = false; + let isNewDep = false; + + for (const line of diffLines) { + if (line.startsWith('+ ')) { + inDependency = true; + isNewDep = true; + currentDep = {}; + } else if (line.startsWith('+ ') && isNewDep) { + inDependency = false; + if (currentDep.groupId && currentDep.artifactId && currentDep.version) { + dependencies.push({ + group: currentDep.groupId, + artifact: currentDep.artifactId, + version: currentDep.version + }); + } + } else if (inDependency && isNewDep) { + if (line.startsWith('+ ')) { + currentDep.groupId = line.replace(/^\+ |<\/groupId>$/g, '').trim(); + } else if (line.startsWith('+ ')) { + currentDep.artifactId = line.replace(/^\+ |<\/artifactId>$/g, '').trim(); + } else if (line.startsWith('+ ')) { + currentDep.version = line.replace(/^\+ |<\/version>$/g, '').trim(); + } } } } - if (dependencies.length === 0) { - core.setOutput('result', 'No dependency changes found'); - return 'No dependency changes to check'; - } + core.setOutput('dependencies', JSON.stringify(dependencies)); + return dependencies.length; + } catch (error) { + core.setFailed(`Failed to parse dependencies: ${error}`); + } - // 检查阿里云Maven是否有这些依赖 - const results = []; + - name: Check Aliyun Maven availability + if: steps.parse-deps.outputs.dependencies != '[]' + id: check-aliyun + uses: actions/github-script@v6 + with: + script: | + const { execSync } = require('child_process'); + const core = require('@actions/core'); + const github = require('@actions/github'); + + try { + const dependencies = JSON.parse('${{ steps.parse-deps.outputs.dependencies }}'); const aliMavenUrl = 'https://maven.aliyun.com/repository/public'; + const results = []; for (const dep of dependencies) { const artifactPath = dep.group.replace(/\./g, '/') + '/' + dep.artifact + '/' + dep.version; @@ -81,22 +141,25 @@ jobs: } } - const commentBody = `### 阿里云 Maven 依赖检查结果\n\n${results.join('\n')}`; - core.setOutput('result', commentBody); + if (results.length > 0) { + const commentBody = `### 阿里云 Maven 依赖检查结果\n\n${results.join('\n')}`; + + const octokit = github.getOctokit(process.env.GITHUB_TOKEN); + await octokit.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: ${{ github.event.pull_request.number }}, + body: commentBody + }); - // 添加PR评论 - const octokit = github.getOctokit(process.env.GITHUB_TOKEN); - await octokit.rest.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: context.issue.number, - body: commentBody - }); + core.setOutput('result', commentBody); + } - return commentBody; + return 'Dependency check completed'; } catch (error) { core.setFailed(`Action failed with error: ${error}`); } - name: Output result + if: steps.parse-deps.outputs.dependencies != '[]' run: echo "${{ steps.check-aliyun.outputs.result }}" From 1db86fea2b39ce1c8e0fa784e73ad539eddbaec4 Mon Sep 17 00:00:00 2001 From: unknowIfGuestInDream Date: Sat, 3 May 2025 08:57:46 +0800 Subject: [PATCH 4/5] =?UTF-8?q?ci:=20=E6=96=B0=E5=A2=9E=E5=AF=B9dependabot?= =?UTF-8?q?=E7=9A=84=E9=98=BF=E9=87=8C=E4=BA=91=E4=BE=9D=E8=B5=96=E6=A3=80?= =?UTF-8?q?=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Close #2125 Signed-off-by: unknowIfGuestInDream --- .github/workflows/check-aliyun-maven.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/check-aliyun-maven.yml b/.github/workflows/check-aliyun-maven.yml index fe2bb0159..edbb0e858 100644 --- a/.github/workflows/check-aliyun-maven.yml +++ b/.github/workflows/check-aliyun-maven.yml @@ -54,8 +54,8 @@ jobs: const core = require('@actions/core'); try { - const buildType = '${{ steps.detect-build.outputs.build_type }}'; - const changes = '${{ steps.detect-build.outputs.changes }}'; + const buildType = '${{ steps.get-changes.outputs.build_type }}'; + const changes = '${{ steps.get-changes.outputs.changes }}'; const dependencies = []; if (buildType === 'gradle') { @@ -122,7 +122,7 @@ jobs: script: | const { execSync } = require('child_process'); const core = require('@actions/core'); - const github = require('@actions/github'); + const { context, getOctokit } = require('@actions/github'); try { const dependencies = JSON.parse('${{ steps.parse-deps.outputs.dependencies }}'); @@ -144,7 +144,7 @@ jobs: if (results.length > 0) { const commentBody = `### 阿里云 Maven 依赖检查结果\n\n${results.join('\n')}`; - const octokit = github.getOctokit(process.env.GITHUB_TOKEN); + const octokit = getOctokit(process.env.GITHUB_TOKEN); await octokit.rest.issues.createComment({ owner: context.repo.owner, repo: context.repo.repo, From c4f92b545953563400090c2ca66a3c9ea480051a Mon Sep 17 00:00:00 2001 From: unknowIfGuestInDream Date: Sat, 3 May 2025 09:12:40 +0800 Subject: [PATCH 5/5] =?UTF-8?q?ci:=20=E6=96=B0=E5=A2=9E=E5=AF=B9dependabot?= =?UTF-8?q?=E7=9A=84=E9=98=BF=E9=87=8C=E4=BA=91=E4=BE=9D=E8=B5=96=E6=A3=80?= =?UTF-8?q?=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Close #2125 Signed-off-by: unknowIfGuestInDream --- .github/workflows/check-aliyun-maven.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-aliyun-maven.yml b/.github/workflows/check-aliyun-maven.yml index edbb0e858..2a56b9af0 100644 --- a/.github/workflows/check-aliyun-maven.yml +++ b/.github/workflows/check-aliyun-maven.yml @@ -117,7 +117,7 @@ jobs: - name: Check Aliyun Maven availability if: steps.parse-deps.outputs.dependencies != '[]' id: check-aliyun - uses: actions/github-script@v6 + uses: actions/github-script@v7 with: script: | const { execSync } = require('child_process');