Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support for self-hosted runners at organization level #11

Merged
merged 1 commit into from
Aug 23, 2024

Conversation

vprashar2929
Copy link
Contributor

@vprashar2929 vprashar2929 commented Aug 22, 2024

This commit introduces the ability to register self-hosted runners using both organization and repository level registration tokens.

Fixes #10

@vprashar2929 vprashar2929 requested a review from a team as a code owner August 22, 2024 05:50
Copy link
Contributor

@ocobles ocobles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your PR @vprashar2929 ! 🚀

This will be helpful. However, it is possible that even in an org, you may want or need to register a self-runner at repo level. Could you please add an input for that?

Something like:

repository_level:
    description: 'Set to true to use repository-level registration token'
    required: false
    default: false

And then the condition would be:

if [[ "${{ inputs.repository_level }}" == "true" ]] || [[ -z "${{ github.organization }}" ]]; then
  url="https://api.github.com/repos/${{ github.repository }}/actions/runners/registration-token"
else
  url="https://api.github.com/orgs/${{ github.organization }}/actions/runners/registration-token"
fi

@vprashar2929
Copy link
Contributor Author

@ocobles Updated the PR 😄

Copy link
Contributor

@ocobles ocobles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vprashar2929 I realized that we will need some more changes. Where it says sudo -E -u ghrunner ./config.sh... the url must be updated too. Here's a suggestion:

register a runner-scope variable

if [[ "${{ inputs.repository_level }}" == "true" ]] || [[ -z "${{ github.organization }}" ]]; then
    runner_scope="${{ github.repository }}"
    url="https://api.github.com/repos/${{ runner_scope }}/actions/runners/registration-token"
else
    runner_scope="${{ github.organization }}"
    url="https://api.github.com/orgs/${{ runner_scope }}/actions/runners/registration-token"
fi
token=$(curl -fsSL \
    -X POST \
    -H 'accept: application/vnd.github+json' \
    -H 'authorization: Bearer ${{ inputs.github_token }}' \
    -H 'X-GitHub-Api-Version: 2022-11-28' \
    --url $url | jq -r .token)
echo "registration-token=${token}" >> $GITHUB_OUTPUT
echo "runner-scope=${runner_scope}" >> $GITHUB_OUTPUT

and in the Create Device step update the url and labels args:

sudo -E -u ghrunner ./config.sh --unattended --url https://github.com/${{ steps.get-registration-token.outputs.runner-scope }} --token ${{ steps.get-registration-token.outputs.registration-token }} --name $(hostname) --work /home/ghrunner --labels ${{ steps.get-registration-token.outputs.runner-scope }} --ephemeral

This commit introduces the ability to register self-hosted runners using
both organization and repository level registration tokens.

Signed-off-by: Vibhu Prashar <vibhu.sharma2929@gmail.com>
@vprashar2929
Copy link
Contributor Author

My bad I forgot to check that. 😞 Fixed now

Copy link
Contributor

@ocobles ocobles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏼 looks good!

@ocobles ocobles merged commit 3237a8b into equinix-labs:main Aug 23, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RFE: support org level self hosted runner
2 participants