diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ff90dd03..cfa159a9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -40,10 +40,10 @@ jobs: 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 + - run: cd bsc-plugin && npm ci + - run: cd bsc-plugin && npm run build #create npm package - - run: npm pack + - run: cd bsc-plugin && npm pack #create GitHub release - name: Create GitHub Release @@ -63,9 +63,10 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - asset_paths: '["./*.tgz"]' + asset_paths: '["./bsc-plugin/*.tgz"]' #If there's a dash followed by an alpha character, this is a prerelease and should be tagged "next". Otherwise tag as "latest" - run: if [[ "${{ github.ref }}" =~ -[a-zA-Z] ]]; then echo "DIST_TAG=next" >> $GITHUB_ENV; else echo "DIST_TAG=latest" >> $GITHUB_ENV; fi + #upload to npm - - run: npm publish --tag ${{env.DIST_TAG}} + - run: cd bsc-plugin && npm publish --tag ${{env.DIST_TAG}} diff --git a/.github/workflows/create-package.yml b/.github/workflows/create-package.yml new file mode 100644 index 00000000..2de14e54 --- /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: cd bsc-plugin && npm ci + - run: cd bsc-plugin && npm version "$BUILD_VERSION" --no-git-tag-version + - run: cd bsc-plugin && npm pack + + # create the release if not exist + - run: cd bsc-plugin && 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: cd bsc-plugin && 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/bsc-plugin/package.json b/bsc-plugin/package.json index e739d09d..a6206ce9 100644 --- a/bsc-plugin/package.json +++ b/bsc-plugin/package.json @@ -2,6 +2,21 @@ "name": "rooibos-roku", "version": "5.12.0", "description": "simple, flexible, fun brightscript test framework for roku scenegraph apps - roku brighterscript plugin", + "scripts": { + "preversion": "npm run build && npm run lint && npm run test", + "clean": "rm -rf ./dist && mkdir dist", + "compile": "npm run clean && tsc -p .", + "prepublishOnly": "npm run build", + "lint": "eslint \"src/**\"", + "build": "npm run compile && cp -r ../framework/src/source ./dist/lib/framework", + "test": "nyc mocha", + "test:nocover": "mocha", + "publish-coverage": "nyc report --reporter=text-lcov | coveralls", + "publish-npm": "npm run test && npm publish", + "publish-npm:beta": "npm run test && npm publish --tag=beta", + "local": "ts-node scripts/install-local.js", + "remote": "ts-node scripts/install-npm.js" + }, "repository": { "type": "git", "url": "/~https://github.com/rokucommunity/rooibos.git" @@ -44,21 +59,6 @@ "ts-node": "^9.0.0", "typescript": "^4.9.5" }, - "scripts": { - "preversion": "npm run build && npm run lint && npm run test", - "clean": "rm -rf ./dist && mkdir dist", - "compile": "npm run clean && tsc -p .", - "prepublishOnly": "npm run build", - "lint": "eslint \"src/**\"", - "build": "npm run compile && cp -r ../framework/src/source ./dist/lib/framework", - "test": "nyc mocha", - "test:nocover": "mocha", - "publish-coverage": "nyc report --reporter=text-lcov | coveralls", - "publish-npm": "npm run test && npm publish", - "publish-npm:beta": "npm run test && npm publish --tag=beta", - "local": "ts-node scripts/install-local.js", - "remote": "ts-node scripts/install-npm.js" - }, "preferGlobal": true, "keywords": [ "brightscript", diff --git a/package.json b/package.json index c6cb9ae5..0846feab 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,10 @@ "name": "rooibos", "version": "1.0.0", "description": "simple, flexible, fun brightscript test framework for roku scenegraph apps", + "scripts": { + "build": "npx bsc", + "test": "npx bsc --project ./bsconfig-tests.json" + }, "files": [ "dist/**/!(manifest)*" ], @@ -31,9 +35,5 @@ "rootDir": "src", "packageRootDir": "dist" }, - "homepage": "/~https://github.com/rokucommunity/rooibos#readme", - "scripts": { - "build": "npx bsc", - "test": "npx bsc --project ./bsconfig-tests.json" - } + "homepage": "/~https://github.com/rokucommunity/rooibos#readme" }