Merge create-release-action@v2 step for configuration as git project and for usual project

Hi, I have a github workflow which creates release in Octopus, since we started to use configuration as code feature, we need to support both versions of this step, for new type of octopus project and old one, like in code below(part of bigger workflow):

- name: Create Octopus release  
  uses: OctopusDeploy/create-release-action@v3
  if: ${{  env.OCTOPUS_IS_GIT_ENABLED_PROJECT == 'false'  }}
  with:
    project: ${{ steps.setup.outputs.project }}
    channel: ${{ inputs.octopus-channel }}
    release_number: "${{ env.RELEASE_VERSION }}"
    packages: ${{ format(steps.setup.outputs.packages, '\n') }}
    server: ${{ inputs.octopus-server }}
    space: ${{ inputs.octopus-space-name }}
    api_Key: ${{ secrets.octopus-api-key }}
    release_notes: '${{ env.CI_MD_BUILD_LINK }}:${{ env.RELEASE_VERSION }}'

- name: Create Octopus release 
  uses: OctopusDeploy/create-release-action@v3
  if: ${{  env.OCTOPUS_IS_GIT_ENABLED_PROJECT == 'true' }}
  with:
    project: ${{ steps.setup.outputs.project }}
    channel: ${{ inputs.octopus-channel }}
    git_ref: ${{ github.ref }}
    release_number: "${{ env.RELEASE_VERSION }}"
    packages: ${{ format(steps.setup.outputs.packages, '\n') }}
    server: ${{ inputs.octopus-server }}
    space: ${{ inputs.octopus-space-name }}
    api_Key: ${{ secrets.octopus-api-key }}
    release_notes: '${{ env.CI_MD_BUILD_LINK }}:${{ env.RELEASE_VERSION }}'

As you can see the only difference is in

git_ref: ${{ github.ref }}

I tried to merge both steps and set the value of git_ref depending of the env.OCTOPUS_IS_GIT_CONTROLLED_PROJECT value, like below :

git_ref: ${{ env.OCTOPUS_IS_GIT_CONTROLLED_PROJECT == 'true' && github.ref }}

but anyway show an error:

Error: Error: Since the provided project is not a version controlled project, the GitCommit and GitRef arguments are not supported for this command.

Could you confirm that I need to use both version of the step or please suggest how can I merge them with supporting both types of the project

Hi @Igor.Nesterov,

Thanks for reaching out to Octopus Support!
Sorry to hear you’re encountering issues.

I did some testing myself on this and I wasn’t able to get one configuration to work for both version controlled and regular projects.

Sending even a null value for git_ref to a project that isn’t version controlled would result in an error.

The crux of this is likely due to conditional statements in GHA not being able to be nested within the with: portion, where variable values are specified.
If this was the case, you could specify that only if the project was version controlled should you include a git_ref parameter.

Unfortunately, I believe the best method is to have two different configurations as you’ve already done.
Apologies I don’t have a better answer for you - should you have any additional questions please don’t hesitate to get back to me and I’ll do my best to help.

Kind Regards,
Adam

1 Like

Thanks for answer Adam.
As you mentioned, will continue to use both steps until we will not migrate everything on configuration as code.

1 Like