diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 854640b..0000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,15 +0,0 @@ -name: Build spec - -on: [pull_request, push] - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - uses: ljharb/actions/node/install@main - name: 'nvm install lts/* && npm install' - with: - node-version: lts/* - - run: npm run build diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml deleted file mode 100644 index 43206c8..0000000 --- a/.github/workflows/deploy.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: Deploy gh-pages - -on: - push: - branches: - - main - -jobs: - deploy: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - uses: ljharb/actions/node/install@main - name: 'nvm install lts/* && npm install' - with: - node-version: lts/* - - run: npm run build - - uses: JamesIves/github-pages-deploy-action@v4.3.3 - with: - branch: gh-pages - folder: build - clean: true diff --git a/.github/workflows/publish-main.yml b/.github/workflows/publish-main.yml new file mode 100644 index 0000000..b701bfd --- /dev/null +++ b/.github/workflows/publish-main.yml @@ -0,0 +1,23 @@ +name: Publish + +on: + push: + branches: [main] + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: '[node LTS] npm install' + uses: ljharb/actions/node/install@main + with: + node-version: lts/* + - run: npm run build + - name: Publish to gh-pages + uses: JamesIves/github-pages-deploy-action@v4.3.3 + with: + branch: gh-pages + folder: build + clean-exclude: | + pr diff --git a/.github/workflows/publish-pr.yml b/.github/workflows/publish-pr.yml new file mode 100644 index 0000000..2ea79ba --- /dev/null +++ b/.github/workflows/publish-pr.yml @@ -0,0 +1,80 @@ +name: Publish PR + +on: + workflow_run: + workflows: ['Render PR'] + types: [completed] + +jobs: + publish: + runs-on: ubuntu-latest + if: > + ${{ + !github.event.repository.fork && + github.event.workflow_run.event == 'pull_request' && + github.event.workflow_run.conclusion == 'success' + }} + steps: + - name: Print event info + uses: actions/github-script@v7 + with: + script: 'console.log(${{ toJson(github.event) }});' + - name: Download zipball + uses: actions/github-script@v7 + with: + script: | + const { owner, repo } = context.repo; + const { total_count, artifacts } = await github.actions.listWorkflowRunArtifacts({ + owner, + repo, + run_id: ${{ github.event.workflow_run.id }}, + name: 'result', + }); + if (total_count !== 1) { + const summary = artifacts?.map(artifact => { + const { name, size_in_bytes, url } = artifact; + return { name, size_in_bytes, url }; + }); + const repr = value => JSON.stringify(value); + throw Error(`Expected 1 artifact, got ${total_count} ${repr(summary ?? [])}`); + } + const artifactData = { + owner, + repo, + artifact_id: artifacts[0].id, + archive_format: 'zip', + }; + const download = await github.actions.downloadArtifact(artifactData); + const fs = require('fs'); + fs.writeFileSync('${{ github.workspace }}/result.zip', Buffer.from(download.data)); + - name: Provide result directory + run: rmdir -rf result && mkdir -p result + - run: unzip -o result.zip -d result + - run: ls result + - name: Extract PR number + id: extract-pr-number + run: | + cd result + awk -vok=1 \ + '{ print; if(!match($0, /^[1-9][0-9]*$/)) ok=0; } END { exit !(NR==1 && ok); }' \ + pr-number.txt + echo "number=$(cat pr-number.txt)" >> $GITHUB_OUTPUT + rm pr-number.txt + - name: Publish to gh-pages + uses: JamesIves/github-pages-deploy-action@v4.3.3 + with: + branch: gh-pages + folder: result + target-folder: pr/${{ steps.extract-pr-number.outputs.number }} + - name: Determine gh-pages url + id: get-pages-url + run: | + gh_pages_url="https://$(printf '%s' "$GITHUB_REPOSITORY" \ + | sed 's#/#.github.io/#; s#^tc39.github.io/#tc39.es/#')" + echo "url=$gh_pages_url" >> $GITHUB_OUTPUT + - name: Provide PR comment + uses: phulsechinmay/rewritable-pr-comment@v0.3.0 + with: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + message: | + The rendered spec for this PR is available at ${{ steps.get-pages-url.outputs.url }}. diff --git a/.github/workflows/render-pr.yml b/.github/workflows/render-pr.yml new file mode 100644 index 0000000..cfd9431 --- /dev/null +++ b/.github/workflows/render-pr.yml @@ -0,0 +1,22 @@ +name: Render PR + +on: [pull_request] + +jobs: + render: + runs-on: ubuntu-latest + if: ${{ github.event.pull_request }} + steps: + - uses: actions/checkout@v4 + - name: '[node LTS] npm install' + uses: ljharb/actions/node/install@main + with: + node-version: lts/* + - run: npm run build + - name: Save PR number + run: echo ${{ github.event.number }} > build/pr-number.txt + - uses: actions/upload-artifact@v4 + if: ${{ !github.event.repository.fork }} + with: + name: result + path: build/