Process Draft Releases with MSIX #6
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: Process Draft Releases with MSIX | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| - cron: '0 0 * * *' | |
| jobs: | |
| get-draft-releases: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| version-list: ${{ steps.get-drafts.outputs.version-list }} | |
| version-count: ${{ steps.get-drafts.outputs.version-count }} | |
| steps: | |
| - name: Get draft releases | |
| id: get-drafts | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const { data: releases } = await github.rest.repos.listReleases({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo | |
| }); | |
| const draftReleases = releases.filter(release => release.draft); | |
| console.log(`Found ${draftReleases.length} draft releases`); | |
| if (draftReleases.length === 0) { | |
| core.setFailed('No draft releases found'); | |
| return; | |
| } | |
| // 提取所有tag_name并去掉v前缀,生成version列表,同时进行空值检测 | |
| const versions = draftReleases.map(release => { | |
| if (!release.tag_name) { | |
| console.log(`Warning: Draft release ${release.id} has empty tag_name, skipping`); | |
| return null; | |
| } | |
| const version = release.tag_name; | |
| if (!version || version.trim() === '') { | |
| console.log(`Warning: Draft release ${release.id} tag_name '${release.tag_name}' becomes empty, skipping`); | |
| return null; | |
| } | |
| // 检测版本号格式是否有效(应该包含数字和点) | |
| if (!/^[\d.]+$/.test(version)) { | |
| console.log(`Warning: Draft release ${release.id} version '${version}' has invalid format, skipping`); | |
| return null; | |
| } | |
| console.log(`Valid version found: ${version} (from tag: ${release.tag_name})`); | |
| return version; | |
| }).filter(version => version !== null); | |
| console.log('Valid draft release versions (without v prefix):', versions); | |
| console.log(`Total valid versions: ${versions.length}`); | |
| if (versions.length === 0) { | |
| core.setFailed('No valid draft releases found after filtering'); | |
| return; | |
| } | |
| core.setOutput('version-list', JSON.stringify(versions)); | |
| core.setOutput('version-count', versions.length.toString()); | |
| download-msix-matrix: | |
| needs: get-draft-releases | |
| strategy: | |
| matrix: | |
| version: ${{ fromJSON(needs.get-draft-releases.outputs.version-list) }} | |
| uses: ./.github/workflows/GetMsix.yml | |
| with: | |
| version: ${{ matrix.version }} | |
| secrets: | |
| PRODUCT_ID: ${{ secrets.PRODUCT_ID }} | |
| check-available-artifacts: | |
| needs: [get-draft-releases, download-msix-matrix] | |
| runs-on: ubuntu-latest | |
| outputs: | |
| available-versions: ${{ steps.check-artifacts.outputs.available-versions }} | |
| available-count: ${{ steps.check-artifacts.outputs.available-count }} | |
| steps: | |
| - name: Check which artifacts are available | |
| id: check-artifacts | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const allVersions = ${{ needs.get-draft-releases.outputs.version-list }}; | |
| const availableVersions = []; | |
| console.log('Checking available artifacts for versions:', allVersions); | |
| try { | |
| const { data: artifacts } = await github.rest.actions.listArtifactsForRepo({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| per_page: 100 | |
| }); | |
| const currentRunArtifacts = artifacts.artifacts.filter(artifact => | |
| artifact.workflow_run && artifact.workflow_run.id === context.runId | |
| ); | |
| console.log(`Current run artifacts: ${currentRunArtifacts.map(a => a.name).join(', ')}`); | |
| for (const version of allVersions) { | |
| const artifactName = `msix-${version}`; | |
| const exists = currentRunArtifacts.some(artifact => artifact.name === artifactName); | |
| if (exists) { | |
| console.log(`✓ Artifact found for version: ${version}`); | |
| availableVersions.push(version); | |
| } else { | |
| console.log(`✗ Artifact not found for version: ${version}`); | |
| } | |
| } | |
| console.log(`Available versions with artifacts: ${availableVersions.length}/${allVersions.length}`); | |
| console.log('Available versions:', availableVersions); | |
| if (availableVersions.length === 0) { | |
| core.setFailed('No artifacts available for any version'); | |
| return; | |
| } | |
| core.setOutput('available-versions', JSON.stringify(availableVersions)); | |
| core.setOutput('available-count', availableVersions.length.toString()); | |
| } catch (error) { | |
| console.log('Error checking artifacts:', error); | |
| core.setFailed('Failed to check artifacts availability'); | |
| } | |
| release-matrix: | |
| needs: check-available-artifacts | |
| strategy: | |
| matrix: | |
| version: ${{ fromJSON(needs.check-available-artifacts.outputs.available-versions) }} | |
| uses: ./.github/workflows/release.yml | |
| with: | |
| version: ${{ matrix.version }} | |
| mode: 'publish_only' | |
| secrets: | |
| RELEASE_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} |