diff --git a/.github/workflows/treeshake.yml b/.github/workflows/treeshake.yml new file mode 100644 index 0000000..7fe45db --- /dev/null +++ b/.github/workflows/treeshake.yml @@ -0,0 +1,80 @@ +name: Check tree-shakeability +on: [ pull_request ] +jobs: + build: + runs-on: ubuntu-latest + permissions: + pull-requests: write + concurrency: ci-treeshake-${{ github.ref }} + steps: + - uses: actions/checkout@v2 + - name: Use Node.js + uses: actions/setup-node@v1 + with: + node-version: 16 + + - name: Installing dependencies + run: npm ci + + - name: Build artifacts + run: npm run build + + - name: Run agadoo + id: agadoo + run: | + # Run Agadoo and store the output for further usage + # We store the process stdout and stderr to tmp files + STDOUT_F=$(mktemp) + STDERR_F=$(mktemp) + # Run agadoo and capture errors without breaking the workflow + $(npx agadoo 2> $STDERR_F > $STDOUT_F) && true + # Infer the result from the first word of the last line + RET="$(cat $STDERR_F | tail -1 | cut -d' ' -f 1)" + # In order to be used in GH actions `echo "::set-output` the + # multi-line output must be escaped. + STDOUT="$(cat $STDOUT_F)" + STDOUT="${STDOUT//'%'/%25}" + STDOUT="${STDOUT//$'\n'/%0A}" + STDOUT="${STDOUT//$'\r'/%0D}" + STDERR="$(cat $STDERR_F)" + STDERR="${STDERR//'%'/%25}" + STDERR="${STDERR//$'\n'/%0A}" + STDERR="${STDERR//$'\r'/%0D}" + echo "::set-output name=stdout::$STDOUT" + echo "::set-output name=stderr::$STDERR" + if [[ $RET == 'Success!' ]]; then + echo "::set-output name=status::tree-shakeable" + else + echo "::set-output name=status::not tree-shakeable" + fi + echo "$STDOUT" + echo "" + echo "$STDERR" + # Clean-up + rm $STDOUT_F + rm $STDERR_F + exit 0 + - name: comment PR + uses: unsplash/comment-on-pr@v1.3.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + msg: | + **Check tree-shakeability** for ${{ github.sha }}: ${{ steps.agadoo.outputs.status == 'tree-shakeable' && ':deciduous_tree:' || ':x:' }} ${{ steps.agadoo.outputs.status }} +
+ Agadoo stdout + ```javascript + ${{ steps.agadoo.outputs.stdout }} + ``` +
+
+ Agadoo stderr + ```javascript + ${{ steps.agadoo.outputs.stderr }} + ``` +
+ check_for_duplicate_msg: false + delete_prev_regex_msg: ^\*\*Check tree-shakeability\*\* + - name: Fail if cannot tree-shake + if: ${{ steps.agadoo.outputs.status == 'not tree-shakeable' }} + run: exit 1