Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions add-a-self-hosted-runner-to-a-group-for-an-organization.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
. ./.gh-api-examples.conf

# https://docs.github.com/en/enterprise-cloud@latest/rest/actions/self-hosted-runner-groups?apiVersion=2022-11-28#add-a-self-hosted-runner-to-a-group-for-an-organization
# PUT /orgs/{org}/actions/runner-groups/{runner_group_id}/runners/{runner_id}

#runner_group_id=$(./list-self-hosted-runner-groups-for-an-organization.sh | jq '.runner_groups[-1].id')
runner_group_id=$(./list-self-hosted-runner-groups-for-an-organization.sh | jq '.runner_groups[0].id')
runner_id=$(./list-self-hosted-runners-for-an-organization.sh | jq '.runners[-1].id')

set -x
curl -v ${curl_custom_flags} \
-X PUT \
-H "X-GitHub-Api-Version: ${github_api_version}" \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
"${GITHUB_API_BASE_URL}/orgs/${org}/actions/runner-groups/${runner_group_id}/runners/${runner_id}"

10 changes: 9 additions & 1 deletion build-testcase-selfhosted-runner
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@

set -x

if [ $runner_version == 'latest' ];
then
runner_version=$(./list-runner-latest-release.sh)
fi

# Get the registration token for the runner before we cd into the runner download
# directory.
registration_token=$(./create-a-registration-token-for-a-repository.sh | jq -r '.token')

rm -rf actions-runner
mkdir actions-runner && cd actions-runner




curl -O -L https://github.com/actions/runner/releases/download/${runner_version}/actions-runner-${runner_os}-${runner_platform}-${runner_version##v}.tar.gz

tar zxf actions-runner-${runner_os}-${runner_platform}-${runner_version##v}.tar.gz
Expand All @@ -20,4 +28,4 @@ then
hostname="github.com"
fi

./config.sh --url https://${hostname}/${org}/${repo} --token ${registration_token} --unattended --name ${runner_name} --labels ${runner_labels} --replace
./config.sh --url https://${hostname}/${org}/${repo} --token ${registration_token} --unattended --name ${repo_runner_name} --labels ${runner_labels} --replace
28 changes: 28 additions & 0 deletions build-testcase-selfhosted-runner-enterprise
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
. .gh-api-examples.conf

set -x

if [ $runner_version == 'latest' ];
then
runner_version=$(./list-runner-latest-release.sh)
fi

# Get the registration token for the runner before we cd into the runner download
# directory.
registration_token=$(./create-a-registration-token-for-an-enterprise.sh | jq -r '.token')

rm -rf actions-runner
mkdir actions-runner && cd actions-runner

curl -O -L https://github.com/actions/runner/releases/download/${runner_version}/actions-runner-${runner_os}-${runner_platform}-${runner_version##v}.tar.gz

tar zxf actions-runner-${runner_os}-${runner_platform}-${runner_version##v}.tar.gz

# This is a gnarly thing to do but saves rewriting how the config file
# gets populated for this one script that uses github.com the runner tarball download
if [ $hostname == "api.github.com" ];
then
hostname="github.com"
fi

./config.sh --url https://${hostname}/enterprises/${enterprise} --token ${registration_token} --unattended --name ${ent_runner_name}
29 changes: 29 additions & 0 deletions build-testcase-selfhosted-runner-org
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
. .gh-api-examples.conf

set -x

if [ $runner_version == 'latest' ];
then
runner_version=$(./list-runner-latest-release.sh)
fi

# Get the registration token for the runner before we cd into the runner download
# directory.
#registration_token=$(./create-a-registration-token-for-a-repository.sh | jq -r '.token')
registration_token=$(./create-a-registration-token-for-an-organization.sh | jq -r '.token')

rm -rf actions-runner
mkdir actions-runner && cd actions-runner

curl -O -L https://github.com/actions/runner/releases/download/${runner_version}/actions-runner-${runner_os}-${runner_platform}-${runner_version##v}.tar.gz

tar zxf actions-runner-${runner_os}-${runner_platform}-${runner_version##v}.tar.gz

# This is a gnarly thing to do but saves rewriting how the config file
# gets populated for this one script that uses github.com the runner tarball download
if [ $hostname == "api.github.com" ];
then
hostname="github.com"
fi

./config.sh --url https://${hostname}/${org} --token ${registration_token} --unattended --name ${org_runner_name}
20 changes: 14 additions & 6 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ def main(args):
org_members="${org_members}"
default_org_webhook_id=1
# Org self hosted runners
org_self_hosted_runner_group_name="org self hosted runners"

org_shr_group_name="pwr_org_shr_group"


### [Repository](https://docs.github.com/en/rest/repos/repos#create-an-organization-repository)
Expand Down Expand Up @@ -304,7 +303,9 @@ def main(args):
runner_version=${runner_version}
runner_os=${runner_os}
runner_platform=${runner_platform}
runner_name="the-power-example-runner"
repo_runner_name="pwr-repo-runner"
org_runner_name="pwr-org-runner"
ent_runner_name="pwr-ent-runner"
runner_labels="the-power,self-hosted"


Expand Down Expand Up @@ -593,8 +594,8 @@ def main(args):
"--runner-version",
action="store",
dest="runner_version",
default="v2.312.0",
help="Version of self hosted runner. Be sure to use the tag like this: `v2.294.0`",
default="latest",
help="Version of self hosted runner. Defaults to latest. If using anything else be sure to use the tag like this: `v2.294.0`",
)
parser.add_argument(
"--runner-os",
Expand Down Expand Up @@ -830,7 +831,14 @@ def main(args):
action="store",
dest="default_repo_visibility",
default="private",
help="Set the default visibility for repositories",
help="Set the default visibility for repositories.",
)
parser.add_argument(
"--org-shr-group-name",
action="store",
dest="org_shr_group_name",
default="",
help="Organization self hosted runner group name.",
)
parser.add_argument(
"--github-api-version",
Expand Down
8 changes: 4 additions & 4 deletions create-a-reference.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
. ./.gh-api-examples.conf

# https://docs.github.com/en/rest/reference/git#create-a-reference
# https://docs.github.com/en/enterprise-cloud@latest/rest/git/refs?apiVersion=2022-11-28#create-a-reference
# POST /repos/{owner}/{repo}/git/refs

# If the script is passed an argument $1 use that as the name
Expand All @@ -11,10 +11,9 @@ if [ -z "$1" ]
sha=$1
fi

json_file=tmp/create-a-reference.json

ref="refs/heads/grandmasterflash2"

json_file=tmp/create-a-reference.json
jq -n \
--arg ref "${ref}" \
--arg sha "${sha}" \
Expand All @@ -26,4 +25,5 @@ jq -n \
curl ${curl_custom_flags} \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
${GITHUB_API_BASE_URL}/repos/${org}/${repo}/git/refs --data @${json_file}
"${GITHUB_API_BASE_URL}/repos/${org}/${repo}/git/refs" --data @${json_file}

6 changes: 4 additions & 2 deletions create-a-registration-token-for-an-enterprise.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
. ./.gh-api-examples.conf

# https://docs.github.com/rest/reference/actions#create-a-registration-token-for-an-enterprise
# https://docs.github.com/en/enterprise-cloud@latest/rest/actions/self-hosted-runners?apiVersion=2022-11-28#create-a-registration-token-for-an-enterprise
# POST /enterprises/{enterprise}/actions/runners/registration-token

curl ${curl_custom_flags} \
-X POST \
-H "X-GitHub-Api-Version: ${github_api_version}" \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
${GITHUB_API_BASE_URL}/enterprises/${enterprise}/actions/runners/registration-token
"${GITHUB_API_BASE_URL}/enterprises/${enterprise}/actions/runners/registration-token"

21 changes: 21 additions & 0 deletions create-a-registration-token-for-an-organization.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
. ./.gh-api-examples.conf

# https://docs.github.com/en/enterprise-cloud@latest/rest/actions/self-hosted-runners?apiVersion=2022-11-28#create-a-registration-token-for-an-organization
# POST /orgs/{org}/actions/runners/registration-token


if [ -z "$1" ]
then
repo=$repo
else
repo=$1
fi


curl ${curl_custom_flags} \
-X POST \
-H "X-GitHub-Api-Version: ${github_api_version}" \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
"${GITHUB_API_BASE_URL}/orgs/${org}/actions/runners/registration-token"

9 changes: 8 additions & 1 deletion create-a-self-hosted-runner-group-for-an-organization.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
# POST /orgs/{org}/actions/runner-groups


name=${org_self_hosted_runner_group_name:-org_runner_group}
if [ -z "$1" ]
then
name=${org_shr_group_name}
else
name=$1
fi


json_file=tmp/create-a-self-hosted-runner-group-for-an-organization.json
jq -n \
Expand All @@ -19,3 +25,4 @@ curl ${curl_custom_flags} \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
"${GITHUB_API_BASE_URL}/orgs/${org}/actions/runner-groups" --data @${json_file}

8 changes: 4 additions & 4 deletions create-branch.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
. ./.gh-api-examples.conf

# https://docs.github.com/en/rest/reference/git#create-a-reference
# POST /repos/:owner/:repo/git/refs
# https://docs.github.com/en/enterprise-cloud@latest/rest/git/refs?apiVersion=2022-11-28#create-a-reference
# POST /repos/{owner}/{repo}/git/refs

# If the script is passed an argument $1 use that as the name

Expand Down Expand Up @@ -39,9 +39,9 @@ jq -n \
--arg sha "${sha}" \
'{ ref: $ref, sha: $sha }' > ${json_file}

json_string=$(cat $json_file | jq )

curl ${curl_custom_flags} \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
${GITHUB_API_BASE_URL}/repos/${org}/${repo}/git/refs --data "${json_string}"
"${GITHUB_API_BASE_URL}/repos/${org}/${repo}/git/refs" --data $@{json_file}

6 changes: 2 additions & 4 deletions create-commit-status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,22 @@ if [ -z "$2" ]
status_context=$2
fi


target_branch=${branch_name}
timestamp=$(date +%s)

sha=$(curl --silent -H "Authorization: Bearer ${GITHUB_TOKEN}" ${GITHUB_API_BASE_URL}/repos/${org}/${repo}/git/refs/heads/${target_branch}| jq -r '.object.sha')

json_file=tmp/create-commit-status.json

jq -n \
--arg state "${state}" \
--arg target_url "https://example.com/build/status" \
--arg description "The build status was: $status This is completely fake. The status ran at: ${timestamp}" \
--arg context "${status_context}" \
'{ state : $state , target_url : $target_url, description: $description, context: $context }' > ${json_file}

json_string=$(cat $json_file | jq )

curl ${curl_custom_flags} \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
${GITHUB_API_BASE_URL}/repos/${org}/${repo}/statuses/${sha} --data "${json_string}"
"${GITHUB_API_BASE_URL}/repos/${org}/${repo}/statuses/${sha}" --data $@{json_file}

11 changes: 1 addition & 10 deletions create-n-commit-statuses.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@
# The state of the status.
# Can be one of: error, failure, pending, success
# If there is no first argument use a default value of "pending"

state="pending"




target_branch=${branch_name}
timestamp=$(date +%s)

Expand All @@ -24,7 +19,6 @@ turns=${1:-30}

for item in $(seq $turns)
do

echo $item >&2
item_l=$(printf "%05d" $item)
status_context="ci/pwr-commit-status-required-${item_l}"
Expand All @@ -36,11 +30,8 @@ do
--arg context "${status_context}" \
'{ state : $state , target_url : $target_url, description: $description, context: $context }' > ${json_file}

json_string=$(cat $json_file | jq )


curl ${curl_custom_flags} \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
${GITHUB_API_BASE_URL}/repos/${org}/${repo}/statuses/${sha} --data "${json_string}"
"${GITHUB_API_BASE_URL}/repos/${org}/${repo}/statuses/${sha}" --data "${json_file}"
done
25 changes: 25 additions & 0 deletions docs/zdpower.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Creating separate installations with the `zdpower` script
The `zdpower` script is a handy wrapper over configure.py for use in cases where multiple copies of the power are needed.

```mermaid
graph TD
subgraph Inputs
A[Ticket Number] -->|provided as argument or prompted| Script[zdpower]
B[power_config ~/.the-power-dotcom.conf] --> Script
C[GitHub Repo URL https://github.com/gm3dmo/the-power] --> Script
end

subgraph Outputs
Script --> D[Cloned Directory named after Ticket Number]
D --> E[dotcom-configure.sh executed]
E --> F[.gh-api-examples.conf file created]
end
```


#. Make sure you have a home bin directory `mkdir -p ~/bin`
#. Copy `zdpower` to your home directory `cp zdpower ~/bin && chmod 500 ~/bin/zdpower`
#. Copy this skeleton file to your ime directory `cp the-power-dotcom.skeleton ~/.the-power-dotcom.conf`
#. Edit this new `~/.the-power-dotcom.conf` file with all of the appropriate values for your environment like your github_token, enterprise and organization name.
#. Run `dotcom-configure.sh` to set the power up to target your dotcom environment.

47 changes: 47 additions & 0 deletions pwr-create-branch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
. ./.gh-api-examples.conf

# https://docs.github.com/en/enterprise-cloud@latest/rest/git/refs?apiVersion=2022-11-28#create-a-reference
# POST /repos/{owner}/{repo}/git/refs

# If the script is passed an argument $1 use that as the name

if [ -z "$1" ]
then
repo=$repo
else
repo=$1
fi

# We want this to always be able to create a branch so, if given no arguments 2
# it will create a branch name with a suffix of the current unix timestamp
#

timestamp=$(date +%s)

if [ -z "$2" ]
then
branch_name=${branch_name}_${timestamp}
else
branch_name=$2
fi

json_file=tmp/create-branch-${branch_name}.json

sha=$(curl --silent -H "Authorization: Bearer ${GITHUB_TOKEN}" ${GITHUB_API_BASE_URL}/repos/${org}/${repo}/git/refs/heads/${base_branch} | jq -r '.object.sha')

echo "==================" >&2
echo "(${sha})" >&2
echo "($branch_name)" >&2
echo "==================" >&2

jq -n \
--arg ref "refs/heads/${branch_name}" \
--arg sha "${sha}" \
'{ ref: $ref, sha: $sha }' > ${json_file}


curl ${curl_custom_flags} \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
"${GITHUB_API_BASE_URL}/repos/${org}/${repo}/git/refs" --data $@{json_file}