paths-filter icon indicating copy to clipboard operation
paths-filter copied to clipboard

Changes are compared against incorrect branch

Open ramandatascientist opened this issue 3 years ago • 1 comments

Hello,

When i run this workflow against main/ (i.e merge PR to main/) , it compares the commit hash with main/

eg: Changes will be detected between 891f6892ce44fefc67bd90251cb3f0d463f52d12 and main

But when i run this workflow against release/ branch (eg: merge PR to release/), it shows incorrect behaviour. It compare release/ branch with main/

eg: Change detection refs/remotes/origin/main...refs/remotes/origin/release/v2023.08

It should be compared against my commit hash and release/v2023.08 branch and not with main

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

name: All - Bump the Semver tag on push to main or release branches

on:
  workflow_dispatch:
  push:
    branches:
      - 'main'
      - 'release/v**'
    paths:
      - 'collector/build/**' # only generate tag on the last process commit of ADF (i.e after ADF ARM builder)
      - 'refinery/**'
      - 'datastore/**'

jobs:
  calculate-version:
    name: Calculate Version
    runs-on: ubuntu-latest
    strategy:
      # We're using the matrix strategy so that we run the right steps for the right service.
      # Since a job might fail, we don't fail fast to allow all jobs to attempt to run.
      fail-fast: false
      matrix:
        service: [datastore, collector, refinery]

    env:
      SERVICE_NAME: ${{ matrix.service }}

    outputs:
      tag: ${{ steps.version.outputs.tag }}
      
    steps:
    - uses: actions/checkout@v3
      with:
        fetch-depth: 0
        
    - uses: dorny/paths-filter@v2
      id: pathfilter
      with:
        filters: |
            collector: 'collector/build/**'
            datastore: 'datastore/**'
            refinery: 'refinery/**'
    
    - name: Determine Version
      id: version
      if: (steps.pathfilter.outputs.datastore == 'true' && matrix.service == 'datastore')
        || (steps.pathfilter.outputs.collector == 'true' && matrix.service == 'collector')
        || (steps.pathfilter.outputs.refinery == 'true' && matrix.service == 'refinery')
        
      env:
        GIT_BRANCH: ${{ github.ref_name }}
        GIT_TAG_PREFIX: "${{ env.SERVICE_NAME }}-v"
      shell: bash
      run: ./config/version.sh
      
    - name: Dump version metadata
      if: steps.version.conclusion != 'skipped'
      env:
        JSON: ${{ toJson(steps.version.outputs) }}
      run: |
        echo "$JSON" > version.json
    - name: Upload version metadata
      uses: actions/upload-artifact@v2
      if: steps.version.conclusion != 'skipped'
      with:
        name: versions
        path: version.json
        
    - name: 'Tag sources'   
      if: steps.version.conclusion != 'skipped' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release/')) 
      env:
        TAG: ${{ steps.version.outputs.tag }}
      uses: actions/github-script@v6
      with:
        script: |
          await github.rest.git.createRef({
            owner: context.repo.owner,
            repo: context.repo.repo,
            ref: "refs/tags/${{ env.TAG }}",
            sha: context.sha
          })

ramandatascientist avatar Apr 24 '23 21:04 ramandatascientist

@ramandatascientist is the Long lived branches example from the README what you are looking for? That would need this config:

    - uses: dorny/paths-filter@v2
      id: pathfilter
      with:
        base: ${{ github.ref }}
        filters: |
            collector: 'collector/build/**'
            datastore: 'datastore/**'
            refinery: 'refinery/**'

aldenquimby avatar May 22 '23 11:05 aldenquimby