Ver código fonte

Allow to get SHA for `alive` branch creation from a private repository

- Authenticate the curl API request by GH_PAT according to
https://docs.github.com/de/rest/authentication/authenticating-to-the-rest-api?apiVersion=2022-11-28#authenticating-in-a-github-actions-workflow-using-curl
Thank you @dnzxy for the hint!

This is a temporary requirement until the repositories are made public.
bjornoleh 2 anos atrás
pai
commit
5ea744f97d
1 arquivos alterados com 13 adições e 6 exclusões
  1. 13 6
      .github/workflows/build_Open-iAPS.yml

+ 13 - 6
.github/workflows/build_Open-iAPS.yml

@@ -67,13 +67,20 @@ jobs:
     - name: Create alive branch
       if: env.ALIVE_BRANCH_EXISTS == 'false'
       env:
-        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+        GITHUB_TOKEN: ${{ secrets.GH_PAT }}
       run: |
-        # Get ref for nightscout/Open-iAPS:main
-        SHA=$(curl -sS https://api.github.com/repos/${{ env.UPSTREAM_REPO }}/git/refs \
-          | jq '.[] | select(.ref == "refs/heads/main" ) | .object.sha' \
-          | tr -d '"'
-        );
+        # get ref for nightscout/Open-iAPS:main
+        response=$(curl --request GET \
+                          --url "https://api.github.com/repos/${{ env.UPSTREAM_REPO }}/git/refs/heads/main" \
+                          --header "Authorization: Bearer $GITHUB_TOKEN" \
+                          --silent)
+        echo "API Response: $response"
+        SHA=$(echo "$response" | jq -r '.object.sha')
+        if [ "$SHA" = "null" ]; then
+            echo "Error: Unable to retrieve SHA for the main branch."
+            exit 1
+        fi
+        echo "SHA of main branch: $SHA";
         
         # Create alive branch based on nightscout/Open-iAPS:main
         gh api \