From 0125afcbe8a9dfba872272b12ff2bec5f24ff49e Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 23 Jun 2021 16:25:34 -0700 Subject: [PATCH] Meta: migrate from travis-ci to Github Actions (#2260) --- .github/workflows/build.yml | 17 ++++++++ .github/workflows/deploy.yml | 21 ++++++++++ .github/workflows/preview-build.yml | 26 ++++++++++++ .github/workflows/preview.yml | 51 +++++++++++++++++++++++ .github/workflows/require-allow-edits.yml | 2 - .travis.yml | 31 -------------- scripts/publish-preview.js | 20 +++++---- 7 files changed, 128 insertions(+), 40 deletions(-) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/deploy.yml create mode 100644 .github/workflows/preview-build.yml create mode 100644 .github/workflows/preview.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000000..756d6cdd738 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,17 @@ +name: 'ecma-262' + +on: [pull_request, push] + +jobs: + build: + name: 'build & lint ecmarkup' + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - uses: ljharb/actions/node/install@56f291b2a0d9e3bce72634356ae949b1e054b9f8 + name: 'nvm install lts/* && npm ci' + with: + node-version: lts/* + use-npm-ci: true + - run: npm run build-master diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 00000000000..0e931641548 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,21 @@ +name: 'ecma-262' + +on: + push: + branches: + - master + +jobs: + deploy: + name: 'deploy github pages' + runs-on: ubuntu-latest + if: ${{ github.repository == 'tc39/ecma262' }} + + steps: + - uses: actions/checkout@v2 + - uses: ljharb/actions/node/install@56f291b2a0d9e3bce72634356ae949b1e054b9f8 + name: 'nvm install lts/* && npm ci' + with: + node-version: lts/* + use-npm-ci: true + - run: npm run build-only ./scripts/auto-deploy.sh diff --git a/.github/workflows/preview-build.yml b/.github/workflows/preview-build.yml new file mode 100644 index 00000000000..12ae549fa4b --- /dev/null +++ b/.github/workflows/preview-build.yml @@ -0,0 +1,26 @@ +name: Build Preview + +on: + pull_request: + +jobs: + build: + name: 'build PR preview' + runs-on: ubuntu-latest + outputs: + sha: ${{ github.event.pull_request.head.sha }} + pr: ${{ github.event.number }} + + steps: + - uses: actions/checkout@v2 + - uses: ljharb/actions/node/install@56f291b2a0d9e3bce72634356ae949b1e054b9f8 + name: 'nvm install lts/* && npm ci' + with: + node-version: lts/* + use-npm-ci: true + - run: npm run build-only + - run: node scripts/insert_snapshot_warning + - uses: actions/upload-artifact@v2 + with: + name: out + path: out/ \ No newline at end of file diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml new file mode 100644 index 00000000000..06b1d24060d --- /dev/null +++ b/.github/workflows/preview.yml @@ -0,0 +1,51 @@ +name: Upload Preview + +on: + workflow_run: + workflows: ["Build Preview"] + types: + - completed + +jobs: + upload: + name: 'upload PR preview' + runs-on: ubuntu-latest + if: > + ${{ + github.event.workflow_run.event == 'pull_request' && + github.event.workflow_run.conclusion == 'success' && + github.repository == 'tc39/ecma262' + }} + + steps: + - uses: actions/checkout@v2 + - uses: ljharb/actions/node/install@56f291b2a0d9e3bce72634356ae949b1e054b9f8 + name: 'nvm install lts/* && npm ci' + with: + node-version: lts/* + use-npm-ci: true + - name: 'Download artifact' + uses: actions/github-script@v3.1.0 + 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.filter((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 + - run: node scripts/publish-preview + env: + CI_PREVIEW_TOKEN: ${{ secrets.CI_PREVIEW_TOKEN }} + PULL_REQUEST: ${{ github.event.workflow_run.pull_requests['0'].number }} + GITHUB_HEAD_SHA: ${{ github.event.workflow_run.head_commit.id }} diff --git a/.github/workflows/require-allow-edits.yml b/.github/workflows/require-allow-edits.yml index 31a3d24efb4..9021ca22efb 100644 --- a/.github/workflows/require-allow-edits.yml +++ b/.github/workflows/require-allow-edits.yml @@ -10,5 +10,3 @@ jobs: steps: - uses: ljharb/require-allow-edits@main - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 1dc32becb73..00000000000 --- a/.travis.yml +++ /dev/null @@ -1,31 +0,0 @@ -env: - global: - - secure: "UCSm2OZkCtH8EPSPjp8fujOyQrtHtPJi8DDdOyCSkUunSw9H+HiONwuh+J1Of77B9OUC1HTWE51tW75nsnaQik4GihXB+eah7ow3RLM14LoLoUz+PA84W8sDuuCbm37Kqtf4vnWKlAUhDeUZNyhGyIezdB22UaqWWir9KGdp4AE=" - -workspaces: - use: - - build - -jobs: - include: - - name: build - workspaces: - create: - name: build - paths: - - ./ - node_js: "lts/*" - env: BUILD=true - script: - - 'npm run build-master' - - 'if [ "${TRAVIS_BRANCH-}" = "master" ]; then ./scripts/auto-deploy.sh; fi;' - - name: upload - node_js: "lts/*" - env: UPLOAD=true - script: - - 'npm run build-only' - - 'node scripts/insert_snapshot_warning' - - 'node scripts/publish-preview' - if: type = pull_request AND repo = tc39/ecma262 - -language: node_js diff --git a/scripts/publish-preview.js b/scripts/publish-preview.js index 4295cad5365..212d1df8132 100755 --- a/scripts/publish-preview.js +++ b/scripts/publish-preview.js @@ -9,28 +9,33 @@ const tar = require('tar-stream'); async function go() { - const { TRAVIS_PULL_REQUEST, TRAVIS_PULL_REQUEST_SHA } = process.env; + const { + PULL_REQUEST, + GITHUB_HEAD_SHA, + GITHUB_REPOSITORY = 'tc39/ecma262', + } = process.env; - if (!TRAVIS_PULL_REQUEST) { throw new ReferenceError('Missing env var TRAVIS_PULL_REQUEST'); } - if (!TRAVIS_PULL_REQUEST_SHA) { throw new ReferenceError('Missing env var TRAVIS_PULL_REQUEST_SHA'); } + if (!PULL_REQUEST) { throw new ReferenceError('Missing env var PULL_REQUEST'); } + if (!GITHUB_HEAD_SHA) { throw new ReferenceError('Missing env var GITHUB_HEAD_SHA'); } const dir = join(__dirname, '..', 'out'); const files = glob(join(dir, '**'), { nodir: true }); if (!files.length) { throw new ReferenceError('No preview files found to publish'); } - console.log(`Publishing preview build of PR ${TRAVIS_PULL_REQUEST} (SHA ${TRAVIS_PULL_REQUEST_SHA})`); + console.log(`Publishing preview build of PR ${PULL_REQUEST} (SHA ${GITHUB_HEAD_SHA})`); const compressed = await compress(files, dir); console.log(`Packed to ${compressed.length / 1000}kB`); const data = { - pr: TRAVIS_PULL_REQUEST, - sha: TRAVIS_PULL_REQUEST_SHA, + pr: PULL_REQUEST, + sha: GITHUB_HEAD_SHA, compressed, }; - const url = 'https://ci.tc39.es/preview/tc39/ecma262'; + const [user, repo] = GITHUB_REPOSITORY.split('/'); + const url = `https://ci.tc39.es/preview/${user}/${repo}`; const payloadSize = JSON.stringify(data).length; console.log(`Payload size: ${payloadSize / 1000}kB`); @@ -38,6 +43,7 @@ async function go() { throw Error('Payloads must be under 6MB'); } + console.log(`URL posted to: ${url}`); await tiny.post({ url, data }); console.log('Sent to preview!') }