dorny / paths-filter

Conditionally run actions based on files modified by PR, feature branch or pushed commits
MIT License
2.14k stars 239 forks source link

Where is the wrong in my yaml file? Main feature is not working properly. #169

Closed ffcabbar closed 1 year ago

ffcabbar commented 1 year ago

If I change in foo2 folder or foo folder, it triggers all steps and does not skip any steps. Some should be skipped some steps when I change something in just one of them.

My File directory is like this:

name: Upload to S3

on:
  push:
    branches:
      - test-s3
    paths:
      - "foo/js/bc-global.js"
      - "foo/js/scripts/**.js"
      - "foo2/js/lc-global.js"
      - "foo2/js/scripts/**.js"

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@master
      - uses: actions/checkout@v2
      - uses: dorny/paths-filter@v2
        id: changes
        with:
          filters: |
            foo:
              - 'foo/js/bc-global.js'
              - 'foo/js/scripts/**.js'
            foo2:
              - 'foo2/js/lc-global.js'
              - 'foo2/js/scripts/**.js'

      - name: Install node
        uses: actions/setup-node@v3
        with:
          node-version: 16.13.0
          registry-url: "https://registry.npmjs.org"

      - name: Install uglify-js
        run: npm install uglify-js -g

      # minify files for each project
      - name: minify script files for foo
        if: steps.changes.outputs.foo == 'true'
        run: uglifyjs foo/js/scripts/**.js -o foo/js/live/scripts-bundle.js
      - name: minify global file for foo
        if: steps.changes.outputs.foo == 'true'
        run: uglifyjs foo/js/bc-global.js -o foo/js/live/global-bundle.js

      - name: minify script files for foo2
        if: steps.changes.outputs.foo2 == 'true'
        run: uglifyjs foo2/js/scripts/**.js -o foo2/js/live/scripts-bundle.js
      - name: minify global file for foo2
        if: steps.changes.outputs.foo2 == 'true'
        run: uglifyjs foo2/js/lc-global.js -o foo2/js/live/global-bundle.js

      # Auto committing
      - name: Auto committing minified files
        uses: stefanzweifel/git-auto-commit-action@v4
        with:
          file_pattern: "*.js"
          commit_message: "Github Action: Auto Minified JS files"
          branch: ${{ github.ref }}

      # Deploy for foo
      - name: Deploy to S3 for foo
        if: steps.changes.outputs.foo == 'true'
        uses: jakejarvis/s3-sync-action@master
        with:
          args: --follow-symlinks --cache-control max-age=600
        env:
          AWS_S3_BUCKET: ${{ secrets.AWS_BUCKET_NAME }}
          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          AWS_REGION: ${{ secrets.AWS_REGION }}
          SOURCE_DIR: "foo/js/live"
          DEST_DIR: "foo/pages/assets/js/test/"

        # Deploy for foo2
      - name: Deploy to S3 for foo2
        if: steps.changes.outputs.foo2 == 'true'
        uses: jakejarvis/s3-sync-action@master
        with:
          args: --follow-symlinks --cache-control max-age=600
        env:
          AWS_S3_BUCKET: ${{ secrets.AWS_BUCKET_NAME }}
          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          AWS_REGION: ${{ secrets.AWS_REGION }}
          SOURCE_DIR: "foo2/js/live"
          DEST_DIR: "foo2/pages/assets/js/test/"
ffcabbar commented 1 year ago

@dorny Do you have any idea? Because it seems like it has to be working for me. For example '# minify files for each project' part is not working properly. When I change just one folder, all steps of that part are working. But it should not.

dorny commented 1 year ago

@ffcabbar I will take a look on it later in the evening.

ffcabbar commented 1 year ago

Thanks a lot! I'll wait for you. And I also shared it on StackOverflow. Maybe It helps you. link

dorny commented 1 year ago

Your workflow is triggered by the push to test-s3 branch and changes are detected against your default (e.g. main) branch. It's the "Feature branches" workflow. That means if you change in the first pushed commit something in "foo" and in the second pushed commit something in "foo2", it would consider both as changed.

If you want to execute the steps based only on the changes included in the commits currently pushed, then you need to set the base input variable to be the same as the branch where you pushed the commits. See the Long lived branches example.

Hope this will solve your issue. If not, please look at the action logs. You should see exactly how the changes were detected and which files are considered to be modified.

ffcabbar commented 1 year ago

It works now! Thanks a lot! I just added the base input variable.