Fix sending requests on CI (#22)

* Fix getting SHA

* add auth token for all necessary requests
main
Kirill Sizov 4 years ago committed by GitHub
parent cc73962e6c
commit 391370e99e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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

Loading…
Cancel
Save