diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4138f00b..cdc01cce 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,10 +9,7 @@ on: types: [published] workflow_dispatch: -permissions: - contents: read - pages: write - id-token: write +permissions: {} concurrency: group: "pages" @@ -24,19 +21,21 @@ env: jobs: build: permissions: - contents: write + contents: read runs-on: sm-standard-2 steps: - name: Checkout - uses: actions/checkout@v7 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false - name: Setup PNPM - uses: pnpm/action-setup@v6 + uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6.1.1 with: cache: true - name: Setup Node - uses: actions/setup-node@v7 + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version: ${{ env.NODE_VERSION }} @@ -47,6 +46,9 @@ jobs: run: pnpm build - name: Zip files + env: + EVENT_NAME: ${{ github.event_name }} + RELEASE_TAG: ${{ github.event.release.tag_name }} run: | set -euo pipefail mkdir -p artifacts @@ -55,19 +57,41 @@ jobs: cd ./out zip -r ../artifacts/rustfs-console-latest.zip . ) - if [ "${{ github.event_name }}" = "release" ]; then - mkdir -p ./artifacts/${{ github.event.release.tag_name }} + if [ "$EVENT_NAME" = "release" ]; then + if [[ -z "$RELEASE_TAG" || "$RELEASE_TAG" == *"/"* || "$RELEASE_TAG" == *".."* ]]; then + echo "Invalid release tag: $RELEASE_TAG" >&2 + exit 1 + fi + mkdir -p "./artifacts/$RELEASE_TAG" ( cd ./out - zip -r ../artifacts/${{ github.event.release.tag_name }}/rustfs-console-${{ github.event.release.tag_name }}.zip . + zip -r "../artifacts/$RELEASE_TAG/rustfs-console-$RELEASE_TAG.zip" . ) fi - - uses: actions/upload-artifact@v7 - name: Upload artifacts + - name: Upload artifacts + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: path: ./artifacts/rustfs-console-latest.zip + - name: Upload publish artifacts + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: console-publish-artifacts + path: ./artifacts + retention-days: 1 + + upload-r2: + needs: build + permissions: {} + runs-on: sm-standard-2 + steps: + - name: Download publish artifacts + uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0 + with: + name: console-publish-artifacts + path: ./artifacts + - name: Setup AWS CLI shell: bash run: | @@ -130,8 +154,22 @@ jobs: echo "โœ… Upload completed successfully" + upload-release-asset: + needs: build + if: ${{ github.event_name == 'release' }} + permissions: + contents: write + runs-on: sm-standard-2 + steps: + - name: Download publish artifacts + uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0 + with: + name: console-publish-artifacts + path: ./artifacts + - name: Upload release asset `versioned` - if: ${{ github.event_name == 'release' }} - uses: softprops/action-gh-release@v3 + uses: softprops/action-gh-release@8a0cd651e5b2365bd640854a3fa5dfc70e4875f3 # v3.0.4 with: - files: ./artifacts/${{ github.event.release.tag_name }}/rustfs-console-${{ github.event.release.tag_name }}.zip + tag_name: ${{ github.event.release.tag_name }} + files: artifacts/${{ github.event.release.tag_name }}/rustfs-console-${{ github.event.release.tag_name }}.zip + fail_on_unmatched_files: true diff --git a/.github/workflows/dependencies.yml b/.github/workflows/dependencies.yml index 9a213260..54e8b449 100644 --- a/.github/workflows/dependencies.yml +++ b/.github/workflows/dependencies.yml @@ -2,43 +2,52 @@ name: ๐Ÿ“ฆ Dependencies Management on: schedule: - # ๆฏๅ‘จไธ€ๅ‡Œๆ™จ 2 ็‚นๆฃ€ๆŸฅไพ่ต–ๆ›ดๆ–ฐ + # ๆฏๅ‘จไธ€ๅ‡Œๆ™จ 2 ็‚นๆ‰ง่กŒๅช่ฏปๅฎ‰ๅ…จๅฎก่ฎกไธŽไพ่ต–ๆ›ดๆ–ฐๆฃ€ๆŸฅ - cron: "0 2 * * 1" workflow_dispatch: inputs: update_type: - description: "Type of update to perform" + description: "Dependency update mode (manual confirmation required for patch/latest)" required: true - default: "patch" + default: "check-only" type: choice options: + - check-only - patch - - minor - - major - - all + - latest + +permissions: {} env: NODE_VERSION: "22" jobs: # ============================================================================ - # ไพ่ต–ๅฎ‰ๅ…จๆ‰ซๆ + # ไพ่ต–ๅฎ‰ๅ…จๆ‰ซๆ (ๅช่ฏป) # ============================================================================ security-audit: name: ๐Ÿ”’ Security Audit runs-on: sm-standard-2 + permissions: + contents: read + + outputs: + create-security-issue: ${{ steps.audit.outputs.create-security-issue }} + security-summary: ${{ steps.audit.outputs.security-summary }} steps: - name: ๐Ÿ“ฅ Checkout code - uses: actions/checkout@v7 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false - name: Setup PNPM - uses: pnpm/action-setup@v6 + uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6.1.1 with: cache: true - name: ๐Ÿ“ฆ Setup Node.js - uses: actions/setup-node@v7 + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version: ${{ env.NODE_VERSION }} @@ -46,109 +55,128 @@ jobs: run: pnpm ci - name: ๐Ÿ”’ Run security audit + id: audit run: | - echo "## ๐Ÿ”’ Security Audit Report" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - - # ่ฟ่กŒๅฎ‰ๅ…จๅฎก่ฎก - if pnpm audit --json > audit-report.json 2>/dev/null; then - # ่งฃๆžๅฎก่ฎก็ป“ๆžœ - vulnerabilities=$(node -e " - const audit = require('./audit-report.json'); - const meta = audit.metadata?.vulnerabilities; - if (meta) { - const total = meta.total || 0; + set -euo pipefail + echo "## ๐Ÿ”’ Security Audit Report" >> "$GITHUB_STEP_SUMMARY" + echo "" >> "$GITHUB_STEP_SUMMARY" + + echo "create-security-issue=false" >> "$GITHUB_OUTPUT" + echo "security-summary=" >> "$GITHUB_OUTPUT" + + pnpm audit --json > audit-report.json 2>/dev/null || true + + if [ -s audit-report.json ]; then + vulnerabilities=$(node -e ' + const fs = require("node:fs"); + try { + const audit = JSON.parse(fs.readFileSync("./audit-report.json", "utf8")); + const meta = audit.metadata?.vulnerabilities || {}; const critical = meta.critical || 0; const high = meta.high || 0; const moderate = meta.moderate || 0; const low = meta.low || 0; - console.log(JSON.stringify({total, critical, high, moderate, low})); - } else { - console.log(JSON.stringify({total: 0, critical: 0, high: 0, moderate: 0, low: 0})); + const total = meta.total ?? (critical + high + moderate + low); + console.log(JSON.stringify({ total, critical, high, moderate, low })); + } catch { + console.log(JSON.stringify({ total: 0, critical: 0, high: 0, moderate: 0, low: 0 })); } - ") - - echo "| Severity | Count |" >> $GITHUB_STEP_SUMMARY - echo "|----------|-------|" >> $GITHUB_STEP_SUMMARY - echo "| Critical | $(echo $vulnerabilities | jq -r '.critical') |" >> $GITHUB_STEP_SUMMARY - echo "| High | $(echo $vulnerabilities | jq -r '.high') |" >> $GITHUB_STEP_SUMMARY - echo "| Moderate | $(echo $vulnerabilities | jq -r '.moderate') |" >> $GITHUB_STEP_SUMMARY - echo "| Low | $(echo $vulnerabilities | jq -r '.low') |" >> $GITHUB_STEP_SUMMARY - echo "| **Total** | **$(echo $vulnerabilities | jq -r '.total')** |" >> $GITHUB_STEP_SUMMARY + ') + + critical=$(echo "$vulnerabilities" | jq -r '.critical') + high=$(echo "$vulnerabilities" | jq -r '.high') + moderate=$(echo "$vulnerabilities" | jq -r '.moderate') + low=$(echo "$vulnerabilities" | jq -r '.low') + total_vulns=$(echo "$vulnerabilities" | jq -r '.total') + + echo "| Severity | Count |" >> "$GITHUB_STEP_SUMMARY" + echo "|----------|-------|" >> "$GITHUB_STEP_SUMMARY" + echo "| Critical | $critical |" >> "$GITHUB_STEP_SUMMARY" + echo "| High | $high |" >> "$GITHUB_STEP_SUMMARY" + echo "| Moderate | $moderate |" >> "$GITHUB_STEP_SUMMARY" + echo "| Low | $low |" >> "$GITHUB_STEP_SUMMARY" + echo "| **Total** | **$total_vulns** |" >> "$GITHUB_STEP_SUMMARY" - total_vulns=$(echo $vulnerabilities | jq -r '.total') if [ "$total_vulns" -gt 0 ]; then - echo "" >> $GITHUB_STEP_SUMMARY - echo "โš ๏ธ **Action Required**: $total_vulns security vulnerabilities found!" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - echo "Run \`pnpm audit --fix\` to automatically fix vulnerabilities." >> $GITHUB_STEP_SUMMARY - - # ๅฆ‚ๆžœๆœ‰้ซ˜ๅฑๆˆ–ไธฅ้‡ๆผๆดž๏ผŒๅˆ›ๅปบ issue - critical=$(echo $vulnerabilities | jq -r '.critical') - high=$(echo $vulnerabilities | jq -r '.high') + echo "" >> "$GITHUB_STEP_SUMMARY" + echo "โš ๏ธ **Action Required**: $total_vulns security vulnerabilities found!" >> "$GITHUB_STEP_SUMMARY" + echo "" >> "$GITHUB_STEP_SUMMARY" + echo "Review the audit report and update affected packages manually." >> "$GITHUB_STEP_SUMMARY" + if [ "$critical" -gt 0 ] || [ "$high" -gt 0 ]; then - echo "create_security_issue=true" >> $GITHUB_ENV - echo "security_summary=Found $critical critical and $high high severity vulnerabilities" >> $GITHUB_ENV + echo "create-security-issue=true" >> "$GITHUB_OUTPUT" + echo "security-summary=Found $critical critical and $high high severity vulnerabilities" >> "$GITHUB_OUTPUT" fi else - echo "" >> $GITHUB_STEP_SUMMARY - echo "โœ… No security vulnerabilities found!" >> $GITHUB_STEP_SUMMARY + echo "" >> "$GITHUB_STEP_SUMMARY" + echo "โœ… No security vulnerabilities found!" >> "$GITHUB_STEP_SUMMARY" fi else - echo "โœ… No security vulnerabilities found!" >> $GITHUB_STEP_SUMMARY + echo "โœ… No security vulnerabilities found!" >> "$GITHUB_STEP_SUMMARY" fi - name: ๐Ÿ“ค Upload audit report - uses: actions/upload-artifact@v7 + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: security-audit-report path: audit-report.json retention-days: 30 + if-no-files-found: ignore + + # ============================================================================ + # ้š”็ฆปไธŠๆŠฅ้ซ˜ๅฑๅฎ‰ๅ…จๅ‘Š่ญฆ Issue + # ============================================================================ + report-security-issue: + name: ๐Ÿšจ Report Security Issue + runs-on: sm-standard-2 + needs: security-audit + if: needs.security-audit.outputs.create-security-issue == 'true' + permissions: + issues: write + steps: - name: ๐Ÿšจ Create security issue - if: env.create_security_issue == 'true' - uses: actions/github-script@v9 + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 + env: + SECURITY_SUMMARY: ${{ needs.security-audit.outputs.security-summary }} with: script: | - const title = '๐Ÿ”’ Security Vulnerabilities Detected' - const body = ` - ## ๐Ÿšจ Security Alert - - Our automated security scan has detected vulnerabilities in the project dependencies. - - **Summary**: ${{ env.security_summary }} - - ## ๐Ÿ”ง Recommended Actions - - 1. Review the security audit report - 2. Run \`pnpm audit fix\` to automatically fix vulnerabilities (or use the detected package manager) - 3. For vulnerabilities that cannot be auto-fixed, consider: - - Updating to a secure version manually - - Finding alternative packages - - Implementing workarounds - - ## ๐Ÿ“Š Full Report - - See the attached audit report for detailed information about each vulnerability. - - **Workflow Run**: [#${{ github.run_number }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - ` - - github.rest.issues.create({ + const summary = process.env.SECURITY_SUMMARY || "High or critical vulnerabilities detected" + const runUrl = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}` + const title = "๐Ÿ”’ Security Vulnerabilities Detected" + const body = [ + "## ๐Ÿšจ Security Alert", + "", + "Our automated security scan has detected vulnerabilities in the project dependencies.", + "", + `**Summary**: ${summary}`, + "", + "## ๐Ÿ”ง Recommended Actions", + "", + "1. Review the security audit report artifact from the workflow run", + "2. Update affected packages locally and verify with `pnpm run test:run` and `pnpm run build`", + "3. Open a reviewed pull request with the updated `package.json` and `pnpm-lock.yaml`", + "", + `**Workflow Run**: [#${process.env.GITHUB_RUN_NUMBER}](${runUrl})`, + ].join("\n") + + await github.rest.issues.create({ owner: context.repo.owner, repo: context.repo.repo, - title: title, - body: body, - labels: ['security', 'dependencies', 'high-priority'] + title, + body, + labels: ["security", "dependencies", "high-priority"], }) # ============================================================================ - # ไพ่ต–ๆ›ดๆ–ฐๆฃ€ๆŸฅ + # ไพ่ต–ๆ›ดๆ–ฐๆฃ€ๆŸฅ (ๅช่ฏป) # ============================================================================ check-updates: name: ๐Ÿ“‹ Check for Updates runs-on: sm-standard-2 needs: security-audit + permissions: + contents: read outputs: has-updates: ${{ steps.check.outputs.has-updates }} @@ -156,15 +184,17 @@ jobs: steps: - name: ๐Ÿ“ฅ Checkout code - uses: actions/checkout@v7 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false - name: Setup PNPM - uses: pnpm/action-setup@v6 + uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6.1.1 with: cache: true - name: ๐Ÿ“ฆ Setup Node.js - uses: actions/setup-node@v7 + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version: ${{ env.NODE_VERSION }} @@ -174,247 +204,178 @@ jobs: - name: ๐Ÿ“‹ Check for outdated packages id: check run: | - echo "## ๐Ÿ“‹ Dependency Update Check" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - - # ๆฃ€ๆŸฅ่ฟ‡ๆœŸ็š„ๅŒ… - if pnpm outdated --json > outdated.json 2>/dev/null; then - if [ -s outdated.json ]; then - echo "has-updates=true" >> $GITHUB_OUTPUT - - # ็”Ÿๆˆๆ›ดๆ–ฐๆ‘˜่ฆ - update_count=$(node -e " - const outdated = require('./outdated.json'); - console.log(Object.keys(outdated).length); - ") - - echo "update-summary=Found $update_count packages that can be updated" >> $GITHUB_OUTPUT - - echo "### ๐Ÿ“ฆ Outdated Packages ($update_count)" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - echo "| Package | Current | Wanted | Latest | Type |" >> $GITHUB_STEP_SUMMARY - echo "|---------|---------|--------|--------|------|" >> $GITHUB_STEP_SUMMARY - - node -e " - const outdated = require('./outdated.json'); - Object.entries(outdated).forEach(([pkg, info]) => { - const updateType = info.wanted !== info.current ? 'wanted' : 'latest'; - console.log(\`| \${pkg} | \${info.current} | \${info.wanted} | \${info.latest} | \${updateType} |\`); - }); - " >> $GITHUB_STEP_SUMMARY - - echo "" >> $GITHUB_STEP_SUMMARY - echo "๐Ÿ”„ Updates are available! Consider running the dependency update workflow." >> $GITHUB_STEP_SUMMARY - else - echo "has-updates=false" >> $GITHUB_OUTPUT - echo "update-summary=All packages are up to date" >> $GITHUB_OUTPUT - echo "โœ… All packages are up to date!" >> $GITHUB_STEP_SUMMARY - fi + set -euo pipefail + echo "## ๐Ÿ“‹ Dependency Update Check" >> "$GITHUB_STEP_SUMMARY" + echo "" >> "$GITHUB_STEP_SUMMARY" + + pnpm outdated --json > outdated.json 2>/dev/null || true + + update_count=$(node -e ' + const fs = require("node:fs"); + try { + const raw = fs.readFileSync("./outdated.json", "utf8").trim(); + const outdated = raw ? JSON.parse(raw) : {}; + console.log(Object.keys(outdated).length); + } catch { + console.log(0); + } + ') + + if [ "$update_count" -gt 0 ]; then + echo "has-updates=true" >> "$GITHUB_OUTPUT" + echo "update-summary=Found $update_count packages that can be updated" >> "$GITHUB_OUTPUT" + + echo "### ๐Ÿ“ฆ Outdated Packages ($update_count)" >> "$GITHUB_STEP_SUMMARY" + echo "" >> "$GITHUB_STEP_SUMMARY" + echo "| Package | Current | Wanted | Latest | Type |" >> "$GITHUB_STEP_SUMMARY" + echo "|---------|---------|--------|--------|------|" >> "$GITHUB_STEP_SUMMARY" + + node -e ' + const fs = require("node:fs"); + const outdated = JSON.parse(fs.readFileSync("./outdated.json", "utf8")); + Object.entries(outdated).forEach(([pkg, info]) => { + const updateType = info.wanted !== info.current ? "wanted" : "latest"; + console.log(`| ${pkg} | ${info.current} | ${info.wanted} | ${info.latest} | ${updateType} |`); + }); + ' >> "$GITHUB_STEP_SUMMARY" + + echo "" >> "$GITHUB_STEP_SUMMARY" + echo "๐Ÿ”„ Updates are available. Trigger this workflow manually with \`patch\` or \`latest\` to prepare a verified update patch artifact for review." >> "$GITHUB_STEP_SUMMARY" else - echo "has-updates=false" >> $GITHUB_OUTPUT - echo "update-summary=All packages are up to date" >> $GITHUB_OUTPUT - echo "โœ… All packages are up to date!" >> $GITHUB_STEP_SUMMARY + echo "has-updates=false" >> "$GITHUB_OUTPUT" + echo "update-summary=All packages are up to date" >> "$GITHUB_OUTPUT" + echo "โœ… All packages are up to date!" >> "$GITHUB_STEP_SUMMARY" fi - name: ๐Ÿ“ค Upload outdated report - uses: actions/upload-artifact@v7 + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: outdated-packages-report path: outdated.json retention-days: 7 + if-no-files-found: ignore # ============================================================================ - # ่‡ชๅŠจไพ่ต–ๆ›ดๆ–ฐ + # ไบบๅทฅ็กฎ่ฎคๆ›ดๆ–ฐๆผ”็ปƒ (ไป…ๆ‰‹ๅŠจ่งฆๅ‘๏ผŒๆ— ไป“ๅบ“ๅ†™ๆƒ้™๏ผŒ่พ“ๅ‡บๅฏๅฎก้˜…่กฅไธๅˆถๅ“) # ============================================================================ - auto-update: - name: ๐Ÿ”„ Auto Update Dependencies + prepare-update: + name: ๐Ÿ”„ Prepare Dependency Update Patch runs-on: sm-standard-2 needs: [security-audit, check-updates] - if: needs.check-updates.outputs.has-updates == 'true' + if: github.event_name == 'workflow_dispatch' && inputs.update_type != 'check-only' + permissions: + contents: read steps: - name: ๐Ÿ“ฅ Checkout code - uses: actions/checkout@v7 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: - token: ${{ secrets.GITHUB_TOKEN }} + persist-credentials: false - name: Setup PNPM - uses: pnpm/action-setup@v6 + uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6.1.1 with: cache: true - name: ๐Ÿ“ฆ Setup Node.js - uses: actions/setup-node@v7 + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version: ${{ env.NODE_VERSION }} - name: ๐Ÿ“ฅ Install dependencies run: pnpm ci - - name: ๐Ÿ”„ Update dependencies + - name: ๐Ÿ”„ Update dependencies with pinned pnpm + env: + UPDATE_TYPE: ${{ inputs.update_type }} run: | - echo "## ๐Ÿ”„ Updating Dependencies" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - - update_type="${{ github.event.inputs.update_type || 'patch' }}" + set -euo pipefail + echo "## ๐Ÿ”„ Preparing Dependency Updates ($UPDATE_TYPE)" >> "$GITHUB_STEP_SUMMARY" + echo "" >> "$GITHUB_STEP_SUMMARY" - case $update_type in + case "$UPDATE_TYPE" in "patch") - echo "Updating patch versions..." >> $GITHUB_STEP_SUMMARY + echo "Updating dependencies within declared semver ranges via \`pnpm update\`..." >> "$GITHUB_STEP_SUMMARY" pnpm update ;; - "minor") - echo "Updating minor versions..." >> $GITHUB_STEP_SUMMARY - pnpm dlx npm-check-updates -u -p pnpm --target minor - pnpm install - ;; - "major") - echo "Updating major versions..." >> $GITHUB_STEP_SUMMARY - pnpm dlx npm-check-updates -u -p pnpm --target major - pnpm install + "latest") + echo "Updating dependencies to latest versions via \`pnpm update --latest\`..." >> "$GITHUB_STEP_SUMMARY" + pnpm update --latest ;; - "all") - echo "Updating all versions..." >> $GITHUB_STEP_SUMMARY - pnpm dlx npm-check-updates -u -p pnpm - pnpm install + *) + echo "Unsupported update_type: $UPDATE_TYPE" >&2 + exit 1 ;; esac - - name: ๐Ÿงช Run tests after update + - name: ๐Ÿงช Verify updated dependencies run: | - echo "## ๐Ÿงช Testing Updated Dependencies" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY + set -euo pipefail + echo "## ๐Ÿงช Verifying Updated Dependencies" >> "$GITHUB_STEP_SUMMARY" + echo "" >> "$GITHUB_STEP_SUMMARY" - # ๅฎ‰่ฃ…ๆต‹่ฏ•ไพ่ต– - pnpm add -D vitest jsdom @vitest/ui c8 - - # ่ฟ่กŒๆต‹่ฏ• - if pnpm vitest run tests/utils/config-helpers*.test.ts --reporter=verbose; then - echo "โœ… All tests passed with updated dependencies!" >> $GITHUB_STEP_SUMMARY - echo "test_status=passed" >> $GITHUB_ENV + if pnpm run test:run && pnpm run type-check; then + echo "โœ… Tests and type-check passed with updated dependencies!" >> "$GITHUB_STEP_SUMMARY" else - echo "โŒ Tests failed with updated dependencies!" >> $GITHUB_STEP_SUMMARY - echo "test_status=failed" >> $GITHUB_ENV + echo "โŒ Verification failed with updated dependencies!" >> "$GITHUB_STEP_SUMMARY" + exit 1 fi - - name: ๐Ÿ” Check for changes + - name: ๐Ÿ” Export reviewable update patch id: changes run: | - if [[ -n $(git status --porcelain) ]]; then - echo "changes=true" >> $GITHUB_OUTPUT - - # ็”Ÿๆˆๅ˜ๆ›ดๆ‘˜่ฆ - echo "## ๐Ÿ“ Changes Made" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - echo "### Modified Files:" >> $GITHUB_STEP_SUMMARY - git status --porcelain | while read status file; do - echo "- $file" >> $GITHUB_STEP_SUMMARY - done - - # ๆฃ€ๆŸฅ package.json ็š„ๅ˜ๆ›ด - if git diff --name-only | grep -q "package.json\|pnpm-lock.yaml"; then - echo "" >> $GITHUB_STEP_SUMMARY - echo "### Package Changes:" >> $GITHUB_STEP_SUMMARY - echo "\`\`\`diff" >> $GITHUB_STEP_SUMMARY - git diff package.json | head -50 >> $GITHUB_STEP_SUMMARY - echo "\`\`\`" >> $GITHUB_STEP_SUMMARY - fi + set -euo pipefail + if [[ -n "$(git status --porcelain -- package.json pnpm-lock.yaml)" ]]; then + echo "changes=true" >> "$GITHUB_OUTPUT" + git diff -- package.json pnpm-lock.yaml > dependency-update.patch + + echo "## ๐Ÿ“ Reviewable Update Patch Generated" >> "$GITHUB_STEP_SUMMARY" + echo "" >> "$GITHUB_STEP_SUMMARY" + echo "Download the \`dependency-update-patch\` artifact, review the diff, and apply it locally with \`git apply dependency-update.patch\` before opening a pull request." >> "$GITHUB_STEP_SUMMARY" + echo "" >> "$GITHUB_STEP_SUMMARY" + echo "### Package Changes:" >> "$GITHUB_STEP_SUMMARY" + echo "\`\`\`diff" >> "$GITHUB_STEP_SUMMARY" + git diff package.json | awk 'NR <= 50' >> "$GITHUB_STEP_SUMMARY" + echo "\`\`\`" >> "$GITHUB_STEP_SUMMARY" else - echo "changes=false" >> $GITHUB_OUTPUT - echo "No changes detected." >> $GITHUB_STEP_SUMMARY + echo "changes=false" >> "$GITHUB_OUTPUT" + echo "No changes detected." >> "$GITHUB_STEP_SUMMARY" fi - - name: ๐Ÿ”ง Create Pull Request - if: steps.changes.outputs.changes == 'true' && env.test_status == 'passed' - uses: peter-evans/create-pull-request@v8 - with: - token: ${{ secrets.GITHUB_TOKEN }} - commit-message: "๐Ÿ”„ chore: update dependencies (${{ github.event.inputs.update_type || 'patch' }})" - title: "๐Ÿ”„ Dependency Updates (${{ github.event.inputs.update_type || 'patch' }})" - body: | - ## ๐Ÿ”„ Automated Dependency Update - - This PR contains automated dependency updates. - - ### ๐Ÿ“‹ Update Summary - - **Update Type**: ${{ github.event.inputs.update_type || 'patch' }} - - **Status**: ${{ needs.check-updates.outputs.update-summary }} - - ### ๐Ÿงช Testing - - โœ… All existing tests pass - - โœ… No breaking changes detected - - โœ… Security audit completed - - ### ๐Ÿ” Review Checklist - - [ ] Review dependency changes - - [ ] Verify test results - - [ ] Check for any breaking changes - - [ ] Approve and merge if everything looks good - - --- - - ๐Ÿค– This PR was created automatically by the dependency management workflow. - - **Workflow Run**: [#${{ github.run_number }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - branch: automated/dependency-updates-${{ github.run_number }} - labels: | - dependencies - automated - ${{ github.event.inputs.update_type || 'patch' }} - reviewers: "" - draft: false - - - name: โŒ Report failed update - if: steps.changes.outputs.changes == 'true' && env.test_status == 'failed' - uses: actions/github-script@v9 + - name: ๐Ÿ“ค Upload reviewable update patch + if: steps.changes.outputs.changes == 'true' + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: - script: | - const title = 'โŒ Dependency Update Failed' - const body = ` - ## โŒ Automated Dependency Update Failed - - The automated dependency update process failed because tests did not pass with the updated dependencies. - - ### ๐Ÿ“‹ Details - - **Update Type**: ${{ github.event.inputs.update_type || 'patch' }} - - **Status**: Tests failed after dependency updates - - ### ๐Ÿ”ง Next Steps - 1. Review the test failures in the workflow logs - 2. Manually investigate compatibility issues - 3. Update dependencies individually if needed - 4. Fix any breaking changes introduced by updates - - **Workflow Run**: [#${{ github.run_number }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) - ` - - github.rest.issues.create({ - owner: context.repo.owner, - repo: context.repo.repo, - title: title, - body: body, - labels: ['dependencies', 'failed-update', 'needs-investigation'] - }) + name: dependency-update-patch + path: | + dependency-update.patch + package.json + pnpm-lock.yaml + retention-days: 14 # ============================================================================ - # ไพ่ต–ๅˆ†ๆžๆŠฅๅ‘Š + # ไพ่ต–ๅˆ†ๆžๆŠฅๅ‘Š (ๅช่ฏป) # ============================================================================ dependency-analysis: name: ๐Ÿ“Š Dependency Analysis runs-on: sm-standard-2 needs: [security-audit, check-updates] + permissions: + contents: read steps: - name: ๐Ÿ“ฅ Checkout code - uses: actions/checkout@v7 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false - name: Setup PNPM - uses: pnpm/action-setup@v6 + uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6.1.1 with: cache: true - name: ๐Ÿ“ฆ Setup Node.js - uses: actions/setup-node@v7 + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version: ${{ env.NODE_VERSION }} @@ -423,43 +384,45 @@ jobs: - name: ๐Ÿ“Š Generate dependency report run: | - echo "# ๐Ÿ“Š Dependency Analysis Report" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY + set -euo pipefail + echo "# ๐Ÿ“Š Dependency Analysis Report" >> "$GITHUB_STEP_SUMMARY" + echo "" >> "$GITHUB_STEP_SUMMARY" # ไพ่ต–็ปŸ่ฎก - total_deps=$(pnpm list --depth=0 --json | jq '.dependencies | length') - dev_deps=$(pnpm list --depth=0 --dev --json | jq '.dependencies | length // 0') - prod_deps=$((total_deps - dev_deps)) - - echo "## ๐Ÿ“ˆ Dependency Statistics" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - echo "| Category | Count |" >> $GITHUB_STEP_SUMMARY - echo "|----------|-------|" >> $GITHUB_STEP_SUMMARY - echo "| Production Dependencies | $prod_deps |" >> $GITHUB_STEP_SUMMARY - echo "| Development Dependencies | $dev_deps |" >> $GITHUB_STEP_SUMMARY - echo "| **Total Dependencies** | **$total_deps** |" >> $GITHUB_STEP_SUMMARY + dep_json=$(pnpm list --depth=0 --json) + prod_deps=$(echo "$dep_json" | jq '.[0].dependencies // {} | length') + dev_deps=$(echo "$dep_json" | jq '.[0].devDependencies // {} | length') + total_deps=$((prod_deps + dev_deps)) + + echo "## ๐Ÿ“ˆ Dependency Statistics" >> "$GITHUB_STEP_SUMMARY" + echo "" >> "$GITHUB_STEP_SUMMARY" + echo "| Category | Count |" >> "$GITHUB_STEP_SUMMARY" + echo "|----------|-------|" >> "$GITHUB_STEP_SUMMARY" + echo "| Production Dependencies | $prod_deps |" >> "$GITHUB_STEP_SUMMARY" + echo "| Development Dependencies | $dev_deps |" >> "$GITHUB_STEP_SUMMARY" + echo "| **Total Dependencies** | **$total_deps** |" >> "$GITHUB_STEP_SUMMARY" # ๅŒ…ๅคงๅฐๅˆ†ๆž - echo "" >> $GITHUB_STEP_SUMMARY - echo "## ๐Ÿ“ฆ Package Size Analysis" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY + echo "" >> "$GITHUB_STEP_SUMMARY" + echo "## ๐Ÿ“ฆ Package Size Analysis" >> "$GITHUB_STEP_SUMMARY" + echo "" >> "$GITHUB_STEP_SUMMARY" if command -v du &> /dev/null; then node_modules_size=$(du -sh node_modules 2>/dev/null | cut -f1 || echo "N/A") - echo "- **node_modules size**: $node_modules_size" >> $GITHUB_STEP_SUMMARY + echo "- **node_modules size**: $node_modules_size" >> "$GITHUB_STEP_SUMMARY" fi # ่ฎธๅฏ่ฏๅˆ†ๆž - echo "" >> $GITHUB_STEP_SUMMARY - echo "## ๐Ÿ“œ License Analysis" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - echo "License information for production dependencies:" >> $GITHUB_STEP_SUMMARY + echo "" >> "$GITHUB_STEP_SUMMARY" + echo "## ๐Ÿ“œ License Analysis" >> "$GITHUB_STEP_SUMMARY" + echo "" >> "$GITHUB_STEP_SUMMARY" + echo "License information for production dependencies:" >> "$GITHUB_STEP_SUMMARY" # ่ฟ™้‡ŒๅฏไปฅๆทปๅŠ ่ฎธๅฏ่ฏๆฃ€ๆŸฅ้€ป่พ‘ - echo "- Most packages use MIT license (detailed analysis available on request)" >> $GITHUB_STEP_SUMMARY + echo "- Most packages use MIT license (detailed analysis available on request)" >> "$GITHUB_STEP_SUMMARY" - name: ๐Ÿ“ค Upload analysis report - uses: actions/upload-artifact@v7 + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: dependency-analysis-report path: | diff --git a/.github/workflows/quality.yml b/.github/workflows/quality.yml index 95353c4e..55086856 100644 --- a/.github/workflows/quality.yml +++ b/.github/workflows/quality.yml @@ -9,6 +9,8 @@ on: # ๆฏๅคฉๅ‡Œๆ™จ 2 ็‚น่ฟ่กŒ่ดจ้‡ๆฃ€ๆŸฅ - cron: "0 2 * * *" +permissions: {} + env: NODE_VERSION: "22" @@ -19,18 +21,22 @@ jobs: formatting: name: ๐Ÿ’… Code Formatting runs-on: sm-standard-2 + permissions: + contents: read steps: - name: ๐Ÿ“ฅ Checkout code - uses: actions/checkout@v7 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false - name: Setup PNPM - uses: pnpm/action-setup@v6 + uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6.1.1 with: cache: true - name: ๐Ÿ“ฆ Setup Node.js - uses: actions/setup-node@v7 + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version: ${{ env.NODE_VERSION }} @@ -46,18 +52,22 @@ jobs: typescript: name: ๐Ÿ“˜ TypeScript Check runs-on: sm-standard-2 + permissions: + contents: read steps: - name: ๐Ÿ“ฅ Checkout code - uses: actions/checkout@v7 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false - name: Setup PNPM - uses: pnpm/action-setup@v6 + uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6.1.1 with: cache: true - name: ๐Ÿ“ฆ Setup Node.js - uses: actions/setup-node@v7 + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version: ${{ env.NODE_VERSION }} @@ -79,18 +89,22 @@ jobs: dependencies: name: ๐Ÿ“ฆ Dependencies Check runs-on: sm-standard-2 + permissions: + contents: read steps: - name: ๐Ÿ“ฅ Checkout code - uses: actions/checkout@v7 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false - name: Setup PNPM - uses: pnpm/action-setup@v6 + uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6.1.1 with: cache: true - name: ๐Ÿ“ฆ Setup Node.js - uses: actions/setup-node@v7 + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version: ${{ env.NODE_VERSION }} @@ -153,25 +167,14 @@ jobs: complexity: name: ๐Ÿงฎ Code Complexity runs-on: sm-standard-2 + permissions: + contents: read steps: - name: ๐Ÿ“ฅ Checkout code - uses: actions/checkout@v7 - - - name: Setup PNPM - uses: pnpm/action-setup@v6 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: - cache: true - - - name: ๐Ÿ“ฆ Setup Node.js - uses: actions/setup-node@v7 - with: - node-version: ${{ env.NODE_VERSION }} - - - name: ๐Ÿ“ฅ Install dependencies - run: | - pnpm ci - pnpm add -D eslint-plugin-complexity + persist-credentials: false - name: ๐Ÿงฎ Analyze code complexity run: | @@ -218,10 +221,14 @@ jobs: documentation: name: ๐Ÿ“š Documentation Check runs-on: sm-standard-2 + permissions: + contents: read steps: - name: ๐Ÿ“ฅ Checkout code - uses: actions/checkout@v7 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false - name: ๐Ÿ“š Check documentation coverage run: | @@ -271,6 +278,7 @@ jobs: runs-on: sm-standard-2 needs: [formatting, typescript, dependencies, complexity, documentation] if: always() + permissions: {} steps: - name: ๐Ÿ“‹ Generate quality report diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c6f44e99..ba3f67a3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -16,8 +16,7 @@ on: env: NODE_VERSION: "22" -permissions: - contents: write +permissions: {} jobs: # ============================================================================ @@ -27,6 +26,8 @@ jobs: name: ๐Ÿ” Pre-Release Validation runs-on: sm-standard-2 timeout-minutes: 20 + permissions: + contents: read outputs: version: ${{ steps.version.outputs.version }} @@ -34,17 +35,18 @@ jobs: steps: - name: ๐Ÿ“ฅ Checkout code - uses: actions/checkout@v7 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 + persist-credentials: false - name: Setup PNPM - uses: pnpm/action-setup@v6 + uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6.1.1 with: cache: true - name: ๐Ÿ“ฆ Setup Node.js - uses: actions/setup-node@v7 + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version: ${{ env.NODE_VERSION }} @@ -53,14 +55,22 @@ jobs: - name: ๐Ÿท๏ธ Extract version id: version + env: + EVENT_NAME: ${{ github.event_name }} + INPUT_VERSION: ${{ github.event.inputs.version }} run: | - if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then - VERSION="${{ github.event.inputs.version }}" + set -euo pipefail + if [ "$EVENT_NAME" = "workflow_dispatch" ]; then + VERSION="$INPUT_VERSION" else VERSION=${GITHUB_REF#refs/tags/} fi - echo "version=$VERSION" >> $GITHUB_OUTPUT - echo "Version: $VERSION" >> $GITHUB_STEP_SUMMARY + if [[ -z "$VERSION" || ! "$VERSION" =~ ^v?[0-9A-Za-z._-]+$ || "$VERSION" == *".."* ]]; then + echo "Invalid release version: $VERSION" >&2 + exit 1 + fi + echo "version=$VERSION" >> "$GITHUB_OUTPUT" + echo "Version: $VERSION" >> "$GITHUB_STEP_SUMMARY" - name: ๐Ÿงช Run full test suite run: | @@ -97,18 +107,22 @@ jobs: runs-on: sm-standard-2 needs: pre-release-validation if: needs.pre-release-validation.outputs.should-deploy == 'true' + permissions: + contents: read steps: - name: ๐Ÿ“ฅ Checkout code - uses: actions/checkout@v7 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false - name: Setup PNPM - uses: pnpm/action-setup@v6 + uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6.1.1 with: cache: true - name: ๐Ÿ“ฆ Setup Node.js - uses: actions/setup-node@v7 + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version: ${{ env.NODE_VERSION }} @@ -116,16 +130,20 @@ jobs: run: pnpm ci - name: ๐Ÿ—๏ธ Build for production + env: + RELEASE_VERSION: ${{ needs.pre-release-validation.outputs.version }} run: | pnpm run build - echo "## ๐Ÿ—๏ธ Build Information" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - echo "- **Version**: ${{ needs.pre-release-validation.outputs.version }}" >> $GITHUB_STEP_SUMMARY - echo "- **Node.js**: ${{ env.NODE_VERSION }}" >> $GITHUB_STEP_SUMMARY - echo "- **Build Time**: $(date -u +"%Y-%m-%d %H:%M:%S UTC")" >> $GITHUB_STEP_SUMMARY - echo "- **Commit**: ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY + echo "## ๐Ÿ—๏ธ Build Information" >> "$GITHUB_STEP_SUMMARY" + echo "" >> "$GITHUB_STEP_SUMMARY" + echo "- **Version**: $RELEASE_VERSION" >> "$GITHUB_STEP_SUMMARY" + echo "- **Node.js**: $NODE_VERSION" >> "$GITHUB_STEP_SUMMARY" + echo "- **Build Time**: $(date -u +"%Y-%m-%d %H:%M:%S UTC")" >> "$GITHUB_STEP_SUMMARY" + echo "- **Commit**: $GITHUB_SHA" >> "$GITHUB_STEP_SUMMARY" - name: ๐Ÿ“ฆ Create zip artifacts + env: + RELEASE_VERSION: ${{ needs.pre-release-validation.outputs.version }} run: | set -euo pipefail if [[ ! -s out/index.html ]]; then @@ -138,14 +156,14 @@ jobs: cd ./out zip -r ../artifacts/rustfs-console-latest.zip . ) - mkdir -p artifacts/${{ needs.pre-release-validation.outputs.version }} + mkdir -p "artifacts/$RELEASE_VERSION" ( cd ./out - zip -r ../artifacts/${{ needs.pre-release-validation.outputs.version }}/rustfs-console-${{ needs.pre-release-validation.outputs.version }}.zip . + zip -r "../artifacts/$RELEASE_VERSION/rustfs-console-$RELEASE_VERSION.zip" . ) - name: ๐Ÿ“ค Upload build artifacts - uses: actions/upload-artifact@v7 + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: release-build-${{ needs.pre-release-validation.outputs.version }} path: | @@ -176,35 +194,41 @@ jobs: runs-on: sm-standard-2 needs: [pre-release-validation, build-release] if: needs.pre-release-validation.outputs.should-deploy == 'true' && github.event_name == 'push' + permissions: + contents: write steps: - name: ๐Ÿ“ฅ Checkout code - uses: actions/checkout@v7 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 0 + persist-credentials: false - name: ๐Ÿ“ฅ Download release artifact - uses: actions/download-artifact@v7 + uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0 with: name: release-build-${{ needs.pre-release-validation.outputs.version }} path: release-assets - name: ๐Ÿ“ Generate changelog id: changelog + env: + RELEASE_VERSION: ${{ needs.pre-release-validation.outputs.version }} run: | - echo "## ๐ŸŽ‰ What's New in ${{ needs.pre-release-validation.outputs.version }}" > CHANGELOG.md + echo "## ๐ŸŽ‰ What's New in $RELEASE_VERSION" > CHANGELOG.md echo "" >> CHANGELOG.md PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "") if [ -n "$PREVIOUS_TAG" ]; then echo "### ๐Ÿ”„ Changes since $PREVIOUS_TAG" >> CHANGELOG.md echo "" >> CHANGELOG.md - git log --pretty=format:"- %s (%h)" $PREVIOUS_TAG..HEAD >> CHANGELOG.md + git log --pretty=format:"- %s (%h)" "$PREVIOUS_TAG..HEAD" >> CHANGELOG.md else echo "### ๐ŸŽ‰ Initial Release" >> CHANGELOG.md echo "" >> CHANGELOG.md fi + - name: ๐Ÿท๏ธ Create release - uses: softprops/action-gh-release@v3 + uses: softprops/action-gh-release@8a0cd651e5b2365bd640854a3fa5dfc70e4875f3 # v3.0.4 with: tag_name: ${{ needs.pre-release-validation.outputs.version }} name: Release ${{ needs.pre-release-validation.outputs.version }} @@ -222,21 +246,24 @@ jobs: runs-on: sm-standard-2 needs: [pre-release-validation, create-release] if: always() && needs.pre-release-validation.outputs.should-deploy == 'true' + permissions: {} steps: - name: ๐Ÿ“ข Success notification if: needs.create-release.result == 'success' + env: + RELEASE_VERSION: ${{ needs.pre-release-validation.outputs.version }} run: | - echo "# ๐ŸŽ‰ Release Successful!" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - echo "## ๐Ÿ“‹ Release Summary" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - echo "- **Version**: ${{ needs.pre-release-validation.outputs.version }}" >> $GITHUB_STEP_SUMMARY - echo "- **Status**: โœ… Released Successfully" >> $GITHUB_STEP_SUMMARY + echo "# ๐ŸŽ‰ Release Successful!" >> "$GITHUB_STEP_SUMMARY" + echo "" >> "$GITHUB_STEP_SUMMARY" + echo "## ๐Ÿ“‹ Release Summary" >> "$GITHUB_STEP_SUMMARY" + echo "" >> "$GITHUB_STEP_SUMMARY" + echo "- **Version**: $RELEASE_VERSION" >> "$GITHUB_STEP_SUMMARY" + echo "- **Status**: โœ… Released Successfully" >> "$GITHUB_STEP_SUMMARY" - name: ๐Ÿ“ข Failure notification if: needs.create-release.result == 'failure' run: | - echo "# โŒ Release Failed!" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - echo "Release creation failed. Please check the logs and retry." >> $GITHUB_STEP_SUMMARY + echo "# โŒ Release Failed!" >> "$GITHUB_STEP_SUMMARY" + echo "" >> "$GITHUB_STEP_SUMMARY" + echo "Release creation failed. Please check the logs and retry." >> "$GITHUB_STEP_SUMMARY" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index da8b958a..493cf80a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,6 +7,8 @@ on: branches: [main, develop] workflow_dispatch: +permissions: {} + concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true @@ -22,18 +24,22 @@ jobs: name: ๐Ÿ” Code Quality runs-on: sm-standard-2 timeout-minutes: 10 + permissions: + contents: read steps: - name: ๐Ÿ“ฅ Checkout code - uses: actions/checkout@v7 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false - name: Setup PNPM - uses: pnpm/action-setup@v6 + uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6.1.1 with: cache: true - name: ๐Ÿ“ฆ Setup Node.js - uses: actions/setup-node@v7 + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version: ${{ env.NODE_VERSION }} @@ -54,18 +60,22 @@ jobs: runs-on: sm-standard-2 timeout-minutes: 15 needs: lint + permissions: + contents: read steps: - name: ๐Ÿ“ฅ Checkout code - uses: actions/checkout@v7 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false - name: Setup PNPM - uses: pnpm/action-setup@v6 + uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6.1.1 with: cache: true - name: ๐Ÿ“ฆ Setup Node.js ${{ env.NODE_VERSION }} - uses: actions/setup-node@v7 + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version: ${{ env.NODE_VERSION }} @@ -76,7 +86,7 @@ jobs: run: pnpm run test:run - name: ๐Ÿ“Š Upload test results - uses: actions/upload-artifact@v7 + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 if: always() with: name: unit-test-results-node-${{ env.NODE_VERSION }} @@ -94,18 +104,22 @@ jobs: runs-on: sm-standard-2 timeout-minutes: 15 needs: lint + permissions: + contents: read steps: - name: ๐Ÿ“ฅ Checkout code - uses: actions/checkout@v7 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false - name: Setup PNPM - uses: pnpm/action-setup@v6 + uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6.1.1 with: cache: true - name: ๐Ÿ“ฆ Setup Node.js - uses: actions/setup-node@v7 + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version: ${{ env.NODE_VERSION }} @@ -116,7 +130,7 @@ jobs: run: pnpm run build - name: ๐Ÿ“ฆ Upload build artifacts - uses: actions/upload-artifact@v7 + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: name: build-output path: | @@ -133,6 +147,7 @@ jobs: runs-on: sm-standard-2 needs: [unit-tests, build-test] if: always() + permissions: {} steps: - name: ๐Ÿ“‹ Generate test summary diff --git a/tests/lib/workflow-supply-chain-source.test.js b/tests/lib/workflow-supply-chain-source.test.js new file mode 100644 index 00000000..49e39375 --- /dev/null +++ b/tests/lib/workflow-supply-chain-source.test.js @@ -0,0 +1,84 @@ +import test from "node:test" +import assert from "node:assert/strict" +import fs from "node:fs" +import path from "node:path" + +const WORKFLOWS_DIR = ".github/workflows" +const workflowFiles = fs + .readdirSync(WORKFLOWS_DIR) + .filter((name) => name.endsWith(".yml") || name.endsWith(".yaml")) + .sort() + +function readWorkflow(name) { + return fs.readFileSync(path.join(WORKFLOWS_DIR, name), "utf8") +} + +test("all GitHub Actions external uses are pinned to 40-char commit SHAs", () => { + assert.ok(workflowFiles.length > 0, "expected at least one workflow file") + + for (const file of workflowFiles) { + const lines = readWorkflow(file).split("\n") + for (const [index, line] of lines.entries()) { + const match = line.match(/^\s*(?:-\s+)?uses:\s*([^\s#]+)/) + if (!match) continue + + const ref = match[1] + if (ref.startsWith("./")) continue + + assert.match( + ref, + /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+(?:\/[A-Za-z0-9_.-]+)*@[0-9a-f]{40}$/, + `${file}:${index + 1} must pin external action ${ref} to a 40-char commit SHA`, + ) + assert.match(line, /#\s*v\d+/, `${file}:${index + 1} should include an inline version comment`) + } + } +}) + +test("all workflows default to empty top-level permissions and explicit job permissions", () => { + for (const file of workflowFiles) { + const content = readWorkflow(file) + assert.match(content, /^permissions:\s*\{\}\s*$/m, `${file} must declare top-level permissions: {}`) + + const jobsSection = content.split(/^jobs:\s*$/m)[1] ?? "" + const jobBlocks = jobsSection + .split(/\n(?= [a-zA-Z0-9_-]+:\s*$)/) + .filter((block) => /^ [a-zA-Z0-9_-]+:/m.test(block)) + assert.ok(jobBlocks.length > 0, `${file} must define at least one job`) + + for (const block of jobBlocks) { + const jobName = block.match(/^ ([a-zA-Z0-9_-]+):/m)?.[1] ?? "unknown" + assert.match( + block, + /^ permissions:(?:\s*\{\}|\n(?: [a-z-]+:\s*(?:read|write|none)\n?)+)/m, + `${file} job "${jobName}" must declare explicit minimal permissions`, + ) + } + } +}) + +test("workflows do not execute unpinned runtime pnpm dlx/add installs or auto-PR bots", () => { + for (const file of workflowFiles) { + const content = readWorkflow(file) + assert.doesNotMatch(content, /\bpnpm\s+dlx\b/, `${file} must not execute runtime pnpm dlx`) + assert.doesNotMatch(content, /\bpnpm\s+add\b/, `${file} must not install packages at runtime via pnpm add`) + assert.doesNotMatch( + content, + /peter-evans\/create-pull-request/, + `${file} must not open automated PRs via GITHUB_TOKEN`, + ) + } +}) + +test("build and release workflows isolate contents:write away from pnpm build jobs", () => { + const buildWorkflow = readWorkflow("build.yml") + const buildJob = buildWorkflow.match(/ build:\n[\s\S]*?(?=\n upload-r2:)/)?.[0] ?? "" + assert.doesNotMatch(buildJob, /contents:\s*write/, "build.yml build job must not grant contents: write") + assert.doesNotMatch(buildJob, /R2_SECRET_ACCESS_KEY/, "build.yml build job must not receive R2 secrets") + + const releaseWorkflow = readWorkflow("release.yml") + const preReleaseJob = releaseWorkflow.match(/ pre-release-validation:\n[\s\S]*?(?=\n build-release:)/)?.[0] ?? "" + const buildReleaseJob = releaseWorkflow.match(/ build-release:\n[\s\S]*?(?=\n create-release:)/)?.[0] ?? "" + assert.doesNotMatch(preReleaseJob, /contents:\s*write/, "release.yml pre-release-validation must not write contents") + assert.doesNotMatch(buildReleaseJob, /contents:\s*write/, "release.yml build-release must not write contents") +})