From 391370e99e49cc31678e4afe62c718b0c9985b32 Mon Sep 17 00:00:00 2001 From: Kirill Sizov Date: Thu, 26 May 2022 16:01:40 +0300 Subject: [PATCH] Fix sending requests on CI (#22) * Fix getting SHA * add auth token for all necessary requests --- .github/workflows/main.yml | 75 ++++++++++++++++++++++++++++++-------- 1 file changed, 60 insertions(+), 15 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5b6023df..9e454be8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -22,19 +22,37 @@ jobs: - name: Getting SHA from the default branch id: get-sha run: | - URL_get_default_branch="https://api.github.com/repos/${{ github.repository }}" - DEFAULT_BRANCH=$(curl -s -X GET -G ${URL_get_default_branch} | jq -r '.default_branch') - URL_get_sha_default_branch="https://api.github.com/repos/${{ github.repository }}/git/ref/heads/${DEFAULT_BRANCH}" - SHA=$(curl -s -X GET -G ${URL_get_sha_default_branch} | jq .object.sha | tr -d '"') + DEFAULT_BRANCH=$(curl -s \ + --request GET \ + --url https://api.github.com/repos/${{ github.repository }} \ + --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' | \ + jq -r '.default_branch') + + SHA=$(curl -s \ + --request GET \ + --url https://api.github.com/repos/${{ github.repository }}/git/ref/heads/${DEFAULT_BRANCH} \ + --header 'authorization: token ${{ secrets.GITHUB_TOKEN }}' | \ + jq -r '.object.sha') + echo ::set-output name=default_branch::${DEFAULT_BRANCH} echo ::set-output name=sha::${SHA} - name: Waiting a cache creation in the default branch + if: ${{ github.ref_name != 'develop' }} run: | - URL_runs="https://api.github.com/repos/${{ github.repository }}/actions/workflows/cache.yml/runs" SLEEP=45 NUMBER_ATTEMPTS=10 while [[ ${NUMBER_ATTEMPTS} -gt 0 ]]; do - RUN_status=$(curl -s -X GET -G ${URL_runs} | jq -r '.workflow_runs[]? | select((.head_sha == "${{ steps.get-sha.outputs.sha }}") and (.event == "push") and (.name == "Cache") and (.head_branch == "${{ steps.get-sha.outputs.default_branch }}")) | .status') + RUN_status=$(curl -s \ + --request GET \ + --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \ + --url https://api.github.com/repos/${{ github.repository }}/actions/workflows/cache.yml/runs | \ + jq -r '.workflow_runs[]? | + select( + (.head_sha == "${{ steps.get-sha.outputs.sha }}") + and (.event == "push") + and (.name == "Cache") + and (.head_branch == "${{ steps.get-sha.outputs.default_branch }}") + ) | .status') if [[ ${RUN_status} == "completed" ]]; then echo "The cache creation on the '${{ steps.get-sha.outputs.default_branch }}' branch has finished. Status: ${RUN_status}" break @@ -114,10 +132,18 @@ jobs: - name: Getting SHA from the default branch id: get-sha run: | - URL_get_default_branch="https://api.github.com/repos/${{ github.repository }}" - DEFAULT_BRANCH=$(curl -s -X GET -G ${URL_get_default_branch} | jq -r '.default_branch') - URL_get_sha_default_branch="https://api.github.com/repos/${{ github.repository }}/git/ref/heads/${DEFAULT_BRANCH}" - SHA=$(curl -s -X GET -G ${URL_get_sha_default_branch} | jq .object.sha | tr -d '"') + DEFAULT_BRANCH=$(curl -s \ + --request GET \ + --url https://api.github.com/repos/${{ github.repository }} \ + --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' | \ + jq -r '.default_branch') + + SHA=$(curl -s \ + --request GET \ + --url https://api.github.com/repos/${{ github.repository }}/git/ref/heads/${DEFAULT_BRANCH} \ + --header 'authorization: token ${{ secrets.GITHUB_TOKEN }}' | \ + jq -r '.object.sha') + echo ::set-output name=default_branch::${DEFAULT_BRANCH} echo ::set-output name=sha::${SHA} - name: Waiting a cache creation in the default branch @@ -126,7 +152,17 @@ jobs: SLEEP=45 NUMBER_ATTEMPTS=10 while [[ ${NUMBER_ATTEMPTS} -gt 0 ]]; do - RUN_status=$(curl -s -X GET -G ${URL_runs} | jq -r '.workflow_runs[]? | select((.head_sha == "${{ steps.get-sha.outputs.sha }}") and (.event == "push") and (.name == "Cache") and (.head_branch == "${{ steps.get-sha.outputs.default_branch }}")) | .status') + RUN_status=$(curl -s \ + --request GET \ + --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \ + --url https://api.github.com/repos/${{ github.repository }}/actions/workflows/cache.yml/runs | \ + jq -r '.workflow_runs[]? | + select( + (.head_sha == "${{ steps.get-sha.outputs.sha }}") + and (.event == "push") + and (.name == "Cache") + and (.head_branch == "${{ steps.get-sha.outputs.default_branch }}") + ) | .status') if [[ ${RUN_status} == "completed" ]]; then echo "The cache creation on the '${{ steps.get-sha.outputs.default_branch }}' branch has finished. Status: ${RUN_status}" break @@ -238,10 +274,19 @@ jobs: - name: Getting SHA from the default branch id: get-sha run: | - URL_get_default_branch="https://api.github.com/repos/${{ github.repository }}" - DEFAULT_BRANCH=$(curl -s -X GET -G ${URL_get_default_branch} | jq -r '.default_branch') - URL_get_sha_default_branch="https://api.github.com/repos/${{ github.repository }}/git/ref/heads/${DEFAULT_BRANCH}" - SHA=$(curl -s -X GET -G ${URL_get_sha_default_branch} | jq .object.sha | tr -d '"') + DEFAULT_BRANCH=$(curl -s \ + --request GET \ + --url https://api.github.com/repos/${{ github.repository }} \ + --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' | \ + jq -r '.default_branch') + + SHA=$(curl -s \ + --request GET \ + --url https://api.github.com/repos/${{ github.repository }}/git/ref/heads/${DEFAULT_BRANCH} \ + --header 'authorization: token ${{ secrets.GITHUB_TOKEN }}' | \ + jq -r '.object.sha') + + echo ::set-output name=default_branch::${DEFAULT_BRANCH} echo ::set-output name=sha::${SHA} - name: Getting CVAT server cache from the default branch uses: actions/cache@v2