Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: PR Checks

on:
pull_request:
types: [opened, synchronize, reopened]
workflow_dispatch:

permissions:
contents: read
pull-requests: read

env:
NODE_VERSION: "22"

jobs:
################################################################################
# PR Quality Checks Job
################################################################################
pr-checks:
name: PR Quality Checks
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: "npm"
cache-dependency-path: package-lock.json

- name: Install dependencies
run: npm ci

- name: TypeScript type check
run: npm run build:tsc:check

- name: Production build
run: npm run build:prod

- name: Smoke test
run: npm run smoke-test

- name: Check status summary
if: always()
run: |
echo "::notice::All PR checks passed successfully!"

################################################################################
# Check Summary Job
################################################################################
check-summary:
name: Check Summary
needs: pr-checks
if: always()
runs-on: ubuntu-latest

steps:
- name: Check status
run: |
echo "PR Checks: ${{ needs.pr-checks.result }}"

- name: Checks failed notification
if: needs.pr-checks.result == 'failure'
run: |
echo "::error::PR checks failed. Please fix the issues before merging."

- name: Determine overall status
id: status
if: always()
run: |
check_status="${{ needs.pr-checks.result }}"

echo "PR Checks: ${check_status}"

if [ "${check_status}" == "failure" ]; then
echo "overall=failed" >> $GITHUB_OUTPUT
echo "status_icon=❌" >> $GITHUB_OUTPUT
echo "status_text=失败" >> $GITHUB_OUTPUT
else
echo "overall=success" >> $GITHUB_OUTPUT
echo "status_icon=✅" >> $GITHUB_OUTPUT
echo "status_text=通过" >> $GITHUB_OUTPUT
fi

- name: PR check summary
if: always()
run: |
echo "### PR Checks ${{ steps.status.outputs.status_icon }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**状态:** ${{ steps.status.outputs.status_text }}" >> $GITHUB_STEP_SUMMARY
echo "**分支:** ${{ github.head_ref }}" >> $GITHUB_STEP_SUMMARY
echo "**提交:** \`${{ github.sha }}\`" >> $GITHUB_STEP_SUMMARY
echo "**触发者:** ${{ github.actor }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "[查看详情](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})" >> $GITHUB_STEP_SUMMARY

- name: Checks passed notification
if: needs.pr-checks.result == 'success'
run: |
echo "::notice::PR checks passed! This PR is ready for merge."
106 changes: 94 additions & 12 deletions .github/workflows/sync-azure-storage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,37 +142,51 @@ jobs:
ACCOUNT="${{ steps.sas_info.outputs.account }}"
CONTAINER="${{ steps.sas_info.outputs.container }}"
SAS_TOKEN=$(cat /tmp/sas_token.txt)
RELEASE_TAG="${{ steps.release_info.outputs.tag }}"

echo "Generating index.json..."

# Get GitHub Release published_at for fallback
echo "Fetching GitHub Release publish time..."
PUBLISHED_AT=$(gh release view "${RELEASE_TAG}" --json publishedAt -q .publishedAt)

# Get all blobs and organize by version
# Fixed: Correctly extract lastModified from properties.lastModified
BLOBS=$(az storage blob list \
--account-name "${ACCOUNT}" \
--container-name "${CONTAINER}" \
--sas-token "${SAS_TOKEN}" \
--query "[].{name:name, lastModified:lastModified, size:properties.contentLength}" \
--query "[].{name:name, lastModified:properties.lastModified, size:properties.contentLength}" \
--output json)

# Create JSON index with files organized by version
INDEX_JSON=$(echo "$BLOBS" | jq '{
# Use GitHub Release published_at as fallback if lastModified is null/empty
INDEX_JSON=$(echo "$BLOBS" | jq --arg fallback_time "$PUBLISHED_AT" '{
updatedAt: now,
versions: [
.[]
| select(.name | contains("index.json") | not)
| {
version: (.name | split("/")[0]),
name: (.name | split("/")[1:][-1]),
path: .name,
size: .size,
lastModified: .lastModified
}
version: (.name | split("/")[0]),
name: (.name | split("/")[1:][-1]),
path: .name,
size: .size,
lastModified: (.lastModified // $fallback_time)
}
]
| group_by(.version)
| map({
version: .[0].version,
files: [.[].name],
assets: [.[] | {name: .name, path: .path, size: .size, lastModified: .lastModified}]
})
version: .[0].version,
files: [.[].name],
assets: [
.[] | {
name: .name,
path: .path,
size: .size,
lastModified: (.lastModified // $fallback_time)
}
]
})
| sort_by(.version) | reverse
}')

Expand Down Expand Up @@ -232,3 +246,71 @@ jobs:
echo " 3. SAS token has not expired"
echo " 4. Container exists in Azure Storage"
exit 1

- name: Export outputs
if: always()
run: |
# Export outputs for notification job
ACCOUNT="${{ steps.sas_info.outputs.account }}"
VERSION="${{ steps.release_info.outputs.tag }}"

# Count uploaded files
FILE_COUNT=$(ls -1 ./release-assets/* 2>/dev/null | wc -l)

# Build Azure Storage path
BLOB_PATH="https://${ACCOUNT}.blob.core.windows.net/${{ steps.sas_info.outputs.container }}/${VERSION}/"

echo "tag=${VERSION}" >> $GITHUB_OUTPUT
echo "file_count=${FILE_COUNT}" >> $GITHUB_OUTPUT
echo "blob_path=${BLOB_PATH}" >> $GITHUB_OUTPUT
echo "storage_account=${ACCOUNT}" >> $GITHUB_OUTPUT

echo "Exported outputs:"
echo " tag: ${VERSION}"
echo " file_count: ${FILE_COUNT}"
echo " blob_path: ${BLOB_PATH}"
echo " storage_account: ${ACCOUNT}"

azure-sync-notification:
name: Azure Sync Notification
needs: sync-to-azure
if: always()
runs-on: ubuntu-latest
permissions:
contents: read

steps:
- name: Determine sync status
id: status
run: |
sync_result="${{ needs.sync-to-azure.result }}"

if [ "${sync_result}" == "success" ]; then
echo "status_icon=✅" >> $GITHUB_OUTPUT
echo "status_text=成功" >> $GITHUB_OUTPUT
echo "status_verb=已成功同步到" >> $GITHUB_OUTPUT
else
echo "status_icon=❌" >> $GITHUB_OUTPUT
echo "status_text=失败" >> $GITHUB_OUTPUT
echo "status_verb=同步到" >> $GITHUB_OUTPUT
fi

- name: Notify Feishu
uses: HagiCode-org/haginotifier@v1.0.0
with:
message: |
**Azure 同步${{ steps.status.outputs.status_text }}**

发布资源${{ steps.status.outputs.status_verb }} Azure Storage

版本: ${{ needs.sync-to-azure.outputs.tag }}
上传文件: ${{ needs.sync-to-azure.outputs.file_count }} 个
存储路径: ${{ needs.sync-to-azure.outputs.blob_path }}

提交: `${{ github.sha }}`
触发者: ${{ github.actor }}

[查看详情](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
msg_type: 'post'
title: 'Azure 同步${{ steps.status.outputs.status_text }} ${{ steps.status.outputs.status_icon }}'
secrets: inherit
Loading
Loading