From f94d58148182ea09b38c76b7fa3d908b368f1f37 Mon Sep 17 00:00:00 2001 From: Louis Chu Date: Fri, 26 May 2023 19:42:57 -0400 Subject: [PATCH] fix build branch name (#208) (#211) * fix build branch name Signed-off-by: Mingshi Liu * test workflow with new pushes Signed-off-by: Mingshi Liu --------- Signed-off-by: Mingshi Liu <113382730+mingshl@users.noreply.github.com> Signed-off-by: Mingshi Liu (cherry picked from commit 3b58246eae39af426fcd9aa03182409be05bcd15) Co-authored-by: Mingshi Liu <113382730+mingshl@users.noreply.github.com> --- .../workflows/remote-integ-tests-workflow.yml | 19 ++++++++++++++----- .github/workflows/test-and-build.yml | 16 ++++++++++++---- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/.github/workflows/remote-integ-tests-workflow.yml b/.github/workflows/remote-integ-tests-workflow.yml index 0128e2f..2e9192f 100644 --- a/.github/workflows/remote-integ-tests-workflow.yml +++ b/.github/workflows/remote-integ-tests-workflow.yml @@ -31,15 +31,23 @@ jobs: - uses: actions/checkout@v2 - name: Fetch Version Information - id: fetch version + id: fetch_version run: | - if [[ "${{ github.event_name }}" == "push" ]]; then - echo "Base branch name is $(basename "${{ github.ref }}")" - BRANCH_NAME=$(basename "${{ github.ref }}") + if [[ "${{ github.event_name }}" == "push" ]]; then + pr_number=$(curl -sSL -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ + "https://api.github.com/repos/${{ github.repository }}/commits/${{ github.sha }}/pulls" \ + | jq -r '.[0].number') + url_number=$(curl -sSL -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ + "https://api.github.com/repos/${{ github.repository }}/commits/${{ github.sha }}/pulls" \ + | jq -r '.[0].url') + pr_data=$(curl -sSL -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ + "$url_number") + BRANCH_NAME=$(echo "$pr_data" | jq -r '.base.ref') + echo "BRANCH_NAME is $BRANCH_NAME" elif [[ "${{ github.event_name }}" == "pull_request" ]]; then echo "Base branch name is "${{ github.event.pull_request.base.ref }}"" BRANCH_NAME="${{ github.event.pull_request.base.ref }}" - fi + fi CURRENT_VERSION=$(node -p "require('./package.json').version") MAJOR_VERSION=$(echo $CURRENT_VERSION | cut -d. -f1) MINOR_VERSION=$(echo $CURRENT_VERSION | cut -d. -f2) @@ -50,6 +58,7 @@ jobs: echo "OPENSEARCH_DASHBOARDS_VERSION=$BRANCH_NAME" >> $GITHUB_ENV echo "OPENSEARCH_DASHBOARDS_FTREPO_VERSION=$BRANCH_NAME" >> $GITHUB_ENV echo "SEARCH_PROCESSOR_PLUGIN_VERSION=$BRANCH_NAME" >> $GITHUB_ENV + shell: bash - name: Enable longer filenames if: ${{ matrix.os == 'windows-latest' }} diff --git a/.github/workflows/test-and-build.yml b/.github/workflows/test-and-build.yml index 211109c..22478fb 100644 --- a/.github/workflows/test-and-build.yml +++ b/.github/workflows/test-and-build.yml @@ -18,13 +18,21 @@ jobs: shell: bash run: | OPENSEARCH_PLUGIN_VERSION=$(node -p "require('./package.json').version") - if [[ "${{ github.event_name }}" == "push" ]]; then - echo "Base branch name is $(basename "${{ github.ref }}")" - BRANCH_NAME=$(basename "${{ github.ref }}") + if [[ "${{ github.event_name }}" == "push" ]]; then + pr_number=$(curl -sSL -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ + "https://api.github.com/repos/${{ github.repository }}/commits/${{ github.sha }}/pulls" \ + | jq -r '.[0].number') + url_number=$(curl -sSL -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ + "https://api.github.com/repos/${{ github.repository }}/commits/${{ github.sha }}/pulls" \ + | jq -r '.[0].url') + pr_data=$(curl -sSL -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ + "$url_number") + echo "BRANCH_NAME is $BRANCH_NAME" elif [[ "${{ github.event_name }}" == "pull_request" ]]; then echo "Base branch name is "${{ github.event.pull_request.base.ref }}"" BRANCH_NAME="${{ github.event.pull_request.base.ref }}" - fi + fi + echo "Target branch: $BRANCH_NAME" echo "OPENSEARCH_PLUGIN_VERSION=$OPENSEARCH_PLUGIN_VERSION" >> $GITHUB_ENV echo "OPENSEARCH_VERSION=$BRANCH_NAME" >> $GITHUB_ENV