From cda6cbe2ca1292c8e68677a6b6ac34e5a8b4faa0 Mon Sep 17 00:00:00 2001 From: Gabby Getz Date: Tue, 19 Sep 2023 16:04:38 -0400 Subject: [PATCH] Migrate from Travis CI to GitHub actions --- .github/actions/verify-package/action.yml | 7 ++ .github/actions/verify-package/script.sh | 20 ++++ .github/workflows/dev.yml | 118 ++++++++++++++++++++++ .github/workflows/main.yml | 46 +++++++++ .github/workflows/prod.yml | 54 ++++++++++ .travis.yml | 42 -------- gulpfile.js | 44 +++----- travis/coverage.sh | 12 --- travis/deploy.sh | 13 --- travis/prepare.sh | 5 - travis/release.sh | 23 ----- travis/test-release.sh | 6 -- travis/verify.sh | 12 --- 13 files changed, 259 insertions(+), 143 deletions(-) create mode 100644 .github/actions/verify-package/action.yml create mode 100755 .github/actions/verify-package/script.sh create mode 100644 .github/workflows/dev.yml create mode 100644 .github/workflows/main.yml create mode 100644 .github/workflows/prod.yml delete mode 100644 .travis.yml delete mode 100755 travis/coverage.sh delete mode 100755 travis/deploy.sh delete mode 100755 travis/prepare.sh delete mode 100755 travis/release.sh delete mode 100755 travis/test-release.sh delete mode 100755 travis/verify.sh diff --git a/.github/actions/verify-package/action.yml b/.github/actions/verify-package/action.yml new file mode 100644 index 000000000000..73d4dc581570 --- /dev/null +++ b/.github/actions/verify-package/action.yml @@ -0,0 +1,7 @@ +name: verify node package +description: verifies Node.js use of the npm package +runs: + using: "composite" + steps: + - run: $GITHUB_ACTION_PATH/script.sh + shell: bash diff --git a/.github/actions/verify-package/script.sh b/.github/actions/verify-package/script.sh new file mode 100755 index 000000000000..9b41a953e3ce --- /dev/null +++ b/.github/actions/verify-package/script.sh @@ -0,0 +1,20 @@ +#!/bin/bash +set -ev + +node -e "const Cesium = require('./');" +NODE_ENV=development node Specs/test.cjs +NODE_ENV=production node Specs/test.cjs +node Specs/test.mjs + +node packages/engine/Specs/test.mjs +node packages/widgets/Specs/test.mjs + +mkdir ../test +cp cesium-*.tgz ../test +cp Specs/test.*js ../test +cd ../test + +npm install cesium-*.tgz +NODE_ENV=development node test.cjs +NODE_ENV=production node test.cjs +node test.mjs \ No newline at end of file diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml new file mode 100644 index 000000000000..edf16fd312b4 --- /dev/null +++ b/.github/workflows/dev.yml @@ -0,0 +1,118 @@ +run-name: dev +on: + push: + branches-ignore: + - 'cesium.com' +concurrency: + group: ${{ github.ref }} + cancel-in-progress: true +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: install node 18 + uses: actions/setup-node@v3 + with: + node-version: '18' + - name: npm install + run: npm install + - name: lint *.js + run: npm run eslint + - name: lint *.md + run: npm run markdownlint + - name: format code + run: npm run prettier-check + coverage: + runs-on: ubuntu-latest + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_REGION: us-east-1 + BRANCH: ${{ github.ref_name }} + steps: + - uses: actions/checkout@v3 + - name: install node 18 + uses: actions/setup-node@v3 + with: + node-version: '18' + - name: npm install + run: npm install + - name: build + run: npm run build + - name: coverage (firefox) + run: npm run coverage -- --browsers FirefoxHeadless --webgl-stub --failTaskOnError --suppressPassed + - name: upload coverage artifacts + if: ${{ env.AWS_ACCESS_KEY_ID != '' }} + run: aws s3 sync ./Build/Coverage s3://cesium-dev/cesium/$BRANCH/Build/Coverage --delete --color on + release-tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: install node 18 + uses: actions/setup-node@v3 + with: + node-version: '18' + - name: npm install + run: npm install + - name: release build + run: npm run build-release + - name: release tests (chrome) + run: npm run test -- --browsers ChromeCI --failTaskOnError --webgl-stub --release --suppressPassed + - name: cloc + run: npm run cloc + deploy: + runs-on: ubuntu-latest + permissions: + statuses: write + env: + BUILD_VERSION: ${{ github.ref_name }}.${{ github.run_number }} + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_REGION: us-east-1 + BRANCH: ${{ github.ref_name }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_REPO: ${{ github.repository }} + GITHUB_SHA: ${{ github.sha }} + steps: + - uses: actions/checkout@v3 + - name: install node 18 + uses: actions/setup-node@v3 + with: + node-version: '18' + - name: npm install + run: npm install + - name: set the version in package.json + run: npm run deploy-set-version -- --buildVersion $BUILD_VERSION + - name: create release zip + run: npm run make-zip + - name: package "cesium" module + run: npm pack &> /dev/null + - name: package "@cesium/" modules + run: npm pack --workspaces &> /dev/null + - name: build apps + run: npm run build-apps + - uses: ./.github/actions/verify-package + - name: deploy to s3 + if: ${{ env.AWS_ACCESS_KEY_ID != '' }} + run: npm run deploy-s3 -- -b "cesium-dev" -d cesium/$BRANCH -c 'no-cache' --confirm + - name: set status + if: ${{ env.AWS_ACCESS_KEY_ID != '' }} + run: npm run deploy-status -- --status success --message Deployed + node-16: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: install node 16 + uses: actions/setup-node@v3 + with: + node-version: '16' + - name: npm install + run: npm install + - name: release build + run: npm run build-release + - name: package "cesium" module + run: npm pack &> /dev/null + - name: package "@cesium/" modules + run: npm pack --workspaces &> /dev/null + - uses: ./.github/actions/verify-package diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 000000000000..608e282f2d82 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,46 @@ +run-name: main +on: + workflow_run: + workflows: [dev] + types: [completed] + branches: + - main + - 'cesium.com' +jobs: + if_error_or_failure: + runs-on: ubuntu-latest + steps: + - name: message result in slack + if: ${{ github.event.workflow_run.conclusion == 'failure' }} + id: slack + uses: slackapi/slack-github-action@v1.24.0 + env: + SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} + with: + channel-id: 'cesiumjs' + payload: | + { + "blocks": [ + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": ":gh-failed: Last commit on \"${{ github.ref_name }}\" failed" + } + }, + { + "type": "actions", + "elements": [ + { + "type": "button", + "text": { + "type": "plain_text", + "text": "See commit" + }, + "url": "${{ github.event.head_commit.url }}", + "action_id": "button_1" + } + ] + } + ] + } \ No newline at end of file diff --git a/.github/workflows/prod.yml b/.github/workflows/prod.yml new file mode 100644 index 000000000000..1db9974baf79 --- /dev/null +++ b/.github/workflows/prod.yml @@ -0,0 +1,54 @@ +run-name: prod +on: + push: + branches: + - 'cesium.com' +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: install node 18 + uses: actions/setup-node@v3 + with: + node-version: '18' + - name: npm install + run: npm install + - name: lint *.js + run: npm run eslint + - name: lint *.md + run: npm run markdownlint + - name: format code + run: npm run prettier-check + deploy: + runs-on: ubuntu-latest + permissions: + statuses: write + env: + PROD: true + BUILD_VERSION: ${{ github.ref_name }}.${{ github.run_number }} + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_REGION: us-east-1 + BRANCH: ${{ github.ref_name }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_REPO: ${{ github.repository }} + GITHUB_SHA: ${{ github.sha }} + steps: + - uses: actions/checkout@v3 + - name: install node 18 + uses: actions/setup-node@v3 + with: + node-version: '18' + - name: npm install + run: npm install + - name: build website release + run: npm run website-release + - name: build apps + run: npm run build-apps + - name: deploy to cesium.com + if: ${{ env.AWS_ACCESS_KEY_ID != '' }} + run: npm run deploy-s3 -- -b "cesium.com-next" -c 'public, max-age=1800' --confirm + - name: set status + if: ${{ env.AWS_ACCESS_KEY_ID != '' }} + run: npm run deploy-status -- --status success --message Deployed \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index bc4ad92dc4cc..000000000000 --- a/.travis.yml +++ /dev/null @@ -1,42 +0,0 @@ -language: node_js -dist: focal # Workaround for NodeJS 18 - https://travis-ci.community/t/the-command-npm-config-set-spin-false-failed-and-exited-with-1-during/12909/7 -addons: - chrome: stable - firefox: latest -notifications: - slack: - secure: JKzk2sJSbZ9h2PUVWj6KtOAdFbEEnOtv/VZy05pJ2H41xRgUHiGdtMW/vMSeq6XX3IJN8eW2zd0cJTgkFn0ioAlYvID8zRhcvkFHg60QXquoqtp5y65dxjtVz79hefxSo7FO1NhMZBQWE9Tg6R7XkoyTMth62+T9vqOgu2Hms6M= - if: (branch = main) AND (type = push) - on_success: change # default: always -jobs: - include: - - stage: - name: "Coverage" - node_js: "18" - before_script: - - curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" - - unzip awscliv2.zip - - sudo ./aws/install - script: - - ./travis/coverage.sh - - name: "Release Tests" - node_js: "18" - script: - - ./travis/test-release.sh - - ./travis/verify.sh - - npm --silent run cloc - - name: "Linting, Deployment" - node_js: "18" - script: - - ./travis/prepare.sh - - npm --silent run deploy-status -- --status pending --message 'Waiting for build' - - npm --silent run eslint - - npm --silent run markdownlint - - npm --silent run prettier-check - - ./travis/release.sh - - ./travis/deploy.sh - - name: "NodeJS 16" - node_js: "16" - script: - - npm --silent run build-release - - ./travis/verify.sh \ No newline at end of file diff --git a/gulpfile.js b/gulpfile.js index b1bec01ebe21..b8cdb59ba3f7 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -61,9 +61,9 @@ if (/\.0$/.test(version)) { } const karmaConfigFile = resolve("./Specs/karma.conf.cjs"); -const travisDeployUrl = +const devDeployUrl = "http://cesium-dev.s3-website-us-east-1.amazonaws.com/cesium/"; -const isProduction = process.env.TRAVIS_BRANCH === "cesium.com"; +const isProduction = process.env.PROD; //Gulp doesn't seem to have a way to get the currently running tasks for setting //per-task variables. We use the command line argument here to detect which task is being run. @@ -687,19 +687,7 @@ export const makeZip = gulp.series(release, async function () { ); }); -function isTravisPullRequest() { - return ( - process.env.TRAVIS_PULL_REQUEST !== undefined && - process.env.TRAVIS_PULL_REQUEST !== "false" - ); -} - export async function deployS3() { - if (isTravisPullRequest()) { - console.log("Skipping deployment for non-pull request."); - return; - } - const argv = yargs(process.argv) .usage("Usage: deploy-s3 -b [Bucket Name] -d [Upload Directory]") .options({ @@ -737,7 +725,7 @@ export async function deployS3() { const bucketName = argv.bucket; const dryRun = argv.dryRun; const cacheControl = argv.cacheControl ? argv.cacheControl : "max-age=3600"; - const skipFiles = process.env.TRAVIS_BRANCH !== "main"; // Always re-upload the file on the main branch. This will ensure the file does not get deleted after a 30-day period + const skipFiles = process.env.BRANCH !== "main"; // Always re-upload the file on the main branch. This will ensure the file does not get deleted after a 30-day period if (argv.confirm) { return deployCesium( @@ -1061,7 +1049,7 @@ async function deployCesium( async function deployCesiumRelease(bucketName, s3Client, errors) { const releaseDir = "cesiumjs/releases"; - const quiet = process.env.TRAVIS; + const quiet = process.env.CI; let release; try { @@ -1071,8 +1059,8 @@ async function deployCesiumRelease(bucketName, s3Client, errors) { { method: "GET", headers: { - Authorization: process.env.TOKEN - ? `token ${process.env.TOKEN}` + Authorization: process.env.GITHUB_TOKEN + ? `token ${process.env.GITHUB_TOKEN}` : undefined, "User-Agent": "cesium.com-build", }, @@ -1227,19 +1215,14 @@ export async function deploySetVersion() { } export async function deployStatus() { - if (isTravisPullRequest()) { - console.log("Skipping deployment status for non-pull request."); - return; - } - const status = argv.status; const message = argv.message; - const deployUrl = `${travisDeployUrl + process.env.TRAVIS_BRANCH}/`; + const deployUrl = `${devDeployUrl + process.env.BRANCH}/`; const zipUrl = `${deployUrl}Cesium-${version}.zip`; const npmUrl = `${deployUrl}cesium-${version}.tgz`; const coverageUrl = `${ - travisDeployUrl + process.env.TRAVIS_BRANCH + devDeployUrl + process.env.BRANCH }/Build/Coverage/index.html`; return Promise.all([ @@ -1252,7 +1235,7 @@ export async function deployStatus() { async function setStatus(state, targetUrl, description, context) { // skip if the environment does not have the token - if (!process.env.TOKEN) { + if (!process.env.GITHUB_TOKEN) { return; } @@ -1264,19 +1247,20 @@ async function setStatus(state, targetUrl, description, context) { }; const response = await fetch( - `https://api.github.com/repos/${process.env.TRAVIS_REPO_SLUG}/statuses/${process.env.TRAVIS_COMMIT}`, + `https://api.github.com/repos/${process.env.GITHUB_REPO}/statuses/${process.env.GITHUB_SHA}`, { method: "post", body: JSON.stringify(body), headers: { "Content-Type": "application/json", - Authorization: `token ${process.env.TOKEN}`, + Authorization: `token ${process.env.GITHUB_TOKEN}`, "User-Agent": "Cesium", }, } ); - return response.json(); + const result = await response.json(); + return result; } /** @@ -1469,7 +1453,7 @@ export async function runCoverage(options) { html += ""; writeFileSync(join(options.coverageDirectory, "index.html"), html); - if (!process.env.TRAVIS) { + if (!process.env.CI) { folders.forEach(function (dir) { open(join(options.coverageDirectory, `${dir}/index.html`)); }); diff --git a/travis/coverage.sh b/travis/coverage.sh deleted file mode 100755 index c35d714cabc6..000000000000 --- a/travis/coverage.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -set -ev -if [ $TRAVIS_BRANCH != "cesium.com" ]; then - npm --silent run build - npm --silent run coverage -- --browsers FirefoxHeadless --webgl-stub --failTaskOnError --suppressPassed - - # Exit early if AWS credentials are not defined - [ -z "${AWS_ACCESS_KEY_ID}" ] && exit 0; - - # Deploy results - aws s3 sync ./Build/Coverage s3://cesium-dev/cesium/$TRAVIS_BRANCH/Build/Coverage --delete --color on -fi diff --git a/travis/deploy.sh b/travis/deploy.sh deleted file mode 100755 index 26cab879a9f4..000000000000 --- a/travis/deploy.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -set -ev -if [ $TRAVIS_SECURE_ENV_VARS ]; then - # Files deployed to cesium.com are "production", and should be cached at edge locations for - # better performance. Otherwise, this is a development deploy and nothing should be cached - if [ $TRAVIS_BRANCH == "cesium.com" ]; then - echo "Uploading files to cesium.com..." - npm --silent run deploy-s3 -- -b "cesium.com-next" -c 'public, max-age=1800' --confirm - else - npm --silent run deploy-s3 -- -b "cesium-dev" -d cesium/$TRAVIS_BRANCH -c 'no-cache' --confirm - fi - npm --silent run deploy-status -- --status success --message Deployed -fi diff --git a/travis/prepare.sh b/travis/prepare.sh deleted file mode 100755 index 112706047ad8..000000000000 --- a/travis/prepare.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -set -ev -if [ $TRAVIS_BRANCH != "cesium.com" ]; then - npm --silent run deploy-set-version -- --buildVersion $TRAVIS_BRANCH.$TRAVIS_BUILD_NUMBER -fi diff --git a/travis/release.sh b/travis/release.sh deleted file mode 100755 index cf1578ec434e..000000000000 --- a/travis/release.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash -set -ev -if [ $TRAVIS_BRANCH == "cesium.com" ]; then - npm --silent run website-release -else - npm --silent run make-zip - npm pack &> /dev/null - npm pack --workspaces &> /dev/null -fi - -npm --silent run build-apps - -if [ $TRAVIS_BRANCH != "cesium.com" ]; then - # verify prod package - mkdir ../test - cp cesium-*.tgz ../test - cp Specs/test.*js ../test - cd ../test - npm install cesium-*.tgz - NODE_ENV=development node test.cjs - NODE_ENV=production node test.cjs - node test.mjs -fi \ No newline at end of file diff --git a/travis/test-release.sh b/travis/test-release.sh deleted file mode 100755 index 0bc016f0c51c..000000000000 --- a/travis/test-release.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -set -ev -if [ $TRAVIS_BRANCH != "cesium.com" ]; then - npm --silent run build-release - npm --silent run test -- --browsers ChromeCI --failTaskOnError --webgl-stub --release --suppressPassed -fi diff --git a/travis/verify.sh b/travis/verify.sh deleted file mode 100755 index b477afb0bc72..000000000000 --- a/travis/verify.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -set -ev -if [ $TRAVIS_BRANCH != "cesium.com" ]; then - # Various Node.js smoke-screen tests - node -e "const Cesium = require('./');" - NODE_ENV=development node Specs/test.cjs - NODE_ENV=production node Specs/test.cjs - node Specs/test.mjs - - node packages/engine/Specs/test.mjs - node packages/widgets/Specs/test.mjs -fi