diff --git a/README.md b/README.md index 87c5acc..d208fc4 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,13 @@ jobs: size-threshold: '50000' ``` +## Example Workflows + +See the [`recipes/`](./recipes/) directory for complete workflow examples: + +- [`basic.yml`](./recipes/basic.yml) - Basic dependency diff on pull requests +- [`bundle-diff.yml`](./recipes/bundle-diff.yml) - Advanced workflow with package bundle size analysis + ## Package Bundle Analysis In addition to analyzing dependency changes, this action can optionally compare the actual bundle sizes of your packages by examining `npm pack` outputs. This provides insights into the **bundle size** (what gets published) rather than just the **install size** (what gets installed with dependencies). @@ -73,74 +80,7 @@ The action accepts glob patterns to locate package tarballs for comparison: > [!NOTE] > Package bundle analysis only runs when both `base-packages` and `source-packages` are provided. If these inputs are not set, this feature is skipped entirely. -### Example with package analysis - -```yaml -jobs: - build-main: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - with: - ref: main # or your default branch - - name: Use Node - uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0 - with: - node-version: 24.x - - name: Install Dependencies - run: npm ci --ignore-scripts - - name: Build - run: npm run build - - name: Pack - run: npm pack - - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 - with: - name: base-packages - path: '*.tgz' - build-pr: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - - name: Use Node - uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0 - with: - node-version: 24.x - - name: Install Dependencies - run: npm ci --ignore-scripts - - name: Build - run: npm run build - - name: Pack - run: npm pack - - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 - with: - name: source-packages - path: '*.tgz' - diff_dependencies: - runs-on: ubuntu-latest - needs: [build-main, build-pr] - permissions: - pull-requests: write - steps: - - name: Checkout repository - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - with: - fetch-depth: 0 # allows the diff action to access git history - - uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0 - with: - name: base-packages - path: ./base-packages - - uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0 - with: - name: source-packages - path: ./source-packages - - name: Create Diff - uses: e18e/action-dependency-diff@v1 - with: - base-packages: ./base-packages/*.tgz - source-packages: ./source-packages/*.tgz -``` +You can see an example of how to set this up in the [bundle difference workflow](./recipes/bundle-diff.yml). ## Supported package managers diff --git a/recipes/basic.yml b/recipes/basic.yml new file mode 100644 index 0000000..61e017c --- /dev/null +++ b/recipes/basic.yml @@ -0,0 +1,17 @@ +name: Dependency Diff + +on: + pull_request: + +jobs: + diff_dependencies: + runs-on: ubuntu-latest + permissions: + pull-requests: write + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Create Diff + uses: e18e/action-dependency-diff@v1 diff --git a/recipes/bundle-diff.yml b/recipes/bundle-diff.yml new file mode 100644 index 0000000..d507ead --- /dev/null +++ b/recipes/bundle-diff.yml @@ -0,0 +1,77 @@ +name: Dependency Diff + +on: + pull_request: + +jobs: + build-main: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 + with: + ref: main # or your default branch + - name: Use Node + uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0 + with: + node-version: 24.x + + # These steps are whatever you need to build and pack your project. + # Change them as necessary. + - name: Install Dependencies + run: npm ci --ignore-scripts + - name: Build + run: npm run build + - name: Pack + run: npm pack + + - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + with: + name: base-packages + path: '*.tgz' + build-pr: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 + - name: Use Node + uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0 + with: + node-version: 24.x + + # These steps are whatever you need to build and pack your project. + # Change them as necessary. + - name: Install Dependencies + run: npm ci --ignore-scripts + - name: Build + run: npm run build + - name: Pack + run: npm pack + + - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + with: + name: source-packages + path: '*.tgz' + diff_dependencies: + runs-on: ubuntu-latest + needs: [build-main, build-pr] + permissions: + pull-requests: write + steps: + - name: Checkout repository + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 + with: + fetch-depth: 0 # allows the diff action to access git history + - uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0 + with: + name: base-packages + path: ./base-packages + - uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0 + with: + name: source-packages + path: ./source-packages + - name: Create Diff + uses: e18e/action-dependency-diff@v1 + with: + base-packages: ./base-packages/*.tgz + source-packages: ./source-packages/*.tgz