forked from gm3dmo/the-power
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-an-environment-secret.sh
executable file
·33 lines (25 loc) · 1.2 KB
/
create-an-environment-secret.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
. ./.gh-api-examples.conf
# https://docs.github.com/en/rest/reference/actions#create-or-update-an-environment-secret
# PUT /repositories/{repository_id}/environments/{environment_name}/secrets/{secret_name}
json_file=tmp/environment-secret.json
rm -f ${json_file}
environment_name=${default_environment_name}
secret_name=${environment_secret_name}
key_id=$(./get-an-environment-public-key.sh | jq -r '.key_id')
environment_public_key=$(./get-an-environment-public-key.sh | jq -r '.key')
encrypted_value=$(ruby create-an-environment-secret-helper.rb ${environment_public_key})
jq -n \
--arg secret_name "${secret_name}" \
--arg key_id "${key_id}" \
--arg encrypted_value "${encrypted_value}" \
'{
secret_name: $secret_name,
key_id: $key_id,
encrypted_value: $encrypted_value
}' > ${json_file}
repository_id=$(./list-repo.sh $repo | jq -r '.id')
curl ${curl_custom_flags} \
-X PUT \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
${GITHUB_API_BASE_URL}/repositories/${repository_id}/environments/${environment_name}/secrets/${secret_name} --data @${json_file}