diff --git a/npm-install/action.yml b/npm-install/action.yml index 4ceeef3..6d43a69 100644 --- a/npm-install/action.yml +++ b/npm-install/action.yml @@ -52,8 +52,8 @@ outputs: runs: using: 'composite' steps: - - name: 确定锁文件 - id: lockfile + - name: 检测锁文件 + id: detect-lockfile shell: bash run: | LOCKFILE="${{ inputs.lockfile-name }}" @@ -79,19 +79,23 @@ runs: - name: 生成缓存key id: cache-key shell: bash + env: + LOCKFILE_HASH: ${{ hashFiles(steps.detect-lockfile.outputs.lockfile) }} run: | - # 根据检测到的锁文件生成hash - LOCKFILE="${{ steps.lockfile.outputs.lockfile }}" - if [[ -f "${LOCKFILE}" ]]; then - # 使用sha256计算文件hash并取前12位 - HASH=$(sha256sum "${LOCKFILE}" | cut -d' ' -f1 | head -c 12) + LOCKFILE="${{ steps.detect-lockfile.outputs.lockfile }}" + + # 截取hash的前12位 + if [[ -n "${LOCKFILE_HASH}" && "${LOCKFILE_HASH}" != "" ]]; then + LOCKFILE_HASH_SHORT=$(echo "${LOCKFILE_HASH}" | head -c 12) else - echo "⚠️ 警告: 锁文件 ${LOCKFILE} 不存在,使用时间戳作为fallback" - HASH=$(date +%s | tail -c 8) + echo "⚠️ 警告: 无法计算锁文件hash,使用默认值" + LOCKFILE_HASH_SHORT="no-lockfile" fi - CACHE_KEY="${{ runner.os }}-${{ inputs.cache-prefix }}-${HASH}" + CACHE_KEY="${{ runner.os }}-${{ inputs.cache-prefix }}-${LOCKFILE_HASH_SHORT}" echo "key=${CACHE_KEY}" >> $GITHUB_OUTPUT + echo "锁文件: ${LOCKFILE}" + echo "文件hash: ${LOCKFILE_HASH}" echo "缓存key: ${CACHE_KEY}" - name: 拉取缓存依赖 diff --git a/trigger-version/README.md b/trigger-version/README.md index 7247fc4..2f5ab47 100644 --- a/trigger-version/README.md +++ b/trigger-version/README.md @@ -57,7 +57,7 @@ jobs: steps: - name: 获取版本信息 id: version-info - uses: ./trigger-version + uses: actions/xgj/trigger-version@v1 - name: 显示版本信息 run: | @@ -80,7 +80,7 @@ jobs: ```yaml - name: 获取版本信息(自定义前缀) id: version-info - uses: ./trigger-version + uses: actions/xgj/trigger-version@v1 with: version-prefix: "release-" ``` @@ -104,7 +104,7 @@ jobs: steps: - name: 获取版本信息 id: version-info - uses: ./trigger-version + uses: actions/xgj/trigger-version@v1 - name: 检查是否需要部署 id: check-deploy diff --git a/trigger-version/examples/basic-usage.yml b/trigger-version/examples/basic-usage.yml index fc8d477..ae2dc01 100644 --- a/trigger-version/examples/basic-usage.yml +++ b/trigger-version/examples/basic-usage.yml @@ -25,7 +25,7 @@ jobs: - name: 获取触发版本信息 id: version-info - uses: ./trigger-version + uses: actions/xgj/trigger-version@v1 - name: 显示版本信息 run: | diff --git a/trigger-version/examples/conditional-deployment.yml b/trigger-version/examples/conditional-deployment.yml index f4f8c8b..3a4c2df 100644 --- a/trigger-version/examples/conditional-deployment.yml +++ b/trigger-version/examples/conditional-deployment.yml @@ -25,7 +25,7 @@ jobs: - name: 获取版本信息 id: version-info - uses: ./trigger-version + uses: actions/xgj/trigger-version@v1 - name: 确定部署策略 id: deployment-strategy diff --git a/trigger-version/examples/custom-prefix.yml b/trigger-version/examples/custom-prefix.yml index 9199a2a..ba330cd 100644 --- a/trigger-version/examples/custom-prefix.yml +++ b/trigger-version/examples/custom-prefix.yml @@ -19,7 +19,7 @@ jobs: - name: 获取标准版本信息 id: standard-version - uses: ./trigger-version + uses: actions/xgj/trigger-version@v1 # 使用默认的 'v' 前缀 - name: 显示标准版本信息 @@ -38,7 +38,7 @@ jobs: - name: 获取发布版本信息 id: release-version - uses: ./trigger-version + uses: actions/xgj/trigger-version@v1 with: version-prefix: 'release-' @@ -60,7 +60,7 @@ jobs: - name: 获取热修复版本信息 id: hotfix-version - uses: ./trigger-version + uses: actions/xgj/trigger-version@v1 with: version-prefix: 'hotfix-' @@ -80,7 +80,7 @@ jobs: - name: 获取无前缀版本信息 id: no-prefix-version - uses: ./trigger-version + uses: actions/xgj/trigger-version@v1 with: version-prefix: '' @@ -123,7 +123,7 @@ jobs: - name: 使用动态前缀获取版本信息 id: dynamic-version - uses: ./trigger-version + uses: actions/xgj/trigger-version@v1 with: version-prefix: ${{ env.VERSION_PREFIX }} diff --git a/trigger-version/examples/full-cicd.yml b/trigger-version/examples/full-cicd.yml index 9675e24..3138719 100644 --- a/trigger-version/examples/full-cicd.yml +++ b/trigger-version/examples/full-cicd.yml @@ -36,7 +36,7 @@ jobs: - name: 获取触发版本信息 id: version-info - uses: ./trigger-version + uses: actions/xgj/trigger-version@v1 - name: 确定构建和部署策略 id: build-strategy