dorny / paths-filter

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

Comparison betwwen different tags not working where as it compares with default branch #237

Open maazmmd opened 2 months ago

maazmmd commented 2 months ago

Hello,

When i run this workflow against develop/ (i.e merge PR to develop/), it compares default branch rather than tags

eg: Changes will be detected between default branch and feature branch

This shows incorrect behaviour. It compare between 2 tags

eg: Change detection refs/remotes/origin/release/1.10.0...refs/remotes/origin/release/1.10.1

It should be compared between the tags and not with develop

Here is my workflow file. The issue is on step: - uses: dorny/paths-filter@v2.11.1

on:
  workflow_call:
    inputs:
      profile:
        description: "Environment to deploy, must be one of (dev|master|int|prod)"
        required: true
        type: string
      region:
        description: "Region to deploy, must be one of (emea|cn)"
        required: true
        type: string
      git_tag:
        description: "Git tag of the release to deploy"
        required: true
        type: string

jobs:
  deploy:
    runs-on: [self-hosted, linux, X64, build-node]
    steps:
      - uses: ./workflows/actions/com/github/actions/checkout/v3
        with:
          path: repo
          ref: ${{ inputs.git_tag }}
          fetch-depth: 0

      - name: Get previous deployed version from release.yaml
        id: getversion
        working-directory: repo
        run: |
          if [ -z ${{ inputs.tenant }} ]; then
            echo "git_previous_tag=$(cat environments/${{ inputs.profile }}/${{ inputs.region }}/release.yaml | yq e '.previousVer')"
            echo "git_previous_tag=$git_previous_tag" >> $GITHUB_OUTPUT
          else
            echo "git_previous_tag=develop" >> $GITHUB_OUTPUT
          fi 

      - uses: ./workflows/actions/com/github/dorny/paths-filter/4512585405083f25c027a35db413c2b3b9006d50
        id: changes
        with:
          base: ${{ steps.getversion.outputs.git_previous_tag }}
          working-directory: meid
          filters: |
            values: ['environments/${{ inputs.profile }}/${{ inputs.region }}/values.yaml']
            tokenstore: ['environments/${{ inputs.profile }}/${{ inputs.region }}/token-values.yaml']
            userstore: ['environments/${{ inputs.profile }}/${{ inputs.region }}/user-values.yaml']
            clients: ['environments/${{ inputs.profile }}/${{ inputs.region }}/clients.yaml', 'clients/**']
zburgermeiszter commented 2 months ago

@maazmmd did you manage to figure it out?

zburgermeiszter commented 2 months ago

I figured it out. If you define both ref and base it will compare them.

maazmmd commented 2 months ago

@maazmmd did you manage to figure it out?

Yes I was able to figure out but not using dorny/paths-filter for comparison with tags

    - name: Detect changes in feature branches
      uses: ./workflows/actions/com/github/dorny/paths-filter/4512585405083f25c027a35db413c2b3b9006d50 
      id: changes
      if: github.ref_type == 'branch'
      with:
        base: master
        working-directory: repo
        filters: |
          docs: ['docs/**']
          src: ['src/**']

   - name: Detect tag changes for [DEPLOYMENTS]
      id: tag-changes
      if: github.ref_type == 'tag'
      working-directory: repo
      run: |
        set -o xtrace          
        declare -A paths=(
          [docs]='docs/**'
          [src]='src/**')

         # Get previous tag from a step (Not added here)
        git_previous_tag=${{ steps.getversion.outputs.git_previous_tag }}

        for key in "${!paths[@]}"; do
          changed_files=$(git diff --name-only "${{ github.ref_name }}" "$git_previous_tag" -- ${paths[$key]})
          if [ -z "$changed_files" ]; then
            echo "$key=false" >> $GITHUB_OUTPUT
          else
            echo "$key=true" >> $GITHUB_OUTPUT
            echo "Changes detected in $key: $changed_files"
          fi
        done
maazmmd commented 2 months ago

I figured it out. If you define both ref and base it will compare them.

Not working, also tried with working-directory