diff --git a/.github/workflows/snapshot-release.yml b/.github/workflows/snapshot-release.yml index ad3968e211..34aa316aa2 100644 --- a/.github/workflows/snapshot-release.yml +++ b/.github/workflows/snapshot-release.yml @@ -12,12 +12,12 @@ defaults: env: TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} TURBO_TEAM: ${{ secrets.TURBO_TEAM }} - FORCE_COLOR: true + FORCE_COLOR: 1 jobs: snapshot-release: name: Create a snapshot release of a pull request - if: ${{ github.repository_owner == 'withastro' && github.event.issue.pull_request && startsWith(github.event.comment.body, '!preview') }} + if: ${{ github.repository_owner == 'withastro' && github.event.issue.pull_request && contains(fromJSON('["!preview", "/preview", "!snapshot", "/snapshot"]'), github.event.comment.body) }} runs-on: ubuntu-latest permissions: contents: read @@ -37,14 +37,19 @@ jobs: uses: actions/github-script@v6 with: script: | - const splitComment = context.payload.comment.body.split(' '); - splitComment.length !== 2 && (github.rest.issues.createComment({ + const { body } = context.payload.comment; + const PREVIEW_RE = /^[!\/](?:preview|snapshot)\s+(\S*)\s*$/gim; + const [_, name] = PREVIEW_RE.exec(body) ?? []; + if (name) return name; + + const error = 'Invalid command. Expected: "/preview "' + github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, - body: 'Invalid comment format. Expected: "!preview "', - }) || core.setFailed('Invalid comment format. Expected: "!preview "')); - return splitComment[1].trim(); + body: error, + }) + core.setFailed(error) result-encoding: string - name: resolve pr refs @@ -76,34 +81,78 @@ jobs: - name: Bump Package Versions id: changesets run: | - pnpm exec changeset version --snapshot ${{ steps.getSnapshotName.outputs.result }} > changesets.output.txt 2>&1 - echo ::set-output name=result::`cat changesets.output.txt` + pnpm exec changeset status --output status.output.json 2>&1 + pnpm exec changeset version --snapshot ${{ steps.getSnapshotName.outputs.result }} + + EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) + echo "status<<$EOF" >> $GITHUB_OUTPUT + echo "$(cat status.output.json)" >> $GITHUB_OUTPUT + echo "$EOF" >> $GITHUB_OUTPUT env: # Needs access to run the script GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # Disable color + FORCE_COLOR: 0 + NO_COLOR: 1 - name: Publish Release id: publish run: | - pnpm run release --tag next--${{ steps.getSnapshotName.outputs.result }} > publish.output.txt 2>&1 - echo "Release complete" + GITHUB_ACTIONS=0 pnpm run build > build.output.txt 2>&1 + pnpm exec changeset publish --tag experimental--${{ steps.getSnapshotName.outputs.result }} > publish.output.txt 2>&1 + + EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) + + echo "build<<$EOF" >> $GITHUB_OUTPUT + echo "$(cat build.output.txt)" >> $GITHUB_OUTPUT + echo "$EOF" >> $GITHUB_OUTPUT + cat build.output.txt + + echo "publish<<$EOF" >> $GITHUB_OUTPUT + echo "$(cat publish.output.txt)" >> $GITHUB_OUTPUT + echo "$EOF" >> $GITHUB_OUTPUT cat publish.output.txt - echo ::set-output name=result::`cat publish.output.txt` env: # Needs access to publish to npm NPM_TOKEN: ${{ secrets.NPM_TOKEN }} NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + # Disable color + FORCE_COLOR: 0 + NO_COLOR: 1 - name: Pull Request Notification uses: actions/github-script@v6 env: - MESSAGE: ${{ steps.publish.outputs.result }} + TAG: ${{ steps.getSnapshotName.outputs.result }} + STATUS_DATA: ${{ steps.changesets.outputs.status }} + BUILD_LOG: ${{ steps.publish.outputs.build }} + PUBLISH_LOG: ${{ steps.publish.outputs.publish }} with: script: | - console.log(process.env.MESSAGE); + let changeset = { releases: [] }; + try { + changeset = JSON.parse(process.env.STATUS_DATA); + } catch (e) {} + let message = 'Snapshots have been released for the following packages:' + for (const release of changeset.releases) { + if (release.type === 'none') continue; + message += `\n- \`${release.name}@experimental--${process.env.TAG}\``; + } + + function details(title, body) { + message += '\n'; + message += `
${title}` + message += '\n\n```\n'; + message += body; + message += '\n```\n\n
'; + } + + details('Publish Log', process.env.PUBLISH_LOG); + details('Build Log', process.env.BUILD_LOG); + github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, - body: '```\n' + process.env.MESSAGE + '\n```', + body: message, })