Upload Preview #2949
This file contains 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: Upload Preview | |
on: | |
workflow_run: | |
workflows: ["Build Preview"] | |
types: | |
- completed | |
jobs: | |
upload: | |
name: 'upload PR preview' | |
runs-on: ubuntu-22.04 | |
if: > | |
${{ | |
github.event.workflow_run.event == 'pull_request' && | |
github.event.workflow_run.conclusion == 'success' && | |
github.repository == 'tc39/ecma262' | |
}} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: ljharb/actions/node/install@dfd9796898850cf07630d1bd4053a7c9a379e90f | |
name: 'nvm install lts/* && npm ci --no-audit' | |
env: | |
NPM_CONFIG_AUDIT: false | |
with: | |
node-version: lts/* | |
use-npm-ci: true | |
- name: 'Download artifact' | |
uses: actions/[email protected] | |
with: | |
script: | | |
const { owner, repo } = context.repo; | |
const artifacts = await github.actions.listWorkflowRunArtifacts({ | |
owner, | |
repo, | |
run_id: ${{ github.event.workflow_run.id }}, | |
}); | |
const { id: artifact_id } = artifacts.data.artifacts.find((artifact) => artifact.name == 'out'); | |
const download = await github.actions.downloadArtifact({ | |
owner, | |
repo, | |
artifact_id, | |
archive_format: 'zip', | |
}); | |
const fs = require('fs'); | |
fs.writeFileSync('${{ github.workspace }}/out.zip', Buffer.from(download.data)); | |
- run: unzip -o out.zip -d out | |
- name: 'debug info' | |
uses: actions/[email protected] | |
with: | |
script: | | |
console.log(${{ toJson(github.event) }}); | |
- run: head -n1 out/pr.txt | grep -e '^[1-9][0-9]*$' | |
name: 'validate PR number from archive' | |
- run: echo "PULL_REQUEST=$(head -n1 out/pr.txt)" >> $GITHUB_ENV | |
- run: rm out/pr.txt && echo $PULL_REQUEST | |
- run: node scripts/publish-preview | |
env: | |
CI_PREVIEW_TOKEN: ${{ secrets.CI_PREVIEW_TOKEN }} | |
GITHUB_HEAD_SHA: ${{ github.event.workflow_run.head_commit.id }} |