diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 541b11f..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,92 +0,0 @@ -version: 2 -jobs: - build-common: &common-build - docker: - - image: node - working_directory: ~/diff2html - steps: &common-steps - - checkout - - restore_cache: - key: dependency-cache-{{ checksum "yarn.lock" }} - - run: yarn - - save_cache: - key: dependency-cache-{{ checksum "yarn.lock" }} - paths: - - ./node_modules - - run: yarn run build - - run: yarn run coverage - - build-latest: &latest-build - docker: - - image: node - working_directory: ~/diff2html - steps: - - checkout - - restore_cache: - key: dependency-cache-{{ checksum "yarn.lock" }} - - run: yarn - - save_cache: - key: dependency-cache-{{ checksum "yarn.lock" }} - paths: - - ./node_modules - - run: yarn run build - - run: yarn run lint - - run: yarn run coverage - - run: yarn run codacy - - persist_to_workspace: - root: ~/diff2html - paths: - - docs - - build - - build-node_8: - <<: *common-build - docker: - - image: node:8 - - build-node_10: - <<: *common-build - docker: - - image: node:10 - - build-node_11: - <<: *common-build - docker: - - image: node:11 - - build-node_12: - <<: *common-build - docker: - - image: node:12 - - build-node_13: - <<: *latest-build - docker: - - image: node:13 - - deploy: - machine: - enabled: true - working_directory: ~/diff2html - steps: - - attach_workspace: - at: . - - run: - name: Deploy - working_directory: ~/diff2html/docs - command: aws s3 sync . s3://diff2html.xyz --region eu-west-1 - -workflows: - version: 2 - build: - jobs: - - build-node_10 - - build-node_11 - - build-node_12 - - build-node_13 - - deploy: - requires: - - build-node_13 - filters: - branches: - only: master diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..89281cf --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,50 @@ +name: CI + +on: [push] + +jobs: + build: + runs-on: ubuntu-18.04 + env: + CI: true + strategy: + matrix: + node-version: [10.x, 11.x, 12.x, 13.x] + steps: + - uses: actions/checkout@v1 + - name: Setup Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - name: Log environment setup + run: | + node -v + yarn -v + - name: Get yarn cache + id: yarn-cache + run: echo "::set-output name=dir::$(yarn cache dir)" + - uses: actions/cache@v1 + with: + path: ${{ steps.yarn-cache.outputs.dir }} + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + - name: Install dependencies + run: yarn install + - name: Lint + run: yarn run lint + - name: Build + run: yarn run build + - name: Test + run: yarn run coverage + - name: Push coverage to Codacy + if: matrix.node-version == '13.x' + env: + CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }} + run: yarn run codacy + - name: Save coverage report + if: matrix.node-version == '13.x' + uses: actions/upload-artifact@v1 + with: + name: coverage + path: coverage diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..c8ba8dc --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,118 @@ +name: Release + +on: + push: + branches: + - master + +jobs: + version: + runs-on: ubuntu-18.04 + container: + image: codacy/git-version + steps: + - uses: actions/checkout@v1 + - name: Configure Git + run: | + git checkout -f "${GITHUB_REF#refs/heads/}" + git config user.email "$GITHUB_ACTOR@users.noreply.github.com" + git config user.name "$GITHUB_ACTOR" + - name: Get next version + run: | + # Hack: Set a unique fake name for the release branch to avoid releasing master as the new 3.x major release for now + export NEXT_VERSION="$(/bin/git-version --folder=$PWD --release-branch=FAKE-RELEASE-BRANCH-NAME)" + echo "Next version is ${NEXT_VERSION}" + echo "${NEXT_VERSION}" > version.txt + - name: Save version artifact + uses: actions/upload-artifact@v1 + with: + name: version + path: version.txt + - name: Get next npm tag name + run: | + if [ "${GITHUB_REF#refs/heads/}" = "master" ]; then + export PUBLISH_TAG="latest" + elif [ "${GITHUB_REF#refs/heads/}" = "next" ]; then + export PUBLISH_TAG="next" + else + export PUBLISH_TAG="pr" + fi + echo "Next tag is ${PUBLISH_TAG}" + echo "${PUBLISH_TAG}" > tag.txt + - name: Save npm tag name artifact + uses: actions/upload-artifact@v1 + with: + name: tag + path: tag.txt + + publish: + needs: [version, build] + runs-on: ubuntu-18.04 + env: + CI: true + steps: + - uses: actions/checkout@v1 + - name: Download version artifact + uses: actions/download-artifact@v1 + with: + name: version + - name: Download npm tag name artifact + uses: actions/download-artifact@v1 + with: + name: tag + - uses: actions/setup-node@v1 + with: + node-version: 13.x + - run: node -v + - run: yarn -v + - name: Get yarn cache + id: yarn-cache + run: echo "::set-output name=dir::$(yarn cache dir)" + - uses: actions/cache@v1 + with: + path: ${{ steps.yarn-cache.outputs.dir }} + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + - name: Configure Yarn version + run: | + yarn config set version-tag-prefix "" + yarn config set version-git-message "Release version %s" + - name: Configure Git + run: | + git switch -c ${GITHUB_REF#refs/heads/} + git config user.email "$GITHUB_ACTOR@users.noreply.github.com" + git config user.name "$GITHUB_ACTOR" + - name: Install dependencies + run: yarn install + - name: Prepare version + env: + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} + run: | + yarn version --non-interactive --new-version $(cat version/version.txt) + git push --tags "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$GITHUB_REPOSITORY" + - uses: actions/setup-node@v1 + with: + node-version: 13 + registry-url: https://registry.npmjs.org/ + - name: Publish to NPM + env: + NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} + run: | + echo "Going to publish version $(cat version/version.txt) to NPM" + yarn publish --tag $(cat tag/tag.txt) --non-interactive --new-version $(cat version/version.txt) + - uses: actions/setup-node@v1 + with: + node-version: 13 + registry-url: https://npm.pkg.github.com + scope: "@rtfpessoa" + - name: Publish to GitHub + env: + NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} + run: | + # HACK: Override npm package name to be able to publish in GitHub + (TMP_FILE=$(mktemp) && jq '.name = "@rtfpessoa/diff2html"' package.json > "${TMP_FILE}" && mv "${TMP_FILE}" package.json) + echo "Going to publish version $(cat version/version.txt) to GitHub" + yarn publish --tag $(cat tag/tag.txt) --non-interactive --new-version $(cat version/version.txt) + # HACK: Restore npm package name + (TMP_FILE=$(mktemp) && jq '.name = "diff2html"' package.json > "${TMP_FILE}" && mv "${TMP_FILE}" package.json) diff --git a/.github/workflows/website.yml b/.github/workflows/website.yml new file mode 100644 index 0000000..b950edb --- /dev/null +++ b/.github/workflows/website.yml @@ -0,0 +1,63 @@ +name: Website + +on: + push: + branches: + - master + +jobs: + build: + runs-on: ubuntu-18.04 + env: + CI: true + strategy: + matrix: + node-version: [13.x] + steps: + - uses: actions/checkout@v1 + - name: Setup Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - run: node -v + - run: yarn -v + - name: Get yarn cache + id: yarn-cache + run: echo "::set-output name=dir::$(yarn cache dir)" + - uses: actions/cache@v1 + with: + path: ${{ steps.yarn-cache.outputs.dir }} + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + - name: Install dependencies + run: yarn install + - name: Lint + run: yarn run lint + - name: Build + run: yarn run build + - name: Test + run: yarn run coverage + - name: Save website artifact + if: matrix.node-version == '13.x' + uses: actions/upload-artifact@v1 + with: + name: website + path: docs + + deploy: + needs: build + runs-on: ubuntu-18.04 + steps: + - name: Download website artifact + uses: actions/download-artifact@v1 + with: + name: website + - name: Deploy website + env: + AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }} + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + run: | + cd docs + aws s3 sync . s3://diff2html.xyz --region eu-west-1 diff --git a/README.md b/README.md index 3495330..8382fd6 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Codacy Quality Badge](https://api.codacy.com/project/badge/Grade/06412dc3f5a14f568778d0db8a1f7dc8)](https://www.codacy.com/app/rtfpessoa/diff2html?utm_source=github.com&utm_medium=referral&utm_content=rtfpessoa/diff2html&utm_campaign=Badge_Grade) [![Codacy Coverage Badge](https://api.codacy.com/project/badge/Coverage/06412dc3f5a14f568778d0db8a1f7dc8)](https://www.codacy.com/app/rtfpessoa/diff2html?utm_source=github.com&utm_medium=referral&utm_content=rtfpessoa/diff2html&utm_campaign=Badge_Coverage) -[![Circle CI](https://circleci.com/gh/rtfpessoa/diff2html.svg?style=svg)](https://circleci.com/gh/rtfpessoa/diff2html) +![GitHub CI](https://github.com/rtfpessoa/diff2html/workflows/CI/badge.svg) [![npm](https://img.shields.io/npm/v/diff2html.svg)](https://www.npmjs.com/package/diff2html) [![Dependency Status](https://david-dm.org/rtfpessoa/diff2html.svg)](https://david-dm.org/rtfpessoa/diff2html) diff --git a/package.json b/package.json index 2ca56c3..c57486c 100644 --- a/package.json +++ b/package.json @@ -49,11 +49,12 @@ "build-templates": "ts-node ./scripts/hulk.ts --wrapper ts --variable 'defaultTemplates' ./src/templates/*.mustache > ./src/diff2html-templates.ts", "build-website": "rm -rf docs; NODE_ENV=production WEBPACK_MINIMIZE=true webpack --mode production --config webpack.website.ts", "start-website": "WEBPACK_MINIFY=false NODE_ENV=dev webpack-dev-server --mode dev --config webpack.website.ts", - "preversion": "yarn run build && yarn run lint && yarn test", - "version": "git add -A package.json", - "postversion": "git push && git push --tags" + "preversion": "yarn run lint && yarn run build && yarn test", + "version": "git add -A package.json" }, "main": "./lib/diff2html.js", + "module": "./lib-esm/diff2html.js", + "types": "./lib/diff2html.d.ts", "dependencies": { "diff": "4.0.1", "hogan.js": "3.0.2"