From cdd8150e00d4f0d8e90bcffd147e798199b8a864 Mon Sep 17 00:00:00 2001 From: Mikhail Timofeev <48208649+miketimofeev@users.noreply.github.com> Date: Thu, 20 Jan 2022 13:41:21 +0300 Subject: [PATCH] [macOS] Allow using GitHub PAT to enlarge api requests limit (#4917) * Use gh api pat * Add gh token to 10.15 * Add github_api_pat for macos-12 --- images/macos/provision/core/nvm.sh | 2 +- images/macos/provision/core/powershell.sh | 2 +- images/macos/provision/core/ruby.sh | 2 +- images/macos/provision/core/stack.sh | 2 +- images/macos/provision/core/swiftlint.sh | 2 +- images/macos/templates/macOS-10.15.json | 9 ++++++++- images/macos/templates/macOS-11.json | 7 +++++++ images/macos/templates/macOS-12.json | 9 ++++++++- 8 files changed, 28 insertions(+), 7 deletions(-) diff --git a/images/macos/provision/core/nvm.sh b/images/macos/provision/core/nvm.sh index 16252a029..d2e552fea 100755 --- a/images/macos/provision/core/nvm.sh +++ b/images/macos/provision/core/nvm.sh @@ -5,7 +5,7 @@ ########################################################################### source ~/utils/utils.sh -VERSION=$(curl -s https://api.github.com/repos/nvm-sh/nvm/releases/latest | jq -r '.tag_name') +VERSION=$(curl -H "Authorization: token $API_PAT" -s https://api.github.com/repos/nvm-sh/nvm/releases/latest | jq -r '.tag_name') curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/$VERSION/install.sh | bash if [ $? -eq 0 ]; then diff --git a/images/macos/provision/core/powershell.sh b/images/macos/provision/core/powershell.sh index fc6d6ffca..d674fccb3 100644 --- a/images/macos/provision/core/powershell.sh +++ b/images/macos/provision/core/powershell.sh @@ -2,7 +2,7 @@ source ~/utils/utils.sh echo Installing PowerShell... -psRelease=$(curl -s "https://api.github.com/repos/PowerShell/PowerShell/releases/latest") +psRelease=$(curl -H "Authorization: token $API_PAT" -s "https://api.github.com/repos/PowerShell/PowerShell/releases/latest") psDownloadUrl=$(echo $psRelease | jq -r '.assets[].browser_download_url | select(contains("osx-x64.pkg"))' | head -n 1) download_with_retries $psDownloadUrl "/tmp" "powershell.pkg" diff --git a/images/macos/provision/core/ruby.sh b/images/macos/provision/core/ruby.sh index e4c198a6a..cae43e949 100755 --- a/images/macos/provision/core/ruby.sh +++ b/images/macos/provision/core/ruby.sh @@ -10,7 +10,7 @@ echo "GEM_PATH=$GEM_PATH" >> "$HOME/.bashrc" echo 'export PATH="$GEM_PATH:/usr/local/opt/ruby@'${DEFAULT_RUBY_VERSION}'/bin:$PATH"' >> "$HOME/.bashrc" echo "Install Ruby from toolset..." -PACKAGE_TAR_NAMES=$(curl -s "https://api.github.com/repos/ruby/ruby-builder/releases/latest" | jq -r '.assets[].name') +PACKAGE_TAR_NAMES=$(curl -H "Authorization: token $API_PAT" -s "https://api.github.com/repos/ruby/ruby-builder/releases/latest" | jq -r '.assets[].name') TOOLSET_VERSIONS=$(get_toolset_value '.toolcache[] | select(.name | contains("Ruby")) | .versions[]') RUBY_PATH="$AGENT_TOOLSDIRECTORY/Ruby" diff --git a/images/macos/provision/core/stack.sh b/images/macos/provision/core/stack.sh index bdb22a56c..7dfa8328d 100644 --- a/images/macos/provision/core/stack.sh +++ b/images/macos/provision/core/stack.sh @@ -2,7 +2,7 @@ source ~/utils/utils.sh echo "Get the latest Stack version..." -StackRelease=$(curl -s "https://api.github.com/repos/commercialhaskell/stack/releases/latest") +StackRelease=$(curl -H "Authorization: token $API_PAT" -s "https://api.github.com/repos/commercialhaskell/stack/releases/latest") DownloadUrl=$(echo $StackRelease | jq -r '.assets[].browser_download_url | select(contains("osx-x86_64.tar.gz"))' | head -n 1) StackVersion=$(echo $StackRelease | jq -r '.name' | cut -c2-) StackArchive="/tmp/stack.tar.gz" diff --git a/images/macos/provision/core/swiftlint.sh b/images/macos/provision/core/swiftlint.sh index c9c2fdc05..b4bb7e3f4 100644 --- a/images/macos/provision/core/swiftlint.sh +++ b/images/macos/provision/core/swiftlint.sh @@ -2,7 +2,7 @@ source ~/utils/utils.sh echo "Install SwiftLint" -swiftlintUrl=$(curl -s "https://api.github.com/repos/realm/SwiftLint/releases/latest" | jq -r '.assets[].browser_download_url | select(contains("SwiftLint.pkg"))') +swiftlintUrl=$(curl -H "Authorization: token $API_PAT" -s "https://api.github.com/repos/realm/SwiftLint/releases/latest" | jq -r '.assets[].browser_download_url | select(contains("SwiftLint.pkg"))') download_with_retries $swiftlintUrl "/tmp" "SwiftLint.pkg" sudo installer -pkg /tmp/SwiftLint.pkg -target / rm -rf /tmp/SwiftLint.pkg diff --git a/images/macos/templates/macOS-10.15.json b/images/macos/templates/macOS-10.15.json index d6f57c07f..9f130ad8e 100644 --- a/images/macos/templates/macOS-10.15.json +++ b/images/macos/templates/macOS-10.15.json @@ -11,6 +11,7 @@ "output_folder": null, "vm_username": null, "vm_password": null, + "github_api_pat": null, "xcode_install_user": null, "xcode_install_password": null, "image_os": "macos1015" @@ -138,6 +139,9 @@ "./provision/core/rubygem.sh", "./provision/core/git.sh", "./provision/core/node.sh" + ], + "environment_vars": [ + "API_PAT={{user `github_api_pat`}}" ] }, { @@ -191,12 +195,15 @@ "./provision/core/pypy.sh", "./provision/core/pipx-packages.sh", "./provision/core/bicep.sh" + ], + "environment_vars": [ + "API_PAT={{user `github_api_pat`}}" ] }, { "type": "shell", "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} pwsh -f {{ .Path }}", - "scripts": [ + "scripts": [ "./provision/core/toolset.ps1", "./provision/core/configure-toolset.ps1" ] diff --git a/images/macos/templates/macOS-11.json b/images/macos/templates/macOS-11.json index bebcfc2d7..01a086ac5 100644 --- a/images/macos/templates/macOS-11.json +++ b/images/macos/templates/macOS-11.json @@ -11,6 +11,7 @@ "output_folder": null, "vm_username": null, "vm_password": null, + "github_api_pat": null, "xcode_install_user": null, "xcode_install_password": null, "image_os": "macos11" @@ -143,6 +144,9 @@ "./provision/core/rubygem.sh", "./provision/core/git.sh", "./provision/core/node.sh" + ], + "environment_vars": [ + "API_PAT={{user `github_api_pat`}}" ] }, { @@ -194,6 +198,9 @@ "./provision/core/pypy.sh", "./provision/core/pipx-packages.sh", "./provision/core/bicep.sh" + ], + "environment_vars": [ + "API_PAT={{user `github_api_pat`}}" ] }, { diff --git a/images/macos/templates/macOS-12.json b/images/macos/templates/macOS-12.json index 2d3c17686..e9c1de9d7 100644 --- a/images/macos/templates/macOS-12.json +++ b/images/macos/templates/macOS-12.json @@ -11,6 +11,7 @@ "output_folder": null, "vm_username": null, "vm_password": null, + "github_api_pat": null, "xcode_install_user": null, "xcode_install_password": null, "image_os": "macos12" @@ -143,6 +144,9 @@ "./provision/core/rubygem.sh", "./provision/core/git.sh", "./provision/core/node.sh" + ], + "environment_vars": [ + "API_PAT={{user `github_api_pat`}}" ] }, { @@ -193,12 +197,15 @@ "./provision/core/pypy.sh", "./provision/core/pipx-packages.sh", "./provision/core/bicep.sh" + ], + "environment_vars": [ + "API_PAT={{user `github_api_pat`}}" ] }, { "type": "shell", "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} pwsh -f {{ .Path }}", - "scripts": [ + "scripts": [ "./provision/core/toolset.ps1", "./provision/core/configure-toolset.ps1" ]