test: debug #50
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
name: Deploy TDengine Cluster | |
on: | |
push: | |
branches: | |
- test/fractal | |
# on: | |
# workflow_dispatch: | |
# inputs: | |
# version: | |
# description: 'Enter the version of TDengine to install' | |
# required: true | |
# default: '3.3.5.1' | |
# group: | |
# description: 'Enter the group for the runner' | |
# required: true | |
# default: 'default' | |
# dnode_count: | |
# description: 'Number of nodes to deploy' | |
# required: true | |
# default: '2' | |
permissions: | |
actions: read | |
contents: read | |
jobs: | |
filter-runners: | |
runs-on: ubuntu-latest | |
outputs: | |
runners: ${{ steps.get-runners.outputs.matrix}} | |
runner_names: ${{ steps.get-runners.outputs.names}} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Generate GitHub App Token | |
id: app-token | |
uses: tibdex/github-app-token@v1 | |
with: | |
app_id: ${{ secrets.TAOSDATA_BOT_ID }} | |
private_key: ${{ secrets.TAOSDATA_BOT_KEY }} | |
# - name: Get Available Runners | |
# env: | |
# GITHUB_TOKEN: ${{ secrets.RUNNER_PAT }} | |
- name: Get Available Runners | |
env: | |
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }} | |
id: get-runners | |
run: | | |
set -euo pipefail | |
echo "Fetching available runners..." | |
response_file=$(mktemp) | |
gh api /orgs/${{ github.repository_owner }}/actions/runners \ | |
--paginate \ | |
--jq '.runners' > "$response_file" | |
# 设置 dnode_count 的值 | |
dnode_count=2 | |
# 过滤并格式化 runners | |
filtered_runners=$(jq -c --argjson count "$dnode_count" ' | |
map( | |
select( | |
.labels | | |
(map(.name) | index("fractal")) != null and | |
(map(.name) | index("edge_td")) != null | |
) | |
| { | |
name, | |
group: ( | |
if .labels | map(.name) | index("fractal") != null then "fractal" | |
else "default" | |
end | |
), | |
labels: ( | |
.labels | map(.name) | join(", ") | | |
split(", ") | | |
map(select(. != "")) | | |
["self-hosted", "Linux", "X64"] + . | |
) | |
} | |
)[:$count]' "$response_file") | |
echo "✅ Selected runners with formatted labels:" | |
echo "$filtered_runners" | |
# 确保 filtered_runners 是有效的 JSON 数组 | |
if [ -z "$filtered_runners" ]; then | |
echo "No runners found. Setting empty matrix." | |
echo "matrix=[]" >> $GITHUB_OUTPUT | |
echo "names=[]" >> $GITHUB_OUTPUT | |
else | |
echo "matrix=$filtered_runners" >> $GITHUB_OUTPUT | |
names=$(echo "$filtered_runners" | jq -r '.[].name' | tr '\n' ',') | |
names=${names%,} | |
echo "names=${names}" >> $GITHUB_OUTPUT | |
fi | |
update-hosts: | |
needs: filter-runners | |
strategy: | |
matrix: | |
runner: ${{ fromJson(needs.filter-runners.outputs.runners || '[]') }} | |
runs-on: | |
group: ${{ matrix.runner.group }} | |
labels: ${{ matrix.runner.labels }} | |
steps: | |
- name: Print Runner Info | |
run: | | |
echo "🔄 Running on group: ${{ matrix.runner.group }}" | |
echo "🔄 Name: ${{ matrix.runner.name }}" | |
- name: Get IP and Hostname | |
id: get-ip-hostname | |
run: | | |
echo "🔄 Getting IP and hostname for the runner..." | |
# 获取 IP 和主机名 | |
ip=$(hostname -I | awk '{print $1}') # 获取 IP 地址 | |
hostname=$(hostname) # 获取主机名 | |
echo "IP: $ip" | |
echo "Hostname: $hostname" | |
# 将 IP 和主机名保存为输出 | |
echo "$ip $hostname" > ip_hostname_${{ matrix.runner.name }}.txt | |
- name: Upload IP and Hostname Info | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ip_hostname_${{ matrix.runner.name }} | |
path: ip_hostname_${{ matrix.runner.name }}.txt | |
combine-and-update-hosts: | |
needs: | |
- update-hosts | |
- filter-runners | |
strategy: | |
matrix: | |
runner: ${{ fromJson(needs.filter-runners.outputs.runners || '[]') }} | |
runs-on: | |
group: ${{ matrix.runner.group }} | |
labels: ${{ matrix.runner.labels }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Generate GitHub App Token | |
id: app-token | |
uses: tibdex/github-app-token@v1 | |
with: | |
app_id: ${{ secrets.TAOSDATA_BOT_ID }} | |
private_key: ${{ secrets.TAOSDATA_BOT_KEY }} | |
- name: Authenticate GitHub CLI | |
run: | | |
echo "🔄 Authenticating GitHub CLI..." | |
echo "${{ steps.app-token.outputs.token }}" | gh auth login --with-token | |
- name: Download IP and Hostname Info | |
run: | | |
echo "🔄 Downloading IP and hostname info for each runner..." | |
runner_name=${{ needs.filter-runners.outputs.runner_names }} | |
echo "Runner Name: $runner_name" | |
IFS=',' read -r -a names_array <<< "$runner_name" | |
echo "Extracted names: $names_array" | |
for name in "${names_array[@]}"; do | |
echo "Downloading artifact for runner: $name" | |
gh run download $GITHUB_RUN_ID --name "ip_hostname_$name" --dir ip_hostname | |
done | |
# # 解析 runners JSON 数据 | |
# echo "$runners" | jq -c '.[]' | while read -r runner; do | |
# runner_name=$(echo "$runner" | jq -r '.name') | |
# echo "Downloading artifact for runner: $runner_name" | |
# # 下载 Artifact | |
# gh run download $GITHUB_RUN_ID --name "ip_hostname_$runner_name" --dir ip_hostname | |
# done | |
- name: Combine IP and Hostname Info | |
run: | | |
echo "🔄 Combining IP and hostname info..." | |
# 读取所有 runner 的 IP 和主机名信息 | |
ip_hostname_info=$(cat ip_hostname/*.txt | sort | uniq) # 去重 | |
# 将所有信息保存为环境变量,供后续步骤使用 | |
echo "ip_hostname_info<<EOF" >> $GITHUB_ENV | |
echo -e "$ip_hostname_info" >> $GITHUB_ENV | |
echo "EOF" >> $GITHUB_ENV | |
- name: Update /etc/hosts | |
run: | | |
echo "🔄 Updating /etc/hosts..." | |
# 遍历 ip_hostname_info 的每一行 | |
while IFS= read -r line; do | |
# 检查 /etc/hosts 中是否已经存在该行 | |
if ! grep -Fxq "$line" /etc/hosts; then | |
# 如果不存在,则追加到 /etc/hosts | |
echo "$line" | sudo tee -a /etc/hosts | |
else | |
echo "✅ Skipping (already exists): $line" | |
fi | |
done <<< "$ip_hostname_info" | |
echo "✅ Updated /etc/hosts with runner IPs and hostnames:" | |
cat /etc/hosts | |
# - name: Combine IP and Hostname Info | |
# run: | | |
# echo "🔄 Combining IP and hostname info..." | |
# # 获取所有 runner 的 IP 和主机名信息 | |
# ip_hostname_info="" | |
# for job_id in $(echo '${{ toJson(needs.update-hosts) }}' | jq -r '.result | keys[]'); do | |
# job_outputs=$(echo '${{ toJson(needs.update-hosts.outputs) }}' | jq -r --arg job_id "$job_id" '.[$job_id]') | |
# ip_hostname=$(echo "$job_outputs" | jq -r '.ip_hostname') | |
# ip_hostname_info+="$ip_hostname\n" | |
# done | |
# # ip_hostname_info=$(echo '${{ steps.get-ip-hostname.outputs.ip_hostname }}' | jq -r '.') | |
# # 将所有信息保存为环境变量,供后续步骤使用 | |
# echo "ip_hostname_info<<EOF" >> $GITHUB_ENV | |
# echo "$ip_hostname_info" >> $GITHUB_ENV | |
# echo "EOF" >> $GITHUB_ENV | |
# - name: Update /etc/hosts | |
# run: | | |
# echo "🔄 Updating /etc/hosts..." | |
# # 将所有 IP 和主机名信息写入 /etc/hosts | |
# echo "$ip_hostname_info" | sudo tee -a /etc/hosts | |
# echo "✅ Updated /etc/hosts with runner IPs and hostnames:" | |
# cat /etc/hosts | |
# response_file=$(mktemp) | |
# if ! gh api "/orgs/${{ github.repository_owner }}/actions/runners" \ | |
# --method GET \ | |
# --paginate \ | |
# --jq '.runners' > "$response_file"; | |
# then | |
# echo "❌ Failed to fetch runners" | |
# exit 1 | |
# fi | |
# # 验证响应内容 | |
# if [ ! -s "$response_file" ]; then | |
# echo "⚠️ Empty API response" | |
# exit 1 | |
# fi | |
# # 处理JSON数据 | |
# filtered_runners=$(jq -c ' | |
# map( | |
# select( | |
# .labels | | |
# (map(.name) | | |
# contains(["fractal"]) and | |
# contains(["edge_td"]) | |
# ) | |
# ) | |
# | {name, labels} | |
# )' "$response_file") | |
# # 验证JSON有效性 | |
# if ! jq -e . >/dev/null 2>&1 <<< "$filtered_runners"; then | |
# echo "❌ Invalid JSON output" | |
# exit 1 | |
# fi | |
# echo "✅ Filtered runners:" | |
# jq . <<< "$filtered_runners" | |
# # 使用JSON格式输出 | |
# echo "runners=$filtered_runners" >> $GITHUB_OUTPUT | |
# call-install: | |
# runs-on: | |
# group: ${{ github.event.inputs.group }} | |
# labels: ${{ fromJson(github.event.inputs.labels) }} | |
# steps: | |
# - name: Check and Install TDengine Enterprise | |
# uses: taosdata/.github/.github/actions/install-tdengine@test/fractal | |
# with: | |
# version: ${{ github.event.inputs.version }} | |
# group: ${{ github.event.inputs.group }} | |
# labels: ${{ github.event.inputs.labels }} | |
# NAS_DOWNLOAD_URL: ${{ secrets.NAS_DOWNLOAD_URL }} |