GitHub Actions if conditions with subbranch does not work

Hello, Everyone!

I need help with one small thing. I use GitHub Actions for CI. We have develop and several release branches like release/2.6.0, release/2.6.1, release/2.6.2.

I try using If condition:
if: ${{ github.event_name == ‘push’ && github.ref_name == ‘release/*’ }}
if: ${{ github.event_name == ‘push’ && github.ref_name == ‘release/**’ }}

also I tried:
if: ${{ github.event_name == ‘push’ && github.ref_name == ‘release/[0-9].[0-9].[0-9]’ }}
if: ${{ github.event_name == ‘push’ && github.ref_name == ‘release/2.6.[0-9]’ }}
if: ${{ github.event_name == ‘push’ && github.ref_name == ‘release/2.6.[2]’ }}

but worked only “hardcode”:
if: ${{ github.event_name == ‘push’ && github.ref_name == ‘release/2.6.2’ }}

For example, I tried use Setup-Java Actions, but I don’t have good results…IMAGE 2021-11-17 14:40:14

This is my workflow for testing:

name: build

Controls when the workflow will run

on:
push:
branches:
- ‘develop’
- ‘release/**’

workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

  - name: Setup Java JDK
    if: ${{ github.event_name == 'push' && github.ref_name == 'release/**' }}
    uses: actions/setup-java@v2
    with:
      distribution: "temurin" # See 'Supported distributions' for available options
      java-version: "8"

I will be grateful for any help.

I solved problem. this my if conditions

if: ${{ github.event_name == ‘push’ && (contains(github.ref_name, ‘develop’) || contains(github.ref_name, ‘release’)) }}

if: “!contains(github.ref_name, ‘release’)”

1 Like