Skip to content

Commit

Permalink
Enterprise support (#14)
Browse files Browse the repository at this point in the history
* #13: the "repoUrl" used to register the runner must also have the enteprise url + if runner doesn't exist in the proper location, throw an error and show it in stdout + readme updates for default runner dir

* #14: revert startup_script
  • Loading branch information
NorseGaud authored Nov 9, 2022
1 parent ef30564 commit 94c3663
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 41 deletions.
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@ This action is mean to be used with [anka-actions-down](https://github.com/veert

| input name | required? | description |
|-------------------------------------|-------------|---------------------------------------------------------------------------------------------------------------------------------|
| `gh-pat` | **yes** | Github personal access token (requires `repo` scope in order to be able to create/remove self-hosted runners in the repository) |
| `controller-url` | **yes** | The Anka Build Cloud Controller's URL to communicate with |
| `gh-pat` | **yes** | Github personal access token (requires `repo` scope in order to be able to create/remove self-hosted runners in the repository). |
| `controller-url` | **yes** | The Anka Build Cloud Controller's URL to communicate with. |
| `template-id` | **yes** | UUID of the Anka VM Template in the Anka Build Cloud Registry. |
| `template-tag` | no | Anka VM Template's Tag |
| `template-runner-dir` | no | The directory where the runner was installed. |
| `gh-owner` | no | GitHub repository owner |
| `gh-repository` | no | GitHub repository the github action runner will be attached to |
| `gh-base-url` | no | GitHub Enterprise Server base url |
| `controller-root-token` | no | Anka Build Cloud Controller's Root Token used for authentication |
| `controller-tls-ca` | no | Anka Build Cloud Controller TLS certificate's CA (needed if controller TLS cert is self-signed) |
| `controller-https-skip-cert-verify` | no | Skip the Anka Build Cloud Controller's TLS certificate verification |
| `controller-auth-cert` | no | Certificate to use for authorization with the Anka Build Cloud Controller |
| `controller-auth-cert-key` | no | Private key to use for authorization with the Anka Build Cloud Controller |
| `controller-auth-cert-passphrase` | no | The Auth Certificate's passphrase |
| `controller-http-poll-delay` | no | Delay (in seconds) between the HTTP requests to the Anka Build Cloud Controller's API |
| `job-ttl` | no | TTL (in seconds) after which job will be forced to stop (fails with error) (disable with `0`) |
| `group-id` | no | Anka Node Group ID (not name) to target for starting the VM |
| `node-id` | no | Anka Node ID (not name) to target for starting the VM |
| `vcpu` | no | The vCPUs to set before starting the Anka VM |
| `vram` | no | The ram to set before starting the Anka VM |
| `template-tag` | no | Anka VM Template's Tag. |
| `template-runner-dir` | no | The directory where the runner was installed. (default: /Users/anka/actions-runner) |
| `gh-owner` | no | GitHub repository owner. |
| `gh-repository` | no | GitHub repository the github action runner will be attached to. |
| `gh-base-url` | no | GitHub Enterprise Server base url with /api/v3 on the end. At the moment only v3 is supported. |
| `controller-root-token` | no | Anka Build Cloud Controller's Root Token used for authentication. |
| `controller-tls-ca` | no | Anka Build Cloud Controller TLS certificate's CA (needed if controller TLS cert is self-signed). |
| `controller-https-skip-cert-verify` | no | Skip the Anka Build Cloud Controller's TLS certificate verification. |
| `controller-auth-cert` | no | Certificate to use for authorization with the Anka Build Cloud Controller. |
| `controller-auth-cert-key` | no | Private key to use for authorization with the Anka Build Cloud Controller. |
| `controller-auth-cert-passphrase` | no | The Auth Certificate's passphrase. |
| `controller-http-poll-delay` | no | Delay (in seconds) between the HTTP requests to the Anka Build Cloud Controller's API. |
| `job-ttl` | no | TTL (in seconds) after which job will be forced to stop (fails with error) (disable with `0`). |
| `group-id` | no | Anka Node Group ID (not name) to target for starting the VM. |
| `node-id` | no | Anka Node ID (not name) to target for starting the VM. |
| `vcpu` | no | The vCPUs to set before starting the Anka VM. |
| `vram` | no | The ram to set before starting the Anka VM. |

### Outputs

Expand Down
32 changes: 31 additions & 1 deletion __tests__/action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ test('parse all parameters', async () => {
switch (name) {
default:
return name
case 'gh-base-url':
return 'https://api.github.com'
case 'controller-http-poll-delay':
return '1'
case 'job-ttl':
Expand All @@ -39,7 +41,7 @@ test('parse all parameters', async () => {
expect(params).toEqual({
ghOwner: 'gh-owner',
ghRepo: 'gh-repository',
ghBaseUrl: 'gh-base-url',
ghBaseUrl: 'https://api.github.com',
ghPAT: 'gh-pat',
templateId: 'template-id',
templateRunnerDir: 'template-runner-dir',
Expand All @@ -65,6 +67,8 @@ test('parse pollDelay throws', async () => {
switch (name) {
default:
return name
case 'gh-base-url':
return 'https://api.github.com'
case 'job-ttl':
return '2'
}
Expand All @@ -79,6 +83,8 @@ test('parse hardTimeout throws', async () => {
switch (name) {
default:
return name
case 'gh-base-url':
return 'https://api.github.com'
case 'controller-http-poll-delay':
return '1'
}
Expand All @@ -93,6 +99,8 @@ test('parse vcpu throws', async () => {
switch (name) {
default:
return name
case 'gh-base-url':
return 'https://api.github.com'
case 'controller-http-poll-delay':
return '1'
case 'job-ttl':
Expand All @@ -109,6 +117,8 @@ test('parse vram throws', async () => {
switch (name) {
default:
return ''
case 'gh-base-url':
return 'https://api.github.com'
case 'controller-http-poll-delay':
return '1'
case 'job-ttl':
Expand All @@ -119,3 +129,23 @@ test('parse vram throws', async () => {
})
expect(parseParams()).rejects.toThrowError('vram must be positive integer')
})

test('parse gh-base-url throws', async () => {
mockedGetInput.mockImplementation((name, attr) => {
switch (name) {
default:
return name
case 'gh-base-url':
return 'https://fake-url.com'
case 'controller-http-poll-delay':
return '1'
case 'job-ttl':
return '2'
case 'vram':
return '0'
}
})
expect(parseParams()).rejects.toThrowError(
'gh-base-urls must include /api/v3'
)
})
3 changes: 2 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ inputs:
required: false
default: ${{ github.repository }}
gh-base-url:
description: 'GitHub Enterprise Server base url'
description: 'GitHub Enterprise Server base url with /api/v3 on the end. At the moment only v3 is supported.'
required: false
default: 'https://api.github.com'
gh-pat:
description: 'GitHub personal access token (requires "repo" scope access)'
required: true
Expand Down
24 changes: 15 additions & 9 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

28 changes: 18 additions & 10 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
export type ActionParams = {
ghOwner: string
ghRepo: string
ghBaseUrl?: string
ghBaseUrl: string
ghPAT: string

templateId: string
Expand Down Expand Up @@ -45,7 +45,14 @@ export async function doAction(
params: ActionParams
): Promise<void> {
const token = await runner.createToken()
const repoUrl = `https://github.com/${params.ghOwner}/${params.ghRepo}`

// remove api/v3 from urls before registering runner
let ghBaseUrl = params.ghBaseUrl.split('/api')[0]
// change url for github from the api.github.com to the normal one
if (params.ghBaseUrl.match(/api\.github\.com/))
ghBaseUrl = 'https://github.com'

const repoUrl = `${ghBaseUrl}/${params.ghOwner}/${params.ghRepo}`

const vmConfig: StartVMRequest = {
count: 1,
Expand All @@ -56,10 +63,12 @@ export async function doAction(
group_id: params.group_id,
node_id: params.node_id,
startup_script: Buffer.from(
`cd ${params.templateRunnerDir} \
&& ./config.sh --url "${repoUrl}" --token "${token}" --labels "${actionId}" --runnergroup "Default" --name "${actionId}" --work "_work" \
&& ./svc.sh install \
&& ./svc.sh start`,
`set -exo pipefail; \
cd ${params.templateRunnerDir}; \
./config.sh --url "${repoUrl}" --token "${token}" --labels "${actionId}" --runnergroup "Default" --name "${actionId}" --work "_work"; \
./svc.sh install; \
./svc.sh start;
`,
'binary'
).toString('base64'),
script_monitoring: true,
Expand Down Expand Up @@ -123,6 +132,7 @@ export async function parseParams(): Promise<ActionParams> {
const ghOwner = core.getInput('gh-owner', {required: true})

const params: ActionParams = {
ghBaseUrl: core.getInput('gh-base-url'),
ghOwner,
ghRepo: core
.getInput('gh-repository', {required: true})
Expand All @@ -142,10 +152,8 @@ export async function parseParams(): Promise<ActionParams> {
hardTimeout
}

const ghBaseUrl = core.getInput('gh-base-url')
if (ghBaseUrl) {
params.ghBaseUrl = ghBaseUrl
}
if (!params.ghBaseUrl.match('github.com') && !params.ghBaseUrl.match('/api/'))
throw new Error('gh-base-urls must include /api/v3')

const templateTag = core.getInput('template-tag')
if (templateTag) {
Expand Down

0 comments on commit 94c3663

Please sign in to comment.