Skip to content

Commit

Permalink
Append netrc
Browse files Browse the repository at this point in the history
  • Loading branch information
gestrich committed Apr 19, 2024
1 parent d90ee40 commit 1fdb154
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/build_loop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ jobs:
(vars.SCHEDULED_SYNC != 'false' && needs.check_latest_from_upstream.outputs.NEW_COMMITS == 'true' )
)
steps:
env:
TOKEN_TO_CHECK: ${{ secrets.GH_PAT }}
- name: Write to Netrc
run: "../../appendNetrc.sh netrc github.com user {{ env.TOKEN_TO_CHECK }}"
run: "../../appendNetrc.sh netrc api.github.com user {{ env.TOKEN_TO_CHECK }}"
- name: Select Xcode version
run: "sudo xcode-select --switch /Applications/Xcode_15.0.app/Contents/Developer"

Expand Down
45 changes: 45 additions & 0 deletions appendNetrc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash

set -eu
set -o errexit
set -o pipefail
set -o nounset

# Function to URL-encode strings
urlencode() {
local length="${#1}"
for (( i = 0; i < length; i++ )); do
local c="${1:i:1}"
case $c in
[a-zA-Z0-9.~_-]) printf "$c" ;;
*) printf '%%%02X' "'$c" ;;
esac
done
}

# Main script
main() {
local netrcPath="$1"
local machine=$(urlencode "${2}")
local username=$(urlencode "${3}")
local password=$(urlencode "${4}")

if [ -z "$netrcPath" ] || [ -z "$machine" ] || [ -z "$username" ] || [ -z "$password" ]; then
echo "NetrcPath, machine, username, and password are required."
exit 1
fi

# Check and set file permissions
if [ -f "$netrcPath" ]; then
chmod 600 "$netrcPath"
fi

# Append to the file
echo "machine ${machine}" >> "$netrcPath"
echo " login ${username}" >> "$netrcPath"
echo " password ${password}" >> "$netrcPath"
chmod 600 "$netrcPath"
}

# Run the script with passed arguments
main "$@"

0 comments on commit 1fdb154

Please sign in to comment.