forked from Greenstand/treetracker-query-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
91 additions
and
16 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
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,39 @@ | ||
const fs = require('fs'); | ||
|
||
// 读取.releaserc文件内容 | ||
fs.readFile('.releaserc', 'utf8', (err, data) => { | ||
if (err) { | ||
console.error('Error reading file:', err); | ||
return; | ||
} | ||
|
||
try { | ||
const config = JSON.parse(data); | ||
const branches = config.branches; | ||
|
||
// 函数用于查找匹配的通道 | ||
function findChannel(branchName) { | ||
for (const branch of branches) { | ||
const regex = new RegExp('^' + branch.name.replace('*', '.*') + '$'); | ||
if (regex.test(branchName)) { | ||
return branch.channel; | ||
} | ||
} | ||
return null; // 如果没有匹配项,则返回null | ||
} | ||
|
||
// 测试分支名 | ||
const branchName = 'beta/123'; | ||
const channel = findChannel(branchName); | ||
if (channel) { | ||
console.log(`Branch '${branchName}' matches channel '${channel}'.`); | ||
} else { | ||
console.log(`No matching channel found for branch '${branchName}'.`); | ||
} | ||
|
||
// 可以根据需要对其他分支进行测试 | ||
|
||
} catch (error) { | ||
console.error('Error parsing JSON:', error); | ||
} | ||
}); |
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 |
---|---|---|
@@ -1,7 +1,30 @@ | ||
branch_name=$(git rev-parse --abbrev-ref HEAD) | ||
|
||
content=$(cat .releaserc) | ||
#!/bin/bash | ||
|
||
channel=$(echo "$content" | jq -r --arg branch "$branch_name" '.branches[] | select(.name | test("^" + $branch + "$")) | .channel') | ||
# 读取.releaserc文件内容,并提取branches部分的JSON数据 | ||
releaserc_content=$(cat .releaserc) | ||
branches_json=$(echo "$releaserc_content" | jq -r '.branches') | ||
|
||
echo "::set-output name=channel::$channel" | ||
# 输入要检索的branch name | ||
read -p "请输入要检索的branch name: " branch_name | ||
|
||
# 遍历branches数组,检查是否匹配branch name | ||
matched=false | ||
while IFS= read -r branch_info; do | ||
name=$(echo "$branch_info" | jq -r '.name') | ||
channel=$(echo "$branch_info" | jq -r '.channel') | ||
|
||
echo $branch_info | ||
echo $name | ||
|
||
# 判断是否匹配 | ||
if [[ "$branch_name" == $name || "$branch_name" == $name* ]]; then | ||
echo "匹配成功,$branch_name 对应的channel 是: $channel" | ||
matched=true | ||
break | ||
fi | ||
done <<< "$branches_json" | ||
|
||
# 若没有找到匹配的branch name,则输出未找到匹配信息 | ||
if ! $matched; then | ||
echo "未找到与 $branch_name 匹配的channel" | ||
fi |