andresz1 / size-limit-action

Compare the real cost to run your JS app or lib to keep good performance in every pull request
ISC License
451 stars 84 forks source link

Action step is run twice #49

Closed Rolandisimo closed 2 years ago

Rolandisimo commented 3 years ago

The action runs correctly for my feature branch but then checks out to master and runs the action again which is not what I want (also master does not have size-limit as a dependency yet which makes the CLI run fail)

How can I ensure it runs only for the current branch?

My size-limit config looks like:

name: "size"
on:
  pull_request:
    branches:
      - master
jobs:
  size:
    runs-on: ubuntu-latest
    env:
      CI_JOB_NUMBER: 1
    steps:
      - uses: actions/checkout@v1
      - name: Setup SSH Keys and known_hosts
        env:
          SSH_AUTH_SOCK: /tmp/ssh_agent.sock
        run: |
          mkdir -p ~/.ssh
          ssh-keyscan github.com >> ~/.ssh/known_hosts
          ssh-agent -a $SSH_AUTH_SOCK > /dev/null
          ssh-add - <<< "${{ secrets.SSH_PRIVATE_KEY }}"
      - name: Clone designer
        env:
          SSH_AUTH_SOCK: /tmp/ssh_agent.sock
        run: git clone myRepo
      - name: Install designer dependencies
        env:
          SSH_AUTH_SOCK: /tmp/ssh_agent.sock
        run: |
          cd designer
          npm install
          cd ..
      - name: Measure project bundle
        uses: andresz1/size-limit-action@v1 // <--- SIZE LIMIT STEP
        env:
          SSH_AUTH_SOCK: /tmp/ssh_agent.sock
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          build_script: bundle:production

the action logs:

...
/usr/local/bin/npx size-limit --json // <---- FIRST 
[
  {
    "name": "dist/ng-app.js",
    "passed": true,
    "size": 376096,
    "running": 2.8454400000000004,
    "loading": 7.345625
  },
  {
    "name": "dist/ng-app.js",
    "passed": true,
    "size": 376096,
    "running": 2.7477199999999997,
    "loading": 7.345625
  }
]
/usr/bin/git fetch origin master --depth=1
fatal: could not read Username for 'https://github.com': No such device or address
Fetch failed The process '/usr/bin/git' failed with exit code 128
/usr/bin/git checkout -f master
Previous HEAD position was 6534981 Merge 8671d1d92d473451d0759cdaa1b4c5c9a863e70a into a43b0532aceeaa4b6f100849172263a126520e0a
Switched to a new branch 'master'
Branch 'master' set up to track remote branch 'master' from 'origin'.
/usr/local/bin/npm install
...
/usr/local/bin/npx size-limit --json  // <---- SECOND 
tmh-dev commented 3 years ago

I am having the same issue. The action first runs successfully on my feature branch but fails on the second run when master is checked out because it is missing the size-limit dependency.

faergeek commented 3 years ago

NOTE: I'm not the author, I just noticed this issue and https://github.com/andresz1/size-limit-action/issues/48 :-) And I think this should be closed.

The whole purpose of this is action is to compare sizes of bundles between pull request branch and base branch (additionally it fails if limits aren't satisfied, but that can be made easier outside of it). So it's expected for you to have size-limit installed and configured in base branch and pull request branch. Yes, you can't make a pull request where you install and configure it, because in that case base branch would not have it. Besides different places to look for configs to copy, size-limit finds plugins by looking at package.json, so to make it work in that case, this action would need to have logic for copying packages and configs here and there, so they're installed before building and checking limits. I think it just doesn't worth it.

andresz1 commented 2 years ago

Great explanation @faergeek! that's just right