From 252914155050a480484a106621ddcdf236a87f8b Mon Sep 17 00:00:00 2001 From: shimi Date: Mon, 2 Dec 2024 16:38:36 +0200 Subject: [PATCH 01/18] Create pr-jira-validation.yaml --- .github/workflows/pr-jira-validation.yaml | 71 +++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 .github/workflows/pr-jira-validation.yaml diff --git a/.github/workflows/pr-jira-validation.yaml b/.github/workflows/pr-jira-validation.yaml new file mode 100644 index 000000000..7fa57cfbc --- /dev/null +++ b/.github/workflows/pr-jira-validation.yaml @@ -0,0 +1,71 @@ +name: Validate Pull Request + +on: + workflow_dispatch: + inputs: + branch_name: + description: "Name of the branch to test !" + required: true + default: "DOC-2064-test-shimi-3" + +jobs: + validate: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Get source branch + id: get_source_branch + #run: echo "branch=${{ github.event.pull_request.head.ref }}" >> $GITHUB_ENV + run: echo "branch=${{ inputs.branch_name }}" >> $GITHUB_ENV + + - name: Get branch creation event + id: get_branch_creation_event + run: | + BRANCH_CREATION_EVENT=$(gh api -H "Accept: application/vnd.github.v3+json" /repos/${{ github.repository }}/events | jq -c '[.[] | select(.type == "CreateEvent" and .payload.ref == "${{ env.branch }}" and .payload.ref_type == "branch")] | .[0]') + echo "branch_creation_event=$BRANCH_CREATION_EVENT" >> $GITHUB_ENV + + - name: Validate branch creator + id: validate_branch_creator + run: | + ACTOR_LOGIN=$(echo '${{ env.branch_creation_event }}' | jq -r '.actor.login') + if [ "$ACTOR_LOGIN" != "jira[bot]" ]; then + echo "Branch was not created by jira[bot]." + exit 1 + fi + + - name: Validate PR body for Jira ticket link + id: validate_pr_body + run: | + PR_BODY=$(jq -r '.pull_request.body' < $GITHUB_EVENT_PATH) + if ! echo "$PR_BODY" | grep -q "https://spotinst.atlassian.net/browse/Documentation-"; then + echo "PR body does not contain a Jira ticket link." + exit 1 + fi + + - name: Extract Jira ticket ID + id: extract_jira_ticket + run: | + PR_BODY=$(jq -r '.pull_request.body' < $GITHUB_EVENT_PATH) + JIRA_TICKET=$(echo "$PR_BODY" | grep -o "Documentation-[0-9]*" | head -n 1) + if [ -z "$JIRA_TICKET" ]; then + echo "No Jira ticket found in the PR body." + exit 1 + fi + echo "jira_ticket=$JIRA_TICKET" >> $GITHUB_ENV + + - name: Verify Jira ticket status + id: verify_jira_ticket + env: + JIRA_USER: ${{ secrets.JIRA_USER }} + JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }} + run: | + JIRA_TICKET=${{ env.jira_ticket }} + JIRA_API_URL="https://spotinst.atlassian.net/rest/api/2/issue/$JIRA_TICKET" + JIRA_STATUS=$(curl -s -u $JIRA_USER:$JIRA_API_TOKEN $JIRA_API_URL | jq -r '.fields.status.name') + if [ "$JIRA_STATUS" != "APPROVED FOR PUBLISHING" ]; then + echo "Jira ticket $JIRA_TICKET is not in 'APPROVED FOR PUBLISHING' status." + exit 1 + fi + echo "All validations passed." From 910f81c749f956062b590162b9f11032c70b509f Mon Sep 17 00:00:00 2001 From: shimi Date: Mon, 2 Dec 2024 16:40:58 +0200 Subject: [PATCH 02/18] Update pr-jira-validation.yaml --- .github/workflows/pr-jira-validation.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-jira-validation.yaml b/.github/workflows/pr-jira-validation.yaml index 7fa57cfbc..062a0f14c 100644 --- a/.github/workflows/pr-jira-validation.yaml +++ b/.github/workflows/pr-jira-validation.yaml @@ -1,4 +1,4 @@ -name: Validate Pull Request +name: pr-jira-validation on: workflow_dispatch: From 3eb13d13b0d94a848da7c89bf5af56c7d307a38a Mon Sep 17 00:00:00 2001 From: shimi Date: Mon, 2 Dec 2024 17:38:24 +0200 Subject: [PATCH 03/18] Update pr-jira-validation.yaml --- .github/workflows/pr-jira-validation.yaml | 26 ++++++++++++++++------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/.github/workflows/pr-jira-validation.yaml b/.github/workflows/pr-jira-validation.yaml index 062a0f14c..65a33bfe0 100644 --- a/.github/workflows/pr-jira-validation.yaml +++ b/.github/workflows/pr-jira-validation.yaml @@ -1,12 +1,16 @@ name: pr-jira-validation on: - workflow_dispatch: - inputs: - branch_name: - description: "Name of the branch to test !" - required: true - default: "DOC-2064-test-shimi-3" + pull_request: + branches: + - master + +# workflow_dispatch: +# inputs: +# branch_name: +# description: "Name of the branch to test !" +# required: true +# default: "DOC-2064-test-shimi-3" jobs: validate: @@ -17,19 +21,25 @@ jobs: - name: Get source branch id: get_source_branch - #run: echo "branch=${{ github.event.pull_request.head.ref }}" >> $GITHUB_ENV - run: echo "branch=${{ inputs.branch_name }}" >> $GITHUB_ENV + run: echo "branch=${{ github.event.pull_request.head.ref }}" >> $GITHUB_ENV + #run: echo "branch=${{ inputs.branch_name }}" >> $GITHUB_ENV + # - name: Get branch creation event id: get_branch_creation_event + env: + GH_TOKEN: ${{ github.token }} run: | + echo "repo - ${{ github.repository }}" BRANCH_CREATION_EVENT=$(gh api -H "Accept: application/vnd.github.v3+json" /repos/${{ github.repository }}/events | jq -c '[.[] | select(.type == "CreateEvent" and .payload.ref == "${{ env.branch }}" and .payload.ref_type == "branch")] | .[0]') + echo "branch_creation_event - $BRANCH_CREATION_EVENT" echo "branch_creation_event=$BRANCH_CREATION_EVENT" >> $GITHUB_ENV - name: Validate branch creator id: validate_branch_creator run: | ACTOR_LOGIN=$(echo '${{ env.branch_creation_event }}' | jq -r '.actor.login') + echo "ACTOR_LOGIN - $ACTOR_LOGIN" if [ "$ACTOR_LOGIN" != "jira[bot]" ]; then echo "Branch was not created by jira[bot]." exit 1 From 82b4f0e9ad2cbe9642f273bb74e0391957d6528b Mon Sep 17 00:00:00 2001 From: shimi Date: Mon, 2 Dec 2024 17:48:46 +0200 Subject: [PATCH 04/18] Update pr-jira-validation.yaml --- .github/workflows/pr-jira-validation.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-jira-validation.yaml b/.github/workflows/pr-jira-validation.yaml index 65a33bfe0..2c7dbc4d6 100644 --- a/.github/workflows/pr-jira-validation.yaml +++ b/.github/workflows/pr-jira-validation.yaml @@ -49,7 +49,7 @@ jobs: id: validate_pr_body run: | PR_BODY=$(jq -r '.pull_request.body' < $GITHUB_EVENT_PATH) - if ! echo "$PR_BODY" | grep -q "https://spotinst.atlassian.net/browse/Documentation-"; then + if ! echo "$PR_BODY" | grep -q "https://spotinst.atlassian.net/browse/DOC-"; then echo "PR body does not contain a Jira ticket link." exit 1 fi From b22019c98c705e083ca18085d04572b7b68c25c6 Mon Sep 17 00:00:00 2001 From: shimi Date: Mon, 2 Dec 2024 17:50:41 +0200 Subject: [PATCH 05/18] Update pr-jira-validation.yaml --- .github/workflows/pr-jira-validation.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pr-jira-validation.yaml b/.github/workflows/pr-jira-validation.yaml index 2c7dbc4d6..8fb11bb35 100644 --- a/.github/workflows/pr-jira-validation.yaml +++ b/.github/workflows/pr-jira-validation.yaml @@ -49,6 +49,7 @@ jobs: id: validate_pr_body run: | PR_BODY=$(jq -r '.pull_request.body' < $GITHUB_EVENT_PATH) + echo "PR-body - $PR_BODY" if ! echo "$PR_BODY" | grep -q "https://spotinst.atlassian.net/browse/DOC-"; then echo "PR body does not contain a Jira ticket link." exit 1 From 392c3688a74d8404c36750aeb6eb46925ae4ecfa Mon Sep 17 00:00:00 2001 From: shimi Date: Mon, 2 Dec 2024 17:54:48 +0200 Subject: [PATCH 06/18] Update pr-jira-validation.yaml --- .github/workflows/pr-jira-validation.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-jira-validation.yaml b/.github/workflows/pr-jira-validation.yaml index 8fb11bb35..bb3311fca 100644 --- a/.github/workflows/pr-jira-validation.yaml +++ b/.github/workflows/pr-jira-validation.yaml @@ -59,7 +59,7 @@ jobs: id: extract_jira_ticket run: | PR_BODY=$(jq -r '.pull_request.body' < $GITHUB_EVENT_PATH) - JIRA_TICKET=$(echo "$PR_BODY" | grep -o "Documentation-[0-9]*" | head -n 1) + JIRA_TICKET=$(echo "$PR_BODY" | grep -o "DOC-[0-9]*" | head -n 1) if [ -z "$JIRA_TICKET" ]; then echo "No Jira ticket found in the PR body." exit 1 From 925617f79f7df9b871221f94494057a1822e62e6 Mon Sep 17 00:00:00 2001 From: shimi Date: Mon, 2 Dec 2024 18:02:02 +0200 Subject: [PATCH 07/18] Update pr-jira-validation.yaml --- .github/workflows/pr-jira-validation.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pr-jira-validation.yaml b/.github/workflows/pr-jira-validation.yaml index bb3311fca..5f46864cc 100644 --- a/.github/workflows/pr-jira-validation.yaml +++ b/.github/workflows/pr-jira-validation.yaml @@ -75,6 +75,7 @@ jobs: JIRA_TICKET=${{ env.jira_ticket }} JIRA_API_URL="https://spotinst.atlassian.net/rest/api/2/issue/$JIRA_TICKET" JIRA_STATUS=$(curl -s -u $JIRA_USER:$JIRA_API_TOKEN $JIRA_API_URL | jq -r '.fields.status.name') + echo "JIRA_STATUS - $JIRA_STATUS" if [ "$JIRA_STATUS" != "APPROVED FOR PUBLISHING" ]; then echo "Jira ticket $JIRA_TICKET is not in 'APPROVED FOR PUBLISHING' status." exit 1 From aa84a9f73f2550ce3740d95092fc651369c57299 Mon Sep 17 00:00:00 2001 From: shimi Date: Mon, 2 Dec 2024 18:05:27 +0200 Subject: [PATCH 08/18] Update pr-jira-validation.yaml --- .github/workflows/pr-jira-validation.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-jira-validation.yaml b/.github/workflows/pr-jira-validation.yaml index 5f46864cc..0d8e6bcee 100644 --- a/.github/workflows/pr-jira-validation.yaml +++ b/.github/workflows/pr-jira-validation.yaml @@ -77,7 +77,7 @@ jobs: JIRA_STATUS=$(curl -s -u $JIRA_USER:$JIRA_API_TOKEN $JIRA_API_URL | jq -r '.fields.status.name') echo "JIRA_STATUS - $JIRA_STATUS" if [ "$JIRA_STATUS" != "APPROVED FOR PUBLISHING" ]; then - echo "Jira ticket $JIRA_TICKET is not in 'APPROVED FOR PUBLISHING' status." + echo "Jira ticket $JIRA_TICKET is not in 'APPROVED for PUBLISHING' status." exit 1 fi echo "All validations passed." From b4c13edd71037c9fde1cb92ee35c20b66b0b0726 Mon Sep 17 00:00:00 2001 From: shimi Date: Mon, 2 Dec 2024 18:06:24 +0200 Subject: [PATCH 09/18] Update pr-jira-validation.yaml --- .github/workflows/pr-jira-validation.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-jira-validation.yaml b/.github/workflows/pr-jira-validation.yaml index 0d8e6bcee..b9a00a116 100644 --- a/.github/workflows/pr-jira-validation.yaml +++ b/.github/workflows/pr-jira-validation.yaml @@ -77,7 +77,7 @@ jobs: JIRA_STATUS=$(curl -s -u $JIRA_USER:$JIRA_API_TOKEN $JIRA_API_URL | jq -r '.fields.status.name') echo "JIRA_STATUS - $JIRA_STATUS" if [ "$JIRA_STATUS" != "APPROVED FOR PUBLISHING" ]; then - echo "Jira ticket $JIRA_TICKET is not in 'APPROVED for PUBLISHING' status." + echo "Jira ticket $JIRA_TICKET is not in 'Approved for Publishing' status." exit 1 fi echo "All validations passed." From 043f4aab439ff0fe7908df7058aa95be695e59ff Mon Sep 17 00:00:00 2001 From: shimi Date: Mon, 2 Dec 2024 18:10:39 +0200 Subject: [PATCH 10/18] Update pr-jira-validation.yaml --- .github/workflows/pr-jira-validation.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-jira-validation.yaml b/.github/workflows/pr-jira-validation.yaml index b9a00a116..ab4b6eadc 100644 --- a/.github/workflows/pr-jira-validation.yaml +++ b/.github/workflows/pr-jira-validation.yaml @@ -76,7 +76,7 @@ jobs: JIRA_API_URL="https://spotinst.atlassian.net/rest/api/2/issue/$JIRA_TICKET" JIRA_STATUS=$(curl -s -u $JIRA_USER:$JIRA_API_TOKEN $JIRA_API_URL | jq -r '.fields.status.name') echo "JIRA_STATUS - $JIRA_STATUS" - if [ "$JIRA_STATUS" != "APPROVED FOR PUBLISHING" ]; then + if [ "$JIRA_STATUS" != "Approved for Publishing" ]; then echo "Jira ticket $JIRA_TICKET is not in 'Approved for Publishing' status." exit 1 fi From 97ebb9a3ef150d6edf542ef28e1e6dd755c7fadf Mon Sep 17 00:00:00 2001 From: shimi Date: Tue, 3 Dec 2024 15:17:50 +0200 Subject: [PATCH 11/18] Update pr-jira-validation.yaml (#678) --- .github/workflows/pr-jira-validation.yaml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/pr-jira-validation.yaml b/.github/workflows/pr-jira-validation.yaml index ab4b6eadc..adb410214 100644 --- a/.github/workflows/pr-jira-validation.yaml +++ b/.github/workflows/pr-jira-validation.yaml @@ -50,8 +50,8 @@ jobs: run: | PR_BODY=$(jq -r '.pull_request.body' < $GITHUB_EVENT_PATH) echo "PR-body - $PR_BODY" - if ! echo "$PR_BODY" | grep -q "https://spotinst.atlassian.net/browse/DOC-"; then - echo "PR body does not contain a Jira ticket link." + if ! echo "$PR_BODY" | grep -q -e "https://spotinst.atlassian.net/browse/DOC-" -e "https://spotinst.atlassian.net/browse/AUT-"; then + echo "PR body does not contain a valid Jira ticket link (DOC or AUT)." exit 1 fi @@ -59,9 +59,9 @@ jobs: id: extract_jira_ticket run: | PR_BODY=$(jq -r '.pull_request.body' < $GITHUB_EVENT_PATH) - JIRA_TICKET=$(echo "$PR_BODY" | grep -o "DOC-[0-9]*" | head -n 1) + JIRA_TICKET=$(echo "$PR_BODY" | grep -o -e "DOC-[0-9]*" -e "AUT-[0-9]*" | head -n 1) if [ -z "$JIRA_TICKET" ]; then - echo "No Jira ticket found in the PR body." + echo "No DOC or AUT Jira ticket found in the PR body." exit 1 fi echo "jira_ticket=$JIRA_TICKET" >> $GITHUB_ENV @@ -76,8 +76,8 @@ jobs: JIRA_API_URL="https://spotinst.atlassian.net/rest/api/2/issue/$JIRA_TICKET" JIRA_STATUS=$(curl -s -u $JIRA_USER:$JIRA_API_TOKEN $JIRA_API_URL | jq -r '.fields.status.name') echo "JIRA_STATUS - $JIRA_STATUS" - if [ "$JIRA_STATUS" != "Approved for Publishing" ]; then - echo "Jira ticket $JIRA_TICKET is not in 'Approved for Publishing' status." + if [ "$JIRA_STATUS" != "Approved for Publishing" ] && [[ "$JIRA_TICKET" != *DOC* ]]; then + echo "Jira ticket $JIRA_TICKET is not in 'Approved for Publishing' status and does not contain 'DOC'." exit 1 fi echo "All validations passed." From 85495d62dc60c78e76ff6de12a04ecbd732117df Mon Sep 17 00:00:00 2001 From: shimi Date: Tue, 3 Dec 2024 15:48:15 +0200 Subject: [PATCH 12/18] Update pr-jira-validation.yaml --- .github/workflows/pr-jira-validation.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-jira-validation.yaml b/.github/workflows/pr-jira-validation.yaml index adb410214..6d647bb54 100644 --- a/.github/workflows/pr-jira-validation.yaml +++ b/.github/workflows/pr-jira-validation.yaml @@ -15,6 +15,8 @@ on: jobs: validate: runs-on: ubuntu-latest + env: + GH_TOKEN: ${{ github.token }} steps: - name: Checkout code uses: actions/checkout@v3 @@ -27,8 +29,6 @@ jobs: - name: Get branch creation event id: get_branch_creation_event - env: - GH_TOKEN: ${{ github.token }} run: | echo "repo - ${{ github.repository }}" BRANCH_CREATION_EVENT=$(gh api -H "Accept: application/vnd.github.v3+json" /repos/${{ github.repository }}/events | jq -c '[.[] | select(.type == "CreateEvent" and .payload.ref == "${{ env.branch }}" and .payload.ref_type == "branch")] | .[0]') From 345ed6456b0f6b9d24d37e906c35e0991ec14e04 Mon Sep 17 00:00:00 2001 From: "shimi.azulay" Date: Tue, 3 Dec 2024 15:53:53 +0200 Subject: [PATCH 13/18] o --- .github/workflows/pr-jira-validation.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-jira-validation.yaml b/.github/workflows/pr-jira-validation.yaml index 6d647bb54..bda832d11 100644 --- a/.github/workflows/pr-jira-validation.yaml +++ b/.github/workflows/pr-jira-validation.yaml @@ -16,7 +16,7 @@ jobs: validate: runs-on: ubuntu-latest env: - GH_TOKEN: ${{ github.token }} + GH_TOKEN: ${{ github.token }} steps: - name: Checkout code uses: actions/checkout@v3 @@ -31,7 +31,7 @@ jobs: id: get_branch_creation_event run: | echo "repo - ${{ github.repository }}" - BRANCH_CREATION_EVENT=$(gh api -H "Accept: application/vnd.github.v3+json" /repos/${{ github.repository }}/events | jq -c '[.[] | select(.type == "CreateEvent" and .payload.ref == "${{ env.branch }}" and .payload.ref_type == "branch")] | .[0]') + BRANCH_CREATION_EVENT=$(gh api -H "Accept:application/vnd.github.v3+json" /repos/${{ github.repository }}/events | jq -c '[.[] | select(.type == "CreateEvent" and .payload.ref == "${{ env.branch }}" and .payload.ref_type == "branch")] | .[0]') echo "branch_creation_event - $BRANCH_CREATION_EVENT" echo "branch_creation_event=$BRANCH_CREATION_EVENT" >> $GITHUB_ENV From 4d2b8718b57a8971bc1f96120dcb5800e210bd6b Mon Sep 17 00:00:00 2001 From: "shimi.azulay" Date: Tue, 3 Dec 2024 15:56:46 +0200 Subject: [PATCH 14/18] linter changes --- .github/workflows/pr-jira-validation.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-jira-validation.yaml b/.github/workflows/pr-jira-validation.yaml index bda832d11..9da237265 100644 --- a/.github/workflows/pr-jira-validation.yaml +++ b/.github/workflows/pr-jira-validation.yaml @@ -31,7 +31,7 @@ jobs: id: get_branch_creation_event run: | echo "repo - ${{ github.repository }}" - BRANCH_CREATION_EVENT=$(gh api -H "Accept:application/vnd.github.v3+json" /repos/${{ github.repository }}/events | jq -c '[.[] | select(.type == "CreateEvent" and .payload.ref == "${{ env.branch }}" and .payload.ref_type == "branch")] | .[0]') + BRANCH_CREATION_EVENT=$(gh api -H "Accept: application/vnd.github.v3+json" /repos/${{ github.repository }}/events | jq -c '[.[] | select(.type == "CreateEvent" and .payload.ref == "${{ env.branch }}" and .payload.ref_type == "branch")] | .[0]') echo "branch_creation_event - $BRANCH_CREATION_EVENT" echo "branch_creation_event=$BRANCH_CREATION_EVENT" >> $GITHUB_ENV From 9a99406dee51f17f7f50c4b9319d0d3a694950fa Mon Sep 17 00:00:00 2001 From: shimi Date: Tue, 3 Dec 2024 17:21:01 +0200 Subject: [PATCH 15/18] Update pr-jira-validation.yaml --- .github/workflows/pr-jira-validation.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-jira-validation.yaml b/.github/workflows/pr-jira-validation.yaml index 9da237265..5cc3203c2 100644 --- a/.github/workflows/pr-jira-validation.yaml +++ b/.github/workflows/pr-jira-validation.yaml @@ -31,7 +31,7 @@ jobs: id: get_branch_creation_event run: | echo "repo - ${{ github.repository }}" - BRANCH_CREATION_EVENT=$(gh api -H "Accept: application/vnd.github.v3+json" /repos/${{ github.repository }}/events | jq -c '[.[] | select(.type == "CreateEvent" and .payload.ref == "${{ env.branch }}" and .payload.ref_type == "branch")] | .[0]') + BRANCH_CREATION_EVENT=$(gh api -H "Accept: application/vnd.github.v3+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/${{ github.repository }}/activity | jq -c '[.[] | select(.type == "CreateEvent" and .payload.ref == "refs/heads/${{ env.branch }}")] | .[0]') echo "branch_creation_event - $BRANCH_CREATION_EVENT" echo "branch_creation_event=$BRANCH_CREATION_EVENT" >> $GITHUB_ENV From 1e9da9755724f308a22e342d4a8ff8112b1779e8 Mon Sep 17 00:00:00 2001 From: shimi Date: Tue, 3 Dec 2024 17:27:44 +0200 Subject: [PATCH 16/18] Update pr-jira-validation.yaml change the env: GH_TOKEN: ${{ github.token }} location --- .github/workflows/pr-jira-validation.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-jira-validation.yaml b/.github/workflows/pr-jira-validation.yaml index 5cc3203c2..b190eea49 100644 --- a/.github/workflows/pr-jira-validation.yaml +++ b/.github/workflows/pr-jira-validation.yaml @@ -15,8 +15,6 @@ on: jobs: validate: runs-on: ubuntu-latest - env: - GH_TOKEN: ${{ github.token }} steps: - name: Checkout code uses: actions/checkout@v3 @@ -29,6 +27,8 @@ jobs: - name: Get branch creation event id: get_branch_creation_event + env: + GH_TOKEN: ${{ github.token }} run: | echo "repo - ${{ github.repository }}" BRANCH_CREATION_EVENT=$(gh api -H "Accept: application/vnd.github.v3+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/${{ github.repository }}/activity | jq -c '[.[] | select(.type == "CreateEvent" and .payload.ref == "refs/heads/${{ env.branch }}")] | .[0]') From fb29f2ba13f25bf2d36111e66181cba760e4d86f Mon Sep 17 00:00:00 2001 From: shimi Date: Tue, 3 Dec 2024 17:35:22 +0200 Subject: [PATCH 17/18] change the select --- .github/workflows/pr-jira-validation.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pr-jira-validation.yaml b/.github/workflows/pr-jira-validation.yaml index b190eea49..b024194c7 100644 --- a/.github/workflows/pr-jira-validation.yaml +++ b/.github/workflows/pr-jira-validation.yaml @@ -15,6 +15,8 @@ on: jobs: validate: runs-on: ubuntu-latest + env: + GH_TOKEN: ${{ github.token }} steps: - name: Checkout code uses: actions/checkout@v3 @@ -27,11 +29,9 @@ jobs: - name: Get branch creation event id: get_branch_creation_event - env: - GH_TOKEN: ${{ github.token }} run: | echo "repo - ${{ github.repository }}" - BRANCH_CREATION_EVENT=$(gh api -H "Accept: application/vnd.github.v3+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/${{ github.repository }}/activity | jq -c '[.[] | select(.type == "CreateEvent" and .payload.ref == "refs/heads/${{ env.branch }}")] | .[0]') + BRANCH_CREATION_EVENT=$(gh api -H "Accept: application/vnd.github.v3+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/${{ github.repository }}/activity | jq -c '[.[] | select(.activity_type == "branch_creation" and .ref == "refs/heads/${{ env.branch }}")] | .[0]') echo "branch_creation_event - $BRANCH_CREATION_EVENT" echo "branch_creation_event=$BRANCH_CREATION_EVENT" >> $GITHUB_ENV From 884abcfd7a663c45a2b01d7312dcc3c4977c3131 Mon Sep 17 00:00:00 2001 From: shimi Date: Tue, 3 Dec 2024 17:55:29 +0200 Subject: [PATCH 18/18] change the if statement --- .github/workflows/pr-jira-validation.yaml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pr-jira-validation.yaml b/.github/workflows/pr-jira-validation.yaml index b024194c7..4bdafa7d9 100644 --- a/.github/workflows/pr-jira-validation.yaml +++ b/.github/workflows/pr-jira-validation.yaml @@ -76,8 +76,10 @@ jobs: JIRA_API_URL="https://spotinst.atlassian.net/rest/api/2/issue/$JIRA_TICKET" JIRA_STATUS=$(curl -s -u $JIRA_USER:$JIRA_API_TOKEN $JIRA_API_URL | jq -r '.fields.status.name') echo "JIRA_STATUS - $JIRA_STATUS" - if [ "$JIRA_STATUS" != "Approved for Publishing" ] && [[ "$JIRA_TICKET" != *DOC* ]]; then - echo "Jira ticket $JIRA_TICKET is not in 'Approved for Publishing' status and does not contain 'DOC'." - exit 1 + if [ "$JIRA_STATUS" != "Approved for Publishing" ]; then + if [[ "$JIRA_TICKET" == *DOC* ]]; then + echo "Jira ticket $JIRA_TICKET is not in 'Approved for Publishing' status and it is from 'DOC' project." + exit 1 + fi fi echo "All validations passed."