fix: 🐛 build error #615
Workflow file for this run
This file contains hidden or 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: Release Version | |
| # Publish npm packages based on git tags (v*) | |
| on: | |
| push: | |
| tags: ["v*"] | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| environment: release | |
| permissions: | |
| contents: read | |
| id-token: write # | |
| outputs: | |
| tag: ${{ steps.extract_tag.outputs.result }} | |
| steps: | |
| - name: Extract tag | |
| id: extract_tag | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const prefix = 'refs/tags/'; | |
| const ref = context.ref; | |
| if (!ref.startsWith(prefix)) { | |
| throw new Error('Invalid ref: not a tag'); | |
| } | |
| return ref.substring(prefix.length); | |
| result-encoding: string | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Cache node_modules | |
| uses: actions/cache@v4 | |
| with: | |
| path: node_modules | |
| key: ${{ runner.os }}-build-${{ hashFiles('**/package.json', '**/yarn.lock') }} | |
| restore-keys: | | |
| ${{ runner.os }}-build- | |
| ${{ runner.os }}- | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 22.x | |
| - name: Setup global dependencies | |
| run: | | |
| npm install -g yarn@1.22.22 | |
| npm install -g zx@7.2.3 | |
| - name: Install dependencies | |
| run: | | |
| yarn install --frozen-lockfile --registry="https://registry.yarnpkg.com" | |
| - name: Set package version | |
| run: | | |
| zx scripts/workflow/set-package-version.mjs | |
| env: | |
| TAG: ${{ steps.extract_tag.outputs.result }} | |
| - name: Build packages | |
| run: | | |
| yarn build:all | |
| - name: Upload build artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: build | |
| path: | | |
| packages/*/dist/** | |
| packages/*/es/** | |
| packages/*/package.json | |
| package.json | |
| retention-days: 7 | |
| release_npm: | |
| permissions: | |
| id-token: write | |
| needs: [build] | |
| environment: release | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout tag | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.ref }} | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 22.x | |
| registry-url: 'https://registry.npmjs.org' | |
| token: ${{ secrets.NPM_TOKEN }} | |
| - name: Download build artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: build | |
| - name: Publish to npm | |
| run: | | |
| zx scripts/workflow/npm-publish.mjs | |
| env: | |
| NPM_CONFIG_PROVENANCE: true | |
| create_release_pr: | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| needs: [build, release_npm] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout main branch | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: main | |
| fetch-depth: 0 | |
| - name: Setup Git | |
| run: | | |
| git config --global user.name "${{ github.actor }}" | |
| git config --global user.email "${{ github.actor }}@users.noreply.github.com" | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 22.x | |
| - name: Setup global dependencies | |
| run: | | |
| npm install -g yarn@1.22.22 | |
| npm install -g zx@7.2.3 | |
| - name: Install dependencies | |
| run: | | |
| yarn install --frozen-lockfile --registry="https://registry.yarnpkg.com" | |
| - name: Apply version changes | |
| run: | | |
| zx scripts/workflow/set-package-version.mjs | |
| env: | |
| TAG: ${{ needs.build.outputs.tag }} | |
| - name: Commit and push to release branch | |
| uses: EndBug/add-and-commit@v9 | |
| with: | |
| add: "." | |
| default_author: github_actor | |
| fetch: true | |
| new_branch: release | |
| push: '--set-upstream origin release --force' | |
| message: 'chore(release): update version to ${{ needs.build.outputs.tag }}' | |
| - name: Create or update PR | |
| uses: actions/github-script@v7 | |
| env: | |
| RELEASED_VERSION: ${{ needs.build.outputs.tag }} | |
| with: | |
| script: | | |
| const owner = context.repo.owner; | |
| const repo = context.repo.repo; | |
| const base = "main"; | |
| const head = "release"; | |
| const title = `chore(release): version ${process.env.RELEASED_VERSION}`; | |
| const body = `## 🚀 Release ${process.env.RELEASED_VERSION} | |
| This PR was automatically created by the release workflow. | |
| ### Changes | |
| - Updated package versions to ${process.env.RELEASED_VERSION} | |
| - Published packages to npm registry | |
| ### NPM Packages | |
| https://www.npmjs.com/search?q=%40xgplayer | |
| --- | |
| *Auto-generated by GitHub Actions*`; | |
| try { | |
| // Check if PR already exists | |
| const { data: pulls } = await github.rest.pulls.list({ | |
| owner, | |
| repo, | |
| state: 'open', | |
| head: `${owner}:${head}`, | |
| base | |
| }); | |
| if (pulls.length > 0) { | |
| // Update existing PR | |
| const pullNumber = pulls[0].number; | |
| await github.rest.pulls.update({ | |
| owner, | |
| repo, | |
| pull_number: pullNumber, | |
| title, | |
| body | |
| }); | |
| console.log(`✅ Updated existing PR #${pullNumber}`); | |
| core.summary | |
| .addHeading('✅ PR Updated') | |
| .addLink(`PR #${pullNumber}`, `https://github.com/${owner}/${repo}/pull/${pullNumber}`) | |
| .write(); | |
| } else { | |
| // Create new PR | |
| const { data: pr } = await github.rest.pulls.create({ | |
| owner, | |
| repo, | |
| base, | |
| head, | |
| title, | |
| body | |
| }); | |
| console.log(`✅ Created new PR #${pr.number}`); | |
| core.summary | |
| .addHeading('✅ PR Created') | |
| .addLink(`PR #${pr.number}`, pr.html_url) | |
| .write(); | |
| } | |
| } catch (error) { | |
| console.error('❌ Error creating/updating PR:', error.message); | |
| core.summary | |
| .addHeading('⚠️ PR Creation Failed') | |
| .addRaw(`Error: ${error.message}`) | |
| .write(); | |
| // Don't fail the workflow if PR creation fails | |
| } | |
| release_summary: | |
| needs: [build, release_npm, create_release_pr] | |
| runs-on: ubuntu-latest | |
| if: always() | |
| steps: | |
| - name: Generate release summary | |
| run: | | |
| VERSION="${{ needs.build.outputs.tag }}" | |
| BUILD_STATUS="${{ needs.build.result }}" | |
| RELEASE_STATUS="${{ needs.release_npm.result }}" | |
| PR_STATUS="${{ needs.create_release_pr.result }}" | |
| BUILD_BADGE=$([ "$BUILD_STATUS" = "success" ] && echo "✅" || echo "❌") | |
| RELEASE_BADGE=$([ "$RELEASE_STATUS" = "success" ] && echo "✅" || echo "❌") | |
| PR_BADGE=$([ "$PR_STATUS" = "success" ] && echo "✅" || echo "❌") | |
| { | |
| echo "# 🎉 Release Summary" | |
| echo "" | |
| echo "## Version Information" | |
| echo "| Field | Value |" | |
| echo "|-------|-------|" | |
| echo "| Version | \`$VERSION\` |" | |
| echo "| Tag | \`${{ github.ref }}\` |" | |
| echo "| Commit | [\`${{ github.sha }}\`](https://github.com/${{ github.repository }}/commit/${{ github.sha }}) |" | |
| echo "" | |
| echo "## Workflow Status" | |
| echo "| Step | Status |" | |
| echo "|------|--------|" | |
| echo "| Build | $BUILD_BADGE $BUILD_STATUS |" | |
| echo "| NPM Release | $RELEASE_BADGE $RELEASE_STATUS |" | |
| echo "| PR Creation | $PR_BADGE $PR_STATUS |" | |
| echo "" | |
| echo "## Links" | |
| echo "- 📦 [View on NPM](https://www.npmjs.com/search?q=%40xgplayer)" | |
| echo "- 🔗 [Workflow Run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})" | |
| echo "" | |
| echo "*Auto-generated by GitHub Actions*" | |
| } >> $GITHUB_STEP_SUMMARY | |