diff --git a/.github/workflows/check-release-branches.yaml b/.github/workflows/check-release-branches.yaml new file mode 100644 index 000000000000..18a3fa7a1412 --- /dev/null +++ b/.github/workflows/check-release-branches.yaml @@ -0,0 +1,65 @@ +--- +name: Check release branches +on: + push: + - "release/**" # We should only react to branches like "release/networkservicemesh/*/v*.*.*" + - "!release/*" # and ignore branches like "release/v*.*.*". "**" - any character, "*" - any character except "/" + +concurrency: + group: check-release-branches + cancel-in-progress: true + +jobs: + check-release-branches: + name: Check release branches + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set envs + run: | + echo "tag=$(echo ${{ github.event.ref }} | awk -F '/' '{print $NF}')" >> $GITHUB_ENV + { + echo 'branches<> $GITHUB_ENV + + # On this step we get all image names from deployments-k8s/apps folder and + # compare them to the set of release/networkservicemesh/cmd-*/${tag} branches. + # If the sets of branches and images are equal then we merge all + # release/networkservicemesh/cmd-*/${tag} branches into release/${tag} branch. + - name: Check release branches + run: | + images=$(grep -roh 'apps' -e "ghcr\.io\/networkservicemesh\/ci\/.*" | cut -d'/' -f4 | cut -d':' -f1 | sort -u) + branches=$(echo ${{ env.branches }} | tr ' ' '\n' | cut -d'/' -f4 | sort -u) + diff <(echo "$branches") <(echo "$images") + + - name: Merge branches + run: | + git config --global user.email "nsmbot@networkservicmesh.io" + git config --global user.name "NSMBot" + + git checkout -b release/${{ env.tag }} + for branch in ${{ env.branches }}; do + git merge $branch + done + + git push -u origin release/${{ env.tag }} + + # After merging all release branches we remove them from remote deployments-k8s + - name: Remove release branches + run: | + for branch in ${{ env.branches }}; do + branch=${branch#"origin/"} + gh api \ + --method DELETE \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + /repos/networkservicemesh/deployments-k8s/git/refs/heads/$branch + done + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/pr-for-release.yaml b/.github/workflows/pr-for-release.yaml deleted file mode 100644 index 9aaf6e316656..000000000000 --- a/.github/workflows/pr-for-release.yaml +++ /dev/null @@ -1,33 +0,0 @@ ---- -name: Pull Request on release/* Branch Push -on: - push: - branches: - - "release/**" # We should only react to branches like "release/networkservicemesh/*/v*.*.*" - - "!release/*" # and ignore branches like "release/v*.*.*". "**" - any character, "*" - any character except "/" -jobs: - auto-pull-request: - name: Pull Request on release/* Branch Push - runs-on: ubuntu-latest - steps: - - name: Get tag - run: | - branch=${{ github.event.ref }} - echo tag=${branch#refs/heads/release/*/*/} >> $GITHUB_OUTPUT - id: get-tag-step - - - uses: actions/checkout@v2 - - name: Construct PR message - run: | - PULL_REQUEST_BODY=$(git log --pretty='format:%B' -1 | sed '/^$/d;$d' | sed 's/#/# /g') - echo "$PULL_REQUEST_BODY" - echo "PULL_REQUEST_BODY<> $GITHUB_ENV - echo "$PULL_REQUEST_BODY" >> $GITHUB_ENV - echo "EOF" >> $GITHUB_ENV - - - name: pull-request-action - uses: vsoch/pull-request-action@1.1.0 - env: - GITHUB_TOKEN: ${{ secrets.NSM_BOT_GITHUB_TOKEN }} - BRANCH_PREFIX: "release/" - PULL_REQUEST_BRANCH: "release/${{ steps.get-tag-step.outputs.tag }}"