From 68ad878900ed8eb4a360ee83f1f64d97116025b8 Mon Sep 17 00:00:00 2001 From: Bronley Plumb Date: Thu, 3 Oct 2024 09:49:25 -0400 Subject: [PATCH] Add coverage & create-package scripts (#2) * Add build stuff * Add coveralls package * bump node version --- .github/workflows/build.yml | 6 +++ .github/workflows/create-package.yml | 57 ++++++++++++++++++++++++ package-lock.json | 66 ++++++++++++++++++++++++++++ package.json | 5 ++- 4 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/create-package.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8945fcc..f17a17c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,6 +10,9 @@ on: jobs: ci: runs-on: ${{ matrix.os }} + env: + #hardcode the coveralls token...it's not overly important to protect, and github actions won't allow forks to work with coveralls otherwise + COVERALLS_REPO_TOKEN: "OqDqbWVvJMoMlIhpgvFlSygtDJufce50v" strategy: matrix: os: [ubuntu-latest, macos-latest, windows-latest] @@ -18,10 +21,12 @@ jobs: - uses: actions/setup-node@master with: node-version: "16.20.2" + architecture: 'x64' # fix for macos-latest - run: npm ci - run: npm run build - run: npm run lint - run: npm run test + - run: npm run publish-coverage npm-release: #only run this task if a tag starting with 'v' was used to trigger this (i.e. a tagged release) if: startsWith(github.ref, 'refs/tags/v') @@ -34,6 +39,7 @@ jobs: - uses: actions/setup-node@master with: node-version: "16.20.2" + architecture: 'x64' # fix for macos-latest - run: echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ./.npmrc - run: npm ci - run: npm run build diff --git a/.github/workflows/create-package.yml b/.github/workflows/create-package.yml new file mode 100644 index 0000000..6efe73d --- /dev/null +++ b/.github/workflows/create-package.yml @@ -0,0 +1,57 @@ +name: create-package +on: + pull_request: + types: [labeled, unlabeled, synchronize] +jobs: + create-package: + runs-on: ubuntu-latest + if: contains(github.event.pull_request.labels.*.name, 'create-package') + env: + GH_TOKEN: ${{ github.token }} + steps: + - uses: actions/checkout@master + - uses: actions/setup-node@master + with: + node-version: "16.20.2" + # Get a bot token so the bot's name shows up on all our actions + - name: Get Token From roku-ci-token Application + uses: tibdex/github-app-token@v1 + id: generate-token + with: + app_id: ${{ secrets.BOT_APP_ID }} + private_key: ${{ secrets.BOT_PRIVATE_KEY }} + - run: echo "TOKEN=${{ steps.generate-token.outputs.token }}" >> $GITHUB_ENV + - name: Compute variables + run: | + CURRENT_VERSION=$(grep -o '\"version\": *\"[^\"]*\"' package.json | awk -F'\"' '{print $4}') + SANITIZED_BRANCH_NAME=$(echo "$GITHUB_HEAD_REF" | sed 's/[^0-9a-zA-Z-]/-/g') + BUILD_VERSION="$CURRENT_VERSION-$SANITIZED_BRANCH_NAME.$(date +%Y%m%d%H%M%S)" + NPM_PACKAGE_NAME=$(grep -o '\"name\": *\"[^\"]*\"' package.json | awk -F'\"' '{print $4}' | sed -e 's/@//g' -e 's#/#-#g') + ARTIFACT_NAME=$(echo "$NPM_PACKAGE_NAME-$BUILD_VERSION.tgz" | tr '/' '-') + ARTIFACT_URL="${{ github.server_url }}/${{ github.repository }}/releases/download/v0.0.0-packages/${ARTIFACT_NAME}" + + echo "BUILD_VERSION=$BUILD_VERSION" >> $GITHUB_ENV + echo "ARTIFACT_URL=$ARTIFACT_URL" >> $GITHUB_ENV + + - run: npm ci + - run: npm version "$BUILD_VERSION" --no-git-tag-version + - run: npm pack + + # create the release if not exist + - run: gh release create v0.0.0-packages --title "v0.0.0-packages" --latest=false --prerelease --notes "catchall release for temp packages" -R ${{ github.repository }} + continue-on-error: true + + # upload this artifact to the "packages" github release + - run: gh release upload v0.0.0-packages *.tgz -R ${{ github.repository }} + + - name: Fetch build artifact + uses: actions/github-script@v7 + with: + github-token: ${{ env.TOKEN }} + script: | + return github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: "Hey there! I just built a new temporary npm package based on ${{ github.event.pull_request.head.sha }}. You can download it [here](${{ env.ARTIFACT_URL }}) or install it by running the following command: \n```bash\nnpm install ${{ env.ARTIFACT_URL }}\n```" + }); diff --git a/package-lock.json b/package-lock.json index b5781c2..cb04fc2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,6 +18,7 @@ "@typescript-eslint/parser": "^5.27.0", "brighterscript": "^0.67.7", "chai": "^4.2.0", + "coveralls-next": "^4.2.1", "eslint": "^8.16.0", "eslint-plugin-no-only-tests": "2.6.0", "fs-extra": "^11.2.0", @@ -1782,6 +1783,26 @@ "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==", "dev": true }, + "node_modules/coveralls-next": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/coveralls-next/-/coveralls-next-4.2.1.tgz", + "integrity": "sha512-O/SBGZsCryt+6Q3NuJHENyQYaucTEV9qp0KGaed+y42PUh+GuF949LRLHKZbxWwOIc1tV8bJRIVWlfbZ8etEwQ==", + "dev": true, + "license": "BSD-2-Clause", + "dependencies": { + "form-data": "4.0.0", + "js-yaml": "4.1.0", + "lcov-parse": "1.0.0", + "log-driver": "1.2.7", + "minimist": "1.2.8" + }, + "bin": { + "coveralls": "bin/coveralls.js" + }, + "engines": { + "node": ">=16" + } + }, "node_modules/cross-platform-clear-console": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/cross-platform-clear-console/-/cross-platform-clear-console-2.3.0.tgz", @@ -2535,6 +2556,21 @@ "node": "*" } }, + "node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dev": true, + "license": "MIT", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/fromentries": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/fromentries/-/fromentries-1.3.2.tgz", @@ -3324,6 +3360,16 @@ "json-buffer": "3.0.1" } }, + "node_modules/lcov-parse": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/lcov-parse/-/lcov-parse-1.0.0.tgz", + "integrity": "sha512-aprLII/vPzuQvYZnDRU78Fns9I2Ag3gi4Ipga/hxnVMCZC8DnR2nI7XBqrPoywGfxqIx/DgarGvDJZAD3YBTgQ==", + "dev": true, + "license": "BSD-3-Clause", + "bin": { + "lcov-parse": "bin/cli.js" + } + }, "node_modules/levn": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz", @@ -3379,6 +3425,16 @@ "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==", "dev": true }, + "node_modules/log-driver": { + "version": "1.2.7", + "resolved": "https://registry.npmjs.org/log-driver/-/log-driver-1.2.7.tgz", + "integrity": "sha512-U7KCmLdqsGHBLeWqYlFA0V0Sl6P08EE1ZrmA9cxjUE0WVqT9qnyVDPz1kzpFEP0jdJuFnasWIfSd7fsaNXkpbg==", + "dev": true, + "license": "ISC", + "engines": { + "node": ">=0.8.6" + } + }, "node_modules/log-symbols": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-4.1.0.tgz", @@ -3589,6 +3645,16 @@ "node": "*" } }, + "node_modules/minimist": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", + "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/mocha": { "version": "9.2.2", "resolved": "https://registry.npmjs.org/mocha/-/mocha-9.2.2.tgz", diff --git a/package.json b/package.json index 2626534..092da6f 100644 --- a/package.json +++ b/package.json @@ -11,8 +11,10 @@ "build": "rimraf out && tsc", "lint": "eslint \"src/**\"", "preversion": "npm run build && npm run lint && npm run test", + "test:nocover": "mocha", "test": "nyc mocha", - "watch": "rimraf out && tsc --watch" + "watch": "rimraf out && tsc --watch", + "publish-coverage": "nyc report --reporter=text-lcov | coveralls" }, "author": "", "license": "MIT", @@ -29,6 +31,7 @@ "@typescript-eslint/parser": "^5.27.0", "brighterscript": "^0.67.7", "chai": "^4.2.0", + "coveralls-next": "^4.2.1", "eslint": "^8.16.0", "eslint-plugin-no-only-tests": "2.6.0", "fs-extra": "^11.2.0",