From 4ca09906340a0f4456be3efbde4880d66645a367 Mon Sep 17 00:00:00 2001 From: Maxim Schram Date: Mon, 30 Oct 2023 11:03:01 -0400 Subject: [PATCH] chore: gha boiler plate. nvmrc file --- .circleci/config.yml | 681 ++++++++++++++-------------- .github/workflows/ci-cd.yml | 85 ++++ .github/workflows/daily-tx-pull.yml | 36 ++ .nvmrc | 1 + 4 files changed, 467 insertions(+), 336 deletions(-) create mode 100644 .github/workflows/ci-cd.yml create mode 100644 .github/workflows/daily-tx-pull.yml create mode 100644 .nvmrc diff --git a/.circleci/config.yml b/.circleci/config.yml index a033f943d76..202d87860b7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,347 +1,356 @@ version: 2.1 orbs: - browser-tools: circleci/browser-tools@1.2.4 - commitlint: conventional-changelog/commitlint@1.0.0 - node: circleci/node@5.1.0 + browser-tools: circleci/browser-tools@1.2.4 + commitlint: conventional-changelog/commitlint@1.0.0 + node: circleci/node@5.1.0 aliases: - - &save_git_cache - save_cache: - paths: - - .git - key: v3-git-{{ .Revision }} - - &restore_git_cache - restore_cache: - keys: - - v3-git-{{ .Revision }} - - v3-git- - - &save_build_cache - save_cache: - paths: - - build - key: v3-build-{{ .Revision }} - - &restore_build_cache - restore_cache: - keys: - - v3-build-{{ .Revision }} - - &save_dist_cache - save_cache: - paths: - - dist - key: v3-dist-{{ .Revision }} - - &restore_dist_cache - restore_cache: - keys: - - v3-dist-{{ .Revision }} - - &save_npm_cache - save_cache: - paths: - - node_modules - - src/generated - - static/microbit - key: v4-npm-{{ checksum "package-lock.json" }} - - &restore_npm_cache - restore_cache: - keys: - - v4-npm-{{ checksum "package-lock.json" }} - - v4-npm- - - &defaults - docker: - # TODO: fix scratch-audio and change this to `cimg/node:lts-browsers` - - image: cimg/node:14.21-browsers - auth: - username: $DOCKERHUB_USERNAME - password: $DOCKERHUB_PASSWORD - executor: node/default - working_directory: ~/repo + - &save_git_cache + save_cache: + paths: + - .git + key: v3-git-{{ .Revision }} + - &restore_git_cache + restore_cache: + keys: + - v3-git-{{ .Revision }} + - v3-git- + - &save_build_cache + save_cache: + paths: + - build + key: v3-build-{{ .Revision }} + - &restore_build_cache + restore_cache: + keys: + - v3-build-{{ .Revision }} + - &save_dist_cache + save_cache: + paths: + - dist + key: v3-dist-{{ .Revision }} + - &restore_dist_cache + restore_cache: + keys: + - v3-dist-{{ .Revision }} + - &save_npm_cache + save_cache: + paths: + - node_modules + - src/generated + - static/microbit + key: v4-npm-{{ checksum "package-lock.json" }} + - &restore_npm_cache + restore_cache: + keys: + - v4-npm-{{ checksum "package-lock.json" }} + - v4-npm- + - &defaults + docker: + # TODO: fix scratch-audio and change this to `cimg/node:lts-browsers` + - image: cimg/node:14.21-browsers + auth: + username: $DOCKERHUB_USERNAME + password: $DOCKERHUB_PASSWORD + executor: node/default + working_directory: ~/repo jobs: - build-test-no-cache: - <<: *defaults - environment: - DETECT_CHROMEDRIVER_VERSION: "true" - JEST_JUNIT_OUTPUT_DIR: test-results - NODE_OPTIONS: --max-old-space-size=4000 - steps: - - *restore_git_cache - - checkout - - browser-tools/install-chrome # must be before node/install-packages - - node/install-packages - - run: - name: Lint - command: npm run test:lint -- --quiet --output-file test-results/eslint-results.xml --format junit - - run: - name: Unit - environment: - JEST_JUNIT_OUTPUT_NAME: unit-results.xml - command: npm run test:unit -- --reporters="default" --reporters="jest-junit" --coverage --coverageReporters=text --coverageReporters=lcov --maxWorkers="2" - - run: - name: Build - environment: + build-test-no-cache: + <<: *defaults + environment: + DETECT_CHROMEDRIVER_VERSION: "true" + JEST_JUNIT_OUTPUT_DIR: test-results + NODE_OPTIONS: --max-old-space-size=4000 + steps: + - *restore_git_cache + - checkout + - browser-tools/install-chrome # must be before node/install-packages + - node/install-packages + - run: + name: Lint + command: npm run test:lint -- --quiet --output-file test-results/eslint-results.xml --format junit + - run: + name: Unit + environment: + JEST_JUNIT_OUTPUT_NAME: unit-results.xml + command: npm run test:unit -- --reporters="default" --reporters="jest-junit" --coverage --coverageReporters=text --coverageReporters=lcov --maxWorkers="2" + - run: + name: Build + environment: + NODE_ENV: production + command: npm run build + - run: + name: Integration + environment: + JEST_JUNIT_OUTPUT_NAME: integration-results.xml + command: | + google-chrome --version + npx --no -- chromedriver --version + npm run test:integration -- --reporters="default" --reporters="jest-junit" + - store_artifacts: + path: coverage + - store_test_results: + path: test-results + - run: npx --no -- semantic-release --dry-run + + setup: + <<: *defaults + environment: + DETECT_CHROMEDRIVER_VERSION: "true" + steps: + - *restore_git_cache + - checkout + - browser-tools/install-chrome # must be before node/install-packages + - node/install-packages + - *save_git_cache + - *save_npm_cache + + lint: + <<: *defaults + steps: + - *restore_git_cache + - checkout + - *restore_npm_cache + - run: + name: Lint + command: npm run test:lint -- --quiet --output-file test-results/eslint/results.xml --format junit + - store_test_results: + path: test-results + + unit: + <<: *defaults + environment: + JEST_JUNIT_OUTPUT_NAME: results.xml + steps: + - *restore_git_cache + - checkout + - *restore_npm_cache + - run: + name: Unit + environment: + JEST_JUNIT_OUTPUT_DIR: test-results/unit + command: npm run test:unit -- --reporters="default" --reporters="jest-junit" --coverage --coverageReporters=text --coverageReporters=lcov --maxWorkers="2" + - store_artifacts: + path: coverage + - store_test_results: + path: test-results + + build: + <<: *defaults + environment: NODE_ENV: production - command: npm run build - - run: - name: Integration - environment: - JEST_JUNIT_OUTPUT_NAME: integration-results.xml - command: | - google-chrome --version - npx --no -- chromedriver --version - npm run test:integration -- --reporters="default" --reporters="jest-junit" - - store_artifacts: - path: coverage - - store_test_results: - path: test-results - - run: npx --no -- semantic-release --dry-run - setup: - <<: *defaults - environment: - DETECT_CHROMEDRIVER_VERSION: "true" - steps: - - *restore_git_cache - - checkout - - browser-tools/install-chrome # must be before node/install-packages - - node/install-packages - - *save_git_cache - - *save_npm_cache - lint: - <<: *defaults - steps: - - *restore_git_cache - - checkout - - *restore_npm_cache - - run: - name: Lint - command: npm run test:lint -- --quiet --output-file test-results/eslint/results.xml --format junit - - store_test_results: - path: test-results - unit: - <<: *defaults - environment: - JEST_JUNIT_OUTPUT_NAME: results.xml - steps: - - *restore_git_cache - - checkout - - *restore_npm_cache - - run: - name: Unit - environment: - JEST_JUNIT_OUTPUT_DIR: test-results/unit - command: npm run test:unit -- --reporters="default" --reporters="jest-junit" --coverage --coverageReporters=text --coverageReporters=lcov --maxWorkers="2" - - store_artifacts: - path: coverage - - store_test_results: - path: test-results - build: - <<: *defaults - environment: - NODE_ENV: production - NODE_OPTIONS: --max-old-space-size=4000 - steps: - - *restore_git_cache - - checkout - - *restore_npm_cache - - run: - name: Build - command: npm run build - - *save_build_cache - - *save_dist_cache - store_build: - <<: *defaults - steps: - - *restore_build_cache - - store_artifacts: - path: build - store_dist: - <<: *defaults - steps: - - *restore_dist_cache - - store_artifacts: - path: dist - integration: - <<: *defaults - parallelism: 2 - environment: - JEST_JUNIT_OUTPUT_NAME: results.txt - steps: - - *restore_git_cache - - checkout - - *restore_npm_cache - - *restore_build_cache - - browser-tools/install-chrome - - run: - name: Integration - environment: - JEST_JUNIT_OUTPUT_DIR: test-results/integration - command: | - google-chrome --version - npx --no -- chromedriver --version - export TESTFILES=$(circleci tests glob "test/integration/*.test.js" | circleci tests split --split-by=timings) - $(npm bin)/jest ${TESTFILES} --reporters="default" --reporters="jest-junit" --runInBand - - store_test_results: - path: test-results + NODE_OPTIONS: --max-old-space-size=4000 + steps: + - *restore_git_cache + - checkout + - *restore_npm_cache + - run: + name: Build + command: npm run build + - *save_build_cache + - *save_dist_cache + + store_build: + <<: *defaults + steps: + - *restore_build_cache + - store_artifacts: + path: build + store_dist: + <<: *defaults + steps: + - *restore_dist_cache + - store_artifacts: + path: dist - deploy-npm: - <<: *defaults - steps: - - *restore_git_cache - - checkout - - *restore_npm_cache - - *restore_dist_cache - - run: - name: adjust config for hotfix if necessary - command: | - # double brackets are important for matching the wildcard - if [[ "$CIRCLE_BRANCH" == hotfix/* ]]; then - sed -e "s|hotfix/REPLACE|${CIRCLE_BRANCH}|" --in-place release.config.js - fi - - run: npx --no -- semantic-release + integration: + <<: *defaults + parallelism: 2 + environment: + JEST_JUNIT_OUTPUT_NAME: results.txt + steps: + - *restore_git_cache + - checkout + - *restore_npm_cache + - *restore_build_cache + - browser-tools/install-chrome + - run: + name: Integration + environment: + JEST_JUNIT_OUTPUT_DIR: test-results/integration + command: | + google-chrome --version + npx --no -- chromedriver --version + export TESTFILES=$(circleci tests glob "test/integration/*.test.js" | circleci tests split --split-by=timings) + $(npm bin)/jest ${TESTFILES} --reporters="default" --reporters="jest-junit" --runInBand + - store_test_results: + path: test-results - deploy-gh-pages: - <<: *defaults - steps: - - *restore_git_cache - - checkout - - *restore_npm_cache - - *restore_build_cache - - run: | - git config --global user.email $(git log --pretty=format:"%ae" -n1) - git config --global user.name $(git log --pretty=format:"%an" -n1) - - run: npm run deploy -- -e $CIRCLE_BRANCH - push-translations: - <<: *defaults - steps: - - *restore_git_cache - - checkout - - *restore_npm_cache - - run: npm run i18n:src - - run: npm run i18n:push + deploy-npm: + <<: *defaults + steps: + - *restore_git_cache + - checkout + - *restore_npm_cache + - *restore_dist_cache + - run: + name: adjust config for hotfix if necessary + command: | + # double brackets are important for matching the wildcard + if [[ "$CIRCLE_BRANCH" == hotfix/* ]]; then + sed -e "s|hotfix/REPLACE|${CIRCLE_BRANCH}|" --in-place release.config.js + fi + - run: npx --no -- semantic-release + + deploy-gh-pages: + <<: *defaults + steps: + - *restore_git_cache + - checkout + - *restore_npm_cache + - *restore_build_cache + - run: | + git config --global user.email $(git log --pretty=format:"%ae" -n1) + git config --global user.name $(git log --pretty=format:"%an" -n1) + - run: npm run deploy -- -e $CIRCLE_BRANCH + push-translations: + <<: *defaults + steps: + - *restore_git_cache + - checkout + - *restore_npm_cache + - run: npm run i18n:src + - run: npm run i18n:push workflows: - version: 2 - commitlint: - jobs: - - commitlint/lint: - target-branch: develop - filters: - branches: - ignore: - - master - - develop - - beta - - /^hotfix\/.*/ - push-translations: - triggers: - - schedule: - cron: 0 0 * * * # daily at 12 UTC, 8 ET - filters: - branches: - only: - - develop - jobs: - - setup: - context: - - dockerhub-credentials - - push-translations: - context: - - dockerhub-credentials - requires: - - setup + version: 2 + + commitlint: + jobs: + - commitlint/lint: + target-branch: develop + filters: + branches: + ignore: + - master + - develop + - beta + - /^hotfix\/.*/ + + push-translations: + triggers: + - schedule: + cron: 0 0 * * * # daily at 12 UTC, 8 ET + filters: + branches: + only: + - develop + jobs: + - setup: + context: + - dockerhub-credentials + - push-translations: + context: + - dockerhub-credentials + requires: + - setup + + # build-test-no-deploy: (ms: does nothing) + # jobs: + # - build-test-no-cache: + # context: + # - dockerhub-credentials + # filters: + # branches: + # ignore: + # - master + # - develop + # - beta + # - /^hotfix\/.*/ - build-test-no-deploy: - jobs: - - build-test-no-cache: - context: - - dockerhub-credentials - filters: - branches: - ignore: - - master - - develop - - beta - - /^hotfix\/.*/ - build-test-deploy: - jobs: - - setup: - context: - - dockerhub-credentials - filters: - branches: - only: - - master - - develop - - beta - - /^hotfix\/.*/ - - lint: - context: - - dockerhub-credentials - requires: - - setup - - unit: - context: - - dockerhub-credentials - requires: - - setup - - build: - context: - - dockerhub-credentials - requires: - - setup - - integration: - context: - - dockerhub-credentials - requires: - - build - - store_build: - context: - - dockerhub-credentials - requires: - - build - filters: - branches: - only: - - master - - develop - - beta - - /^hotfix\/.*/ - - store_dist: - context: - - dockerhub-credentials - requires: - - build - filters: - branches: - only: - - master - - develop - - beta - - /^hotfix\/.*/ - - deploy-npm: - context: - - dockerhub-credentials - - scratch-npm-creds - requires: - - lint - - unit - - integration - - build - filters: - branches: - only: - - master - - develop - - beta - - /^hotfix\/.*/ - - deploy-gh-pages: - context: - - dockerhub-credentials - requires: - - lint - - unit - - integration - - build - filters: - branches: - ignore: - - /^dependabot/.*/ - - /^renovate/.*/ - - /^pull/.*/ # don't deploy to gh pages on PRs. + build-test-deploy: + jobs: + - setup: + context: + - dockerhub-credentials + filters: + branches: + only: + - master + - develop + - beta + - /^hotfix\/.*/ + - lint: + context: + - dockerhub-credentials + requires: + - setup + - unit: + context: + - dockerhub-credentials + requires: + - setup + - build: + context: + - dockerhub-credentials + requires: + - setup + - integration: + context: + - dockerhub-credentials + requires: + - build + - store_build: + context: + - dockerhub-credentials + requires: + - build + filters: + branches: + only: + - master + - develop + - beta + - /^hotfix\/.*/ + - store_dist: + context: + - dockerhub-credentials + requires: + - build + filters: + branches: + only: + - master + - develop + - beta + - /^hotfix\/.*/ + - deploy-npm: + context: + - dockerhub-credentials + - scratch-npm-creds + requires: + - lint + - unit + - integration + - build + filters: + branches: + only: + - master + - develop + - beta + - /^hotfix\/.*/ + - deploy-gh-pages: + context: + - dockerhub-credentials + requires: + - lint + - unit + - integration + - build + filters: + branches: + ignore: + - /^dependabot/.*/ + - /^renovate/.*/ + - /^pull/.*/ # don't deploy to gh pages on PRs. diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml new file mode 100644 index 00000000000..2fddd56a6b0 --- /dev/null +++ b/.github/workflows/ci-cd.yml @@ -0,0 +1,85 @@ +name: CI/CD + +on: + workflow_dispatch: # Allows you to run this workflow manually from the Actions tab + pull_request: # Runs whenever a pull request is created or updated + push: # Runs whenever a commit is pushed to the repository + branches: [master, develop, beta, hotfix/*] + +concurrency: + group: "${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}" + cancel-in-progress: true + +permissions: + contents: write # publish a GitHub release + pages: write # deploy to GitHub Pages + issues: write # comment on released issues + pull-requests: write # comment on released pull requests + +jobs: + ci-cd: + runs-on: ubuntu-latest + env: + TRIGGER_DEPLOY: ${{ startsWith(github.ref, 'refs/heads/master') }} + steps: + - uses: actions/checkout@v4 + - uses: wagoid/commitlint-github-action@v5 + if: github.event_name == 'pull_request' + - uses: actions/setup-node@v3 + with: + cache: "npm" + node-version-file: ".nvmrc" + + - name: Info + run: | + cat <> $GITHUB_ENV + + if [[ "${GITHUB_REF##*/}" == hotfix/* ]]; then + echo "NPM_TAG=hotfix" >> $GITHUB_ENV + else + echo "NPM_TAG=latest" >> $GITHUB_ENV + fi + + - name: Build + run: | + npm run build + npm --no-git-tag-version version $RELEASE_VERSION + + - name: Semantic release (configured to run dry if branch is other than 'master') + env: + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + npx --no -- semantic-release $([[ "$TRIGGER_DEPLOY" == "false" ]] && echo "--dry-run") diff --git a/.github/workflows/daily-tx-pull.yml b/.github/workflows/daily-tx-pull.yml new file mode 100644 index 00000000000..9575ef464a9 --- /dev/null +++ b/.github/workflows/daily-tx-pull.yml @@ -0,0 +1,36 @@ +name: Daily TX Push + +on: + workflow_dispatch: # Allows you to run this workflow manually from the Actions tab + schedule: + # daily-tx-push (e.g., daily at 12 UTC, 8 ET) + - cron: "0 0 * * *" + +concurrency: + group: "${{ github.workflow }}" + cancel-in-progress: true + +permissions: + contents: write # publish a GitHub release + pages: write # deploy to GitHub Pages + issues: write # comment on released issues + pull-requests: write # comment on released pull requests + +jobs: + daily-tx-push: + runs-on: ubuntu-latest + + env: + # Organization-wide secrets + TX_TOKEN: ${{ secrets.TX_TOKEN }} + + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v3 + with: + cache: "npm" + node-version-file: ".nvmrc" + + - name: Install dependencies + run: npm ci +# todo... diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 00000000000..6f7f377bf51 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +v16