Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
maazmmd opened this issue May 8, 2024 · 4 comments

Comments

@maazmmd
Copy link

maazmmd commented May 8, 2024

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/[email protected]

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
Copy link

@maazmmd did you manage to figure it out?

@zburgermeiszter
Copy link

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

@maazmmd
Copy link
Author

maazmmd commented May 14, 2024

@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
Copy link
Author

maazmmd commented May 14, 2024

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

Not working, also tried with working-directory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants