36 lines
1.0 KiB
YAML
36 lines
1.0 KiB
YAML
name: shell_hash
|
|
description: 获取文件哈希
|
|
|
|
inputs:
|
|
file_array:
|
|
required: true
|
|
description: 文件路径
|
|
|
|
outputs:
|
|
hash:
|
|
description: 文件哈希
|
|
value: ${{ steps.get_hash.outputs.res }}
|
|
|
|
runs:
|
|
using: composite
|
|
steps:
|
|
- name: 获取最新发布版本号
|
|
id: get_hash
|
|
shell: bash
|
|
run: |
|
|
# 初始化 res 变量
|
|
res=""
|
|
fileStr =${{inputs.file_array}}
|
|
# 读取 fileStr 变量中的每一行文件路径
|
|
echo -e "$fileStr" | while IFS= read -r filepath; do
|
|
# 获取文件的哈希值,这里使用 MD5 作为例子
|
|
file_hash=$(md5sum "$filepath" | awk '{print $1}')
|
|
# 将哈希值追加到 res 变量中,使用换行符分隔
|
|
res+="$file_hash"
|
|
done
|
|
|
|
# 计算 res 的哈希值
|
|
final_hash=$(echo -n "$res" | md5sum | awk '{print $1}')
|
|
|
|
echo "res=$final_hash" >> "$GITHUB_OUTPUT"
|
|
echo "final_hash=$final_hash" |